//page requests
var aj;
var tracks = { 
	home : 'restaurant',
	restaurant : 'restaurant',
	restaurantdining : 'restaurant',
	menus : 'restaurant',
	catering : 'catering',
	celebrations : 'catering',
	weddings : 'weddings',
	businesscatering : 'catering',
	specialevents : 'catering',
	venuesheinz : 'catering',
	venuessoldiers : 'catering',
	venueschildrens : 'catering',
	venuesuncommon : 'catering',
	boxlunch : 'boxlunch',
	gourmetgettogether : 'gourmet-get-together',
	gallery1 : 'restaurant',
	gallery2 : 'catering',
	contactus : 'restaurant',
	blog : 'restaurant',
	catie : 'restaurant'
};

function show() {
	var nd = new Element('div', {
		'id': 'contentframe_new',
		'class': 'extended',
		'styles': { 'z-index': '2', 'position': 'relative', 'top': '0px', 'left': '0px','opacity':'1'}
	});
	nd.setHTML(aj.response.text);
	if($('intro'))$('intro').StopPlay();
	$('contentframe').replaceWith(nd);
	aj.evalScripts();
	pageTracker._trackPageview(aj.url.substr(3));
	nd.setProperty('id','contentframe');
	//is there music?
	//set the track based on the filename without "aj_", ".html", and non alpha characters
	// to match the tracks object above.
	var playtrack = ((aj.url.split('.')[0]).substr(3)).replace(/[^a-zA-Z0-9]/g,'');
	var m_player = $('music_player');
	m_player.settrack(tracks[playtrack]);
}

function play(track)
{
	var m_player = $('music_player');
	m_player.settrack(track);
}
	
function getpage(item) {
	var pick;
	if(window.webkit420) pick = (item.getProperty('href')).toString().split("/");
	else pick = item.toString().split("/");
	aj = new Ajax("aj_"+pick[pick.length-1], {method: 'get', onComplete: show});
	aj.request();
}

function loadFromFlash(page) {
	aj = new Ajax("aj_"+page, {method: 'get', onComplete: show});
	aj.request();
}

var navpiece;
var catpiece;
var venuepiece;
var photopiece;
var annette;
var martin;
var hasbeenset = false;
var out1 = true;
var out2 = true;

function hideSlide1() {
	if (out1) {
		$('mgr1').setStyle('display', 'none');
		out1 = false;
	}
}
function hideSlide2() {
	if (out2) {
		$('mgr2').setStyle('display', 'none');
		out2 = false;
	}
}

function setup() { 
	$('bottom').setStyles({ display : 'block' });

	/* unhide these things from the layout shifting so much 
	*/
	if(!hasbeenset) {
		$('mgr1').setStyle('visibility','visible');
		$('mgr2').setStyle('visibility','visible');
		$('bk_rest').setStyle('visibility','visible'); 
		$('bk_cat').setStyle('visibility','visible');
		$('bk_venue').setStyle('visibility','visible');
		$('bk_gal').setStyle('visibility','visible');
		$('r_items').setStyles({'visibility':'visible', display: 'inline'});
		$('c_items').setStyles({'visibility':'visible', display: 'inline'});
		$('v_items').setStyles({'visibility':'visible', display: 'inline'});
		$('p_items').setStyles({'visibility':'visible', display: 'inline'}); 

		navpiece 	= new Fx.Slide($('r_items').firstChild, { mode: 'horizontal', duration : 300, wait: false});
		catpiece 	= new Fx.Slide($('c_items').firstChild, { mode: 'horizontal', duration : 300, wait: false});
		venuepiece 	= new Fx.Slide($('v_items').firstChild, { mode: 'horizontal', duration : 300, wait: false});
		photopiece 	= new Fx.Slide($('p_items').firstChild, { mode: 'horizontal', duration : 500, wait: false});
		annette 	= new Fx.SlideUp($('mgr1content'), { mode: 'vertical', duration : 500, wait: false, onComplete: hideSlide1});
		martin 		= new Fx.SlideUp($('mgr2content'), { mode: 'vertical', duration : 500, wait: false, onComplete: hideSlide2});

	}
	var rcoord = $('restaurant').getCoordinates();
	var ccoord = $('catering').getCoordinates();
	var vcoord = $('venues').getCoordinates();
	var pcoord = $('photo_holder').getCoordinates();
	var mcoord = $('mainframe').getCoordinates();
	//alert("Top: "+rcoord.top);

	$('mgr1content').setStyles({ position: 'absolute', top: '128px', left: '0px', overflow: 'visible', display:'block' });
	$('mgr2content').setStyles({ position: 'absolute', top: '128px', left: '0px', overflow: 'visible', display:'block' });
	$('contentframe').setStyles({ 'z-index' : 1});
	
//*restaurant menu*/
	$('menu_rest').setStyles({position: 'absolute', top: (rcoord.top - 63), left: mcoord.left, 'z-index': 2000 });
	$('r_items').setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
// full height menu
//	($('r_items').firstChild).setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
//	$('redblock_rest').setStyles({position: 'relative', top: 25, left: 0, 'z-index': 2000});
	($('r_items').firstChild).setStyles({position: 'relative', top: 30, left: 0, 'z-index': 2000 });
	$('redblock_rest').setStyles({position: 'relative', top: 7, left: 0, 'z-index': 2000});

/*catering menu*/
	$('menu_cat').setStyles({position: 'absolute', top: ccoord.top-63, left: mcoord.left, 'z-index': 2000 });
	$('c_items').setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
	($('c_items').firstChild).setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
	$('redblock_cat').setStyles({ position: 'relative', top: 9, left: 0, 'z-index': 2000});	

/*venue menu*/
	$('menu_venue').setStyles({position: 'absolute', top: vcoord.top-43, left: mcoord.left, 'z-index': 2000 });
	$('v_items').setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
	($('v_items').firstChild).setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });
	$('redblock_venue').setStyles({ position: 'relative', top: 9, left: 0, 'z-index': 2000});	

