// keeps track of the current section
var currentSection;


function trace( msg ){
  if( typeof( jsTrace ) != 'undefined' ){
    jsTrace.send( msg );
  }
}





function getSection(buttonName)
{
	return buttonName.substring(0, buttonName.lastIndexOf("_"));
}









/*	
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1,c.length);
		if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}
			
	
function setLocation(storeID, locationID) {
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();

	document.cookie = "myStore=" + storeID + ";expires=" + expires + ";path=/";
	//window.location.reload(true);
	alert(storeLocations[locationID][2]);
	
	
	
}
*/




/*
** 
*/
var Site = 
{



	/*
	**
	** TODO:	
	**
	**
	*/
	init:function() {
	
	
	},
	
	
	setLocation:function(storeID, locationID) {
	
	
	
		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		
		//alert("myStore=" + storeID + ";expires=" + expires + ";path=/;domain=zpizza.com");
		
		//alert("Thank you for choosing your zpizza location " + storeLocations);
		
		$('my-store').setHTML(storeLocations[locationID][2]);
		$('my-store').setStyles('font-size: .9em;');
		$$('#my-store a').setStyles('background-color: #f7a139; width: 100%; padding: .7em .5em; margin: .8em auto auto auto; color: #fff; display: block;');
		

		//alert($$('#my-store a'));
		
		document.cookie = "myStore=" + storeID + ";expires=" + expires + ";path=/;domain=zpizza.com";
		//var myLocation = $('my-location');
		//var newLocation = storeLocations[locationID][2];
		//newLocation.replaces(myLocation);
		
	}

};










/*
** 
*/
var Menu = 
{



	/*
	**
	** TODO:	
	**
	**
	*/
	init:function() {
	
		currentSection =  $(document.body).id;
		currentPage = $(document.body).getProperty('class');
	
	
		
		// create a list of the main nav elements
		/*
			this was the older way i was getting the buttons, but it fails in silver stripe
			i think they must have a similar $$ call somewhere that's conflicting. so far
			the new way, just calling the .top class seems to work and i don't believe
			there are any conflicts, but just keep an eye out.
			
			var mainNav = $$('#main li a.top');
		*/
		
		// var mainNav = $$('.top');
		// var mainNav = $$('#main li a','#subnav li a');
		var mainNav = $$('#main li a');
	
		// loop through the main nav elements
		mainNav.each(function(element) {
		
 			
 			// make sure the button isn't the current section			
 			if(getSection(element.id) == currentSection) {
 				return;
 			} else {
 			
				element.setStyle('opacity', .01);
				
				// new fx transitions for the over/out state 
				var fi = new Fx.Style(element, 'opacity', {duration:333, wait: true });
				var fo = new Fx.Style(element, 'opacity', {duration:666, wait: true });
	
	
				 
				// the mouse over event
				element.addEvent('mouseenter', function(){
					fo.stop();
					fi.start(.99);
				});
	
				
				
				// the mouse out event
				element.addEvent('mouseleave', function(){
					fi.stop();
					fo.start(.01);
				});
			}
		});
		
		
	
	
		/*
		var subNav = $$('#subnav li a');
	
		// loop through the main nav elements
		subNav.each(function(element) {
		
 			
 			
 			
 			// make sure the button isn't the current section			
 			if(getSection(element.id) == currentPage) {
 				return;
 			} else {
 			
				element.setStyle('opacity', .01);
				
				// new fx transitions for the over/out state 
				var fi = new Fx.Style(element, 'opacity', {duration:333, wait: true });
				var fo = new Fx.Style(element, 'opacity', {duration:666, wait: true });
	
	
				 
				// the mouse over event
				element.addEvent('mouseenter', function(){
					
					fo.stop();
					fi.start(.01, .99);
				});
	
				
				
				// the mouse out event
				element.addEvent('mouseleave', function(){
					fi.stop();
					fo.start(.99, .01);
				});
			}
		});
		*/
		
		
	}
}






window.addEvent('load', Menu.init);
window.addEvent('load', Site.init);