/*image gallery menu*/
	$('menu_gal').setStyles({position: 'absolute', top: pcoord.top - 63, left: mcoord.left, 'z-index': 2000 });		
	$('p_items').setStyles({position: 'relative', top: 0, left:  0, 'z-index': 2000});
	($('p_items').firstChild).setStyles({position: 'relative', top: 0, left: 0, 'z-index': 2000 });

/*musac*/
	$('music').setStyles({position:'absolute', top: mcoord.bottom - 15, left: mcoord.left - 55 });

/*set gallery actions for IE6*/
	if(window.ie6) {
		$('gallery1').addEvent('click', function() { getpage('gallery-1.html'); return false; });
		$('gallery2').addEvent('click', function() { getpage('gallery-2.html'); return false; });
	}
	
	//var arVersion = navigator.appVersion.split("MSIE");
	//var version = parseFloat(arVersion[1]);
	//this is getting too silly. something needs to be done about it
	if(window.ie6) { //why?
		$('bottom').setStyles({ position : 'absolute' });
	}
	($('p_items').getElementsBySelector('img')).each(function(i) {i.setStyles({paddingTop: 2, paddingLeft: 0, zIndex: 3});});

//set up the nav rollovers
	var nitems = $A($('nav').getElementsByClassName("navitem"));
	
	var subitems = $A($('redblock_rest').getElements('a'));
	subitems.extend($A($('redblock_cat').getElements('a')));
	subitems.extend($A($('redblock_venue').getElements('a')));
	subitems.extend($A($('redblock_gal').getElements('a')));
	
	var lastsub = null;
	var lastmenu = null;
	var linkhit = null;
	
	subitems.each(function(si) {
		si.clicked = false;
		si.addEvent('mouseenter', function(e) { si.setStyles({'background-color' : '#FFF', 'color' : '#F00'}); });
		si.addEvent('mouseleave', function(e) { 
			if(si.clicked) {
				si.setStyles({'background-color' : '#900', 'color' : '#FFF'}); 
			} else {
				si.setStyles({'background-color' : 'transparent', 'color' : '#FFF'}); 
			}
		});
		si.addEvent('click', function(e) {
			if(lastsub == null) lastsub = si;
			lastsub.setStyles({'background-color' : 'transparent', 'color' : '#FFF'}); 
			lastsub.clicked = false;
			si.setStyles({'background-color' : '#900', 'color' : '#FFF'});
			si.clicked = true;
			lastsub = si;
			linkhit=1;
			//highlighting of the parent is done by the parent as this is a child and the click bubbles up	
		});
	});

	nitems.each(function(nitem) {
		nitem.over_color = "#c00";
		nitem.hit_color = "#600";
		nitem.out_color =  (nitem.getStyle('backgroundColor') =='transparent' ? "#1A1A1A" : nitem.getStyle('backgroundColor'));//"#1A1A1A";
		nitem.eff = new Fx.Style(nitem, 'backgroundColor', {duration: 200, wait: false});
		nitem.clicked = false;
		
		nitem.addEvent('mouseenter', function(e) { 
			nitem.eff.start(nitem.out_color, nitem.over_color);
		});
		nitem.addEvent('mouseleave', function(e) {
			if(!nitem.clicked) {
				nitem.eff.start(nitem.over_color, nitem.out_color);
			} else {
				nitem.eff.start(nitem.over_color, nitem.hit_color);
			}
		});
		
		nitem.addEvent('click', function(e) {
			if(lastmenu == null) lastmenu = nitem;
			lastmenu.setStyle('background-color', lastmenu.out_color);
			lastmenu.clicked = false;			
			nitem.setStyle('background-color', nitem.hit_color);
			nitem.clicked = true;
			lastmenu = nitem;
			if(lastsub != null && linkhit == null) {
				lastsub.setStyles({'background-color' : 'transparent', 'color' : '#FFF'}); 
				lastsub.clicked = false;
			}
			linkhit = null;
		});
		
	});

	$('restaurant').addEvent('mouseenter', function(e) { 
		navpiece.slideIn();
		if(!window.ie6)  $('restaurant').setStyles({ backgroundImage: 'url(images/arrow.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '100% center' } );
	});
	$('restaurant').addEvent('mouseleave', function(e) { 
		navpiece.slideOut();
		if(!window.ie6) $('restaurant').setStyles({ backgroundImage: 'url(images/pip.png)' });
	});
	$('catering').addEvent('mouseenter', function(e) { 
		catpiece.slideIn();
		if(!window.ie6)  $('catering').setStyles({ backgroundImage: 'url(images/arrow.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '100% center' } ); 
	});
	$('catering').addEvent('mouseleave', function(e) { 
		catpiece.slideOut(); 
		if(!window.ie6) $('catering').setStyles({ backgroundImage: 'url(images/pip.png)' });
	});
	$('venues').addEvent('mouseenter', function(e) { 
		venuepiece.slideIn();
		if(!window.ie6)  $('venues').setStyles({ backgroundImage: 'url(images/arrow.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '100% center' } ); 
	});
	$('venues').addEvent('mouseleave', function(e) { 
		venuepiece.slideOut(); 
		if(!window.ie6) $('venues').setStyles({ backgroundImage: 'url(images/pip.png)' });
	});
	$('photo_holder').addEvent('mouseenter', function(e) { 
		photopiece.slideIn();
		if(!window.ie6)  $('photo_holder').setStyles({ backgroundImage: 'url(images/arrow.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '100% center' } ); 
	});
	$('photo_holder').addEvent('mouseleave', function(e) {
		photopiece.slideOut();
		if(!window.ie6) $('photo_holder').setStyles({ backgroundImage: 'url(images/pip.png)' });
	});
	
	var gphotos = $$('#photo_holder .photos');
	$('pinner_gal').setStyle('width', (gphotos.length * 110) + 5);
		
	if(!hasbeenset) gphotos.each(function(pic, i) {
		pic.i = i;
		pic.setStyle('position', 'absolute');
		pic.setStyle('z-index', 3);
		pic.setStyles({left: (106*i)-6, width: 106});
		if(i == 0) pic.setStyles({ left: -6});
		if(window.ie) pic.setStyle('top', -3);
		var pfx = new Fx.Styles($(pic), {duration: 300, transition: Fx.Transitions.linear});
		pic.addEvent('mouseenter', function(e) { 
			pic.setStyle('z-index', 3000);
			//filter does nothing
			pic.setStyles({backgroundImage: 'url(images/bk.png)' });
			pic.setStyles({behavior: 'url(js/iepngfix.htc)'});
			(pic.getLast()).setStyles({color: '#000'});
		});
		pic.addEvent('mouseleave', function(e) { 
			pic.setStyle('z-index', 3);
			pic.setStyles({backgroundImage: 'url(images/pip.png)'});
			pic.setStyles({behavior: 'url(js/iepngfix.htc)'});
			(pic.getLast()).setStyles({color: '#FFF'});
		});
	});
	
	//the bottom nav pieces
	$('bottom').setStyles({ left: $('mainframe').getPosition().x, top: $('mainframe').getCoordinates().bottom + 0});
	
	$('hotspot1').addEvent('mouseenter', function(e) {
		e = new Event(e);
		if($('mgr1').getStyle('display') == "none") { $('mgr1').setStyle('display', 'block'); }
		annette.slideOut();
		e.stop();
		out1 = false;
	});
	$('hotspot1').addEvent('mouseleave', function(e) {
		e = new Event(e);
		annette.slideIn();
		e.stop();
		out1 = false;
	});
	
	$('hotspot2').addEvent('mouseenter', function(e) {
		e = new Event(e);
		if($('mgr2').getStyle('display') == "none") { $('mgr2').setStyle('display', 'block'); }
		martin.slideOut();
		e.stop();
		out2 = false;
	});
	$('hotspot2').addEvent('mouseleave', function(e) {
		e = new Event(e);
		martin.slideIn();
		e.stop();
		out2 = true;
	});
	
	//fix ie png silliness
	if(window.ie) { fixie(); }	
	
	//so items aren't doubled, etc
	hasbeenset = true;
	
	//'slideout' while invisible to setup
	navpiece.hide();
	catpiece.hide();
	venuepiece.hide();
	photopiece.hide();
	annette.hide();
	martin.hide();
	hideSlide1();
	hideSlide2();
}
window.addEvent('load', setup);

window.addEvent('resize', setup);


