var prodState=0;
var servState=0;
var servState2=0;
var intOpacity=.95;
var intGoodiesOpacity=.75;
//Event.observe(window,'load',initLoader);
//=================================== START: INIT FUNCTIONS =========================================//
	function initLoader(){	
		switch(Element.readAttribute('mainDivContainer','class')){
			case "homeMain":
				homeInit();
			break;			
		};		
	};
//=================================== START: INIT FUNCTIONS =========================================//
	function indexInit(){
		setZincIndexListener();
		setTimeout("showPageInstructions()",10000);
	};
	 
	function facebookShareInit(){			
		Event.observe('shareusFacebook','click',showServices,true);
	};
	
	function facebookShare(){
		u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
	};
	
	function homeInit(){
		Event.observe('musicOff','click',stopMusic,true);
		setTimeout("soundManager.play('zincTheme',99)",500); 
		new PeriodicalExecuter(isLastObj, 6);		
	};

		function startMusic(e){
			Event.stop(e);
			soundManager.play('zincTheme',99);
			Element.removeClassName('musicOff','activeMusicBtn');
			Element.addClassName('musicOn','activeMusicBtn');			
			Event.stopObserving('musicOn','click',startMusic,true);
			Event.observe('musicOff','click',stopMusic,true);
		};

		function stopMusic(e){
			Event.stop(e);
			soundManager.stop('zincTheme');
			Element.removeClassName('musicOn','activeMusicBtn');
			Element.addClassName('musicOff','activeMusicBtn');
			Event.observe('musicOn','click',startMusic,true);
			Event.stopObserving('musicOff','click',stopMusic,true);
		};	
		
	function servicesInit(){
		var elementList = $$('.fade');
			elementList.each(function(item,index){
				new Effect.Opacity(item,{to:intOpacity})
			});

		var elementList = $$('.servicesCat');
			elementList.each(function(item,index){
				Event.observe(item.id,'click',showServices,true);			
			});
			
		Event.observe('hideServicesBtn','click',hideServicesContainer,true);
		Event.observe('showServicesBtn','click',showServicesContainer,true);

		//add event listener to servicesSubCat
		var elementList = $$('.servicesSubCat');
			elementList.each(function(item,index){
				Event.observe(item.id,'click',showServices2,false);
			});	
		Event.observe('facebookTaglineBtn','click',shakeFacebookContainer,true);
	};

	function productsInit(){
		new Effect.Opacity('productsContainer',{to:.88})

		var elementList = $$('.productCat');
			elementList.each(function(item,index){
				Event.observe(item.id,'click',showProducts,true);
			});

		Event.observe('hideProductsBtn','click',hideProductsContainer,true);
		Event.observe('showProductsBtn','click',showProductsContainer,true);
	};
	
	function goodiesInit(){
		var elementList = $$('.goodiesMsgContainer');
			elementList.each(function(item,index){
				new Effect.Opacity(item,{to:intGoodiesOpacity});
			});	
		new PeriodicalExecuter(isLastObj, 6);	
	};
	
	function hoursInit(){
		//setHoursEventListeners();
	};

	function contactInit(){
		/* new Effect.Opacity('contactTopLeftCol',{to:intOpacity}) */
		new Effect.Opacity('contactTopRightCol',{to:intOpacity})

		var elementList = $$('.hideBtn');
			elementList.each(function(item,index){
				Event.observe(item.id,'click',hideContactContainer,true);
			});

		var elementList = $$('.showBtn');
			elementList.each(function(item,index){
				Event.observe(item.id,'click',showContactContainer,true);
			});
		gMaps();		
	};

	function aboutInit(){
		new Effect.Opacity('aboutMsgContainer',{to:intOpacity})
		Event.observe('hideAboutMsgBtn','click',hideAboutMsgContainer,true);
		Event.observe('showAboutMsgBtn','click',showAboutMsgContainer,true);
		Event.observe('facebookTaglineBtn','click',shakeFacebookContainer,true);
	};
	
	function academyInit(){
		Event.observe('facebookTaglineBtn','click',shakeFacebookContainer,true);
	};	
	
	function academyCoursesInit(){
		var elementList = $$('.coursesNavObj');
			elementList.each(function(item,index){
				Event.observe(item,'click',showCourseDetails,true);
			});	
		Event.observe('facebookTaglineBtn','click',shakeFacebookContainer,true);
	};	

	function pressInit(){
		setPressNavListeners();	
		Event.observe('facebookTaglineBtn','click',shakeFacebookContainer,true);
	};

//=================================== END: INIT FUNCTIONS =========================================//
//=================================== START: GENERAL FUNCTIONS =========================================//
	function showCourseDetails(e){
		Event.stop(e);
		var srcObj = Event.element(e).id;	

		var elementList = $$('.activeAcademySubNav');
		elementList.each(function(item,index){
			Element.removeClassName(item,'activeAcademySubNav');
		});	
		
		var elementList = $$('.activeCourseDetails');
		elementList.each(function(item,index){
			Element.removeClassName(item,'activeCourseDetails');
			Element.hide(item);
		});	
		
		var elementList = $$('.courseIndicator');
		elementList.each(function(item,index){
			Element.remove(item);
		});	
		//Hide all academy course imgs
		var elementList = $$('.academyCourseImgs');
		elementList.each(function(item,index){
			Element.hide(item);
		});		
		
		//display img associated with each academy course
		Element.show(srcObj+'Img');

		Element.addClassName(srcObj,'activeAcademySubNav');			
		var srcObjDetailsObj = srcObj + 'InfoContainer'
		Element.addClassName(srcObjDetailsObj,'activeCourseDetails');
		Element.toggle(srcObjDetailsObj,'appear');
		new Insertion.After(srcObj,'<span class="courseIndicator"></span>');	
	};
	
	function shakeFacebookContainer(){
		new Effect.Shake('facebookContainer');
	};

//=================================== END: GENERAL FUNCTIONS =========================================//
//================================= START: INDEX FUNCTIONS ====================================================================
	function setZincIndexListener(){	
		var elementList = $$('.hairOn');
			elementList.each(function(item,index){				
				Event.observe(item.id,'mouseover',toggleZincIndex,true);
			});		

		var elementList1 = $$('.hairOver');
			elementList1.each(function(item,index){				
				Event.observe(item.id,'mouseout',toggleZincIndex,true);
			});			
		
		var elementList2 = $$('.retreatOn');
			elementList2.each(function(item,index){				
				Event.observe(item.id,'mouseover',toggleZincIndex,true);
			});		

		var elementList3 = $$('.retreatOver');
			elementList3.each(function(item,index){				
				Event.observe(item.id,'mouseout',toggleZincIndex,true);
			});			
	
		Event.observe('retreatLabel','mouseout',toggleZincIndex,true);			
		Event.observe('hairLabel','mouseout',toggleZincIndex,true);	
	};
	
	function setZincRetreatListenerOLD(){	
		var elementList = $$('.retreatOn');
			elementList.each(function(item,index){				
				Event.observe(item.id,'mouseover',toggleZincRetreat,true);
			});		

		var elementList = $$('.retreatOver');
			elementList.each(function(item,index){				
				Event.observe(item.id,'mouseout',toggleZincRetreat,true);
			});			
	
		Event.observe('retreatLabel','mouseout',toggleZincRetreat,true);		
	};	
	
	function toggleZincIndex(e){
		var sourceObj = Event.element(e);
		var sourceObjCls = Element.classNames(sourceObj);
		myString = new String(sourceObjCls);
		splitString = myString.split("On");	
		splitString2 = new String(splitString[0]);
		splitStringFinal = splitString2.split("Over");

		var oppositeObj;
		switch(splitStringFinal[0]){
			case "retreat":
				oppositeObj = "hair"
			break;
			case "hair":
				oppositeObj = "retreat"
			break;			
		};
		
		var elementList = $$('.'+splitStringFinal[0]+'Over');
			elementList.each(function(item,index){				
				Effect.toggle(item,'appear',{duration: .5});
			});				
		
		var elementList2 = $$('.'+oppositeObj+'Over');
			elementList2.each(function(item,index){	
			var targetObjState = Element.getStyle(item,'display')
				if(targetObjState!=='none'){
					
					Effect.toggle(item,'appear',{duration:.5});		
				}
			});			
	};
	
	function toggleZincRetreatOLD(e){
		var sourceObj = Event.element(e);
		var sourceObjCls = Element.classNames(sourceObj);

		var elementList = $$('.retreatOver');
			elementList.each(function(item,index){	
				Effect.toggle(item.id,'appear',{duration:.5});
			});		
			
		var elementList2 = $$('.hairOver');
			elementList2.each(function(item,index){	
				if(Element.getStyle(item,'display')=='block'){
					Effect.toggle(item,'appear',{duration:.5});		
				}
			});				
	};	
	
	function showPageInstructions(){
		Effect.toggle('instructTxt','appear',{duration:.5});
		setTimeout("Effect.Pulsate('instructTxt',{duratin:3.0,pulses:2})",600);
		setTimeout("Effect.DropOut('instructTxt')",7000);
		setTimeout("showPageInstructions()",20000);
	};

//================================= START: HELPER FUNCTIONS ====================================================================

	function setPngBkg(objID,path){
		var objMyImage = null;
		objMyImage = new OpacityObject(objID,path);
		objMyImage.setBackground();
	};

//================================= END: HELPER FUNCTIONS ====================================================================
//================================= START: HOME FUNCTIONS ===================================================================
	function isLastObj(){
		var elementList = $$('.activeSlideshow');
			var srcObj = elementList[0];
			var lastObjFlag = Element.hasClassName(srcObj,'lastObj');
		//REMOVE ANY EXISTING activeSlideshow1BottomBtn CLASSNAMES
			elementList.each(function(item,index){			
				Element.removeClassName(item.id,'activeSlideshow');
				Element.hide(item);
			});		
			
		if(lastObjFlag==true){
			//DETERMINE WHO THE FIRST CHILD IS
			var parentObj = Element.up(srcObj);
			var parentObjFirstChild = Element.firstDescendant(parentObj);	
			Element.addClassName(parentObjFirstChild, 'activeSlideshow');	
			slideShowToggle(parentObjFirstChild.id);
		}else{			
			setAutoSlideshow(elementList[0]);
		};			
	};
	
	function setAutoSlideshow(srcObj){
		//DETERMINE THE targetObj
			var targetObj = Element.next(srcObj).id;
		//ADD activeSlideshow CLASS TO targetObj
			Element.addClassName(targetObj, 'activeSlideshow');					
			slideShowToggle(targetObj);
	};
	
	function slideShowToggle(element){
		Effect.toggle(element,'appear');
	};

//================================= END: HOME FUNCTIONS =====================================================================
//================================= START: SERVICES FUNCTIONS =====================================================================
	function showServices(e){
		Event.stop(e);
		var sourceObj = Event.element(e);
		if(servState==0){			
			Effect.BlindDown('servicesSubContainer');
			servState=1;
		};

		if(servState2==1){
			if(sourceObj.id!=='handsFeet'){
				Effect.BlindUp('servicesDescripContainer');
			};
			servState2=0;
			
			//remove existing activeServItem class names
				removeActiveServItem();
			//remove existing activeServiceCatItem class names
				hideServices3();
		};
		
		if(sourceObj.id=='handsFeet'){
			switch(servState2){
				case 0:
					var elementList = $$('.activeServCatItem');
					elementList.each(function(item,index){
						Effect.Fade(item);
					});
				break;
			};
			var handsFeetItemVis = Element.getStyle('servicesDescripContainer', 'display');
			//IF servicesDescripContainer IS HIDDEN, THEN DISPLAY
				if(handsFeetItemVis=='none'){
					Effect.BlindDown('servicesDescripContainer');
				}
			//ADD ACTIVESERVCATITEM CLASS TO ACTIVE ELEMENT
				Element.addClassName('handsFeetItem', 'activeServCatItem');
			//DISPLAY HANDSFEETITEM DESCRIPTION
				setTimeout("Effect.Appear('handsFeetItem')",700);
			servState2=1;
		};		

		//remove existing activeServiceCat class names
			var elementList = $$('.activeServCat');
				elementList.each(function(item,index){
					Element.removeClassName(item.id,'activeServCat');
				});

		//add activeProdCat to current Category
			Element.addClassName(sourceObj.id+"LI",'activeServCat');

		//remove existing activeServiceCat class names
			var elementList = $$('.servicesSubCatContainer');
				elementList.each(function(item,index){
					Effect.Fade(item.id,{duration:.5})
				});

		//display associated prodCatItems
			setTimeout("Effect.Appear('"+sourceObj.id+"ServicesSubContainer')",700);
	};

	function showServices2(e){
		Event.stop(e);
		var sourceObj = Event.element(e);

		//remove existing activeServItem class names
			removeActiveServItem()

		//add activeProdCat to current Category
			var sourceObj = Event.element(e);
			Element.addClassName(sourceObj.id+'LI','activeServItem');
			showServices3(sourceObj);
	};

	function showServices3(item){
		switch(servState2){
			case 1:
				hideServices3();
				setTimeout("Effect.Appear('"+item.id+"Item',{duration:1.0})",1100);
			break;
			case 0:
				Effect.BlindDown('servicesDescripContainer');
				Effect.Appear(item.id+'Item',{duration:1.0});					
			break;
		};
		
		servState2=1;
		Element.addClassName(item.id+'Item','activeServCatItem');
	};

	function removeActiveServItem(){
		//remove existing activeServItem class names
		var elementList = $$('.activeServItem');
			if(elementList.length>0){
				elementList.each(function(item,index){
					Element.removeClassName(item,'activeServItem');
				});
			};	
	};
	
	function hideServices3(){
		//remove existing activeServiceCatItem class names
		var activeItem = $$('.activeServCatItem');
			if(activeItem.length>0){
				activeItem.each(function(item,index){
					Effect.Fade(item,{duration:1.0});
					Element.removeClassName(item,'activeServCatItem');
				});
			};
	};

	function hideServicesContainer(e){
		Event.stop(e);
		if(servState!==0){
			Effect.BlindUp('servicesSubContainer');
			if(servState2!==0){
				Effect.BlindUp('servicesDescripContainer');
			};
		};

		new Effect.MoveBy('servicesInnerContainer',0,-355);
		setTimeout("Effect.Fade('servicesCatContainer',{duration:.2})",800);
		Element.toggle('hideServicesBtn','appear');
		Element.toggle('showServicesBtn','appear');
	};

	function showServicesContainer(e){
		Event.stop(e);
		if(servState!==0){
			Effect.BlindDown('servicesSubContainer');
			if(servState2!==0){
				Effect.BlindDown('servicesDescripContainer');
			};
		};
		new Effect.MoveBy('servicesInnerContainer',0,355);
		Effect.Appear('servicesCatContainer',{duration:.5})
		Element.toggle('hideServicesBtn','appear');
		Element.toggle('showServicesBtn','appear');
	};

//================================= END: SERVICES FUNCTIONS =====================================================================
//================================= START: PRODUCTS FUNCTIONS ===================================================================
	function showProducts(e){
		Event.stop(e);
		var sourceObj = Event.element(e);
		if(prodState==0){
			new Effect.Opacity('productsDescripContainer',{to:.93})
			Effect.BlindDown('productsDescripContainer');
		}
		//remove existing activeProdCat class names
		var elementList = $$('.activeProdCat');
			elementList.each(function(item,index){
				setTimeout("Element.removeClassName('"+item.id+"','activeProdCat')",300);
			});

		//remove existing activeProdCat class names
		var elementList = $$('.productCatItems');
			elementList.each(function(item,index){
				Effect.Fade(item.id,{duration:.5})
			});

		//add activeProdCat to current Category
		setTimeout("Element.addClassName('"+sourceObj.id+"LI','activeProdCat')",500);
		//display associated prodCatItems
		setTimeout("Effect.Appear('"+sourceObj.id+"Items')",500);

		prodState=1;
	};

	function hideProductsContainer(e){
		Event.stop(e);
		if(prodState!==0){
			Effect.BlindUp('productsDescripContainer');
		}
		new Effect.MoveBy('productsInnerContainer',0,-355);
		setTimeout("Effect.Fade('productCatContainer',{duration:.2})",800);
		Element.toggle('hideProductsBtn','appear');
		Element.toggle('showProductsBtn','appear');
	};

	function showProductsContainer(e){
		Event.stop(e);
		if(prodState!==0){
			Effect.BlindDown('productsDescripContainer');
		}
		new Effect.MoveBy('productsInnerContainer',0,355);
		Effect.Appear('productCatContainer',{duration:.5})
		Element.toggle('hideProductsBtn','appear');
		Element.toggle('showProductsBtn','appear');
	};

//================================= END: PRODUCTS FUNCTIONS =====================================================================
//================================= START: GOODIES FUNCTIONS =====================================================================

//================================= END: GOODIES FUNCTIONS =====================================================================
//================================= START: HOURS FUNCTIONS =====================================================================
	var prevStylist="";
	
	function setHoursEventListeners(){
		var elementList = $$('.stylistID');
		elementList.each(function(item,index){
			Event.observe(item,'click',showStylistHours,true);	
		});
	};

	function showStylistHours(e){
		Event.stop(e);
		var sourceObj=Event.element(e);
		alert($(sourceObj).id)
		if(prevStylist!==""){
			new Effect.Fade(prevStylist+'Schedule');	
			Element.setStyle(prevStylist,{textDecoration:'none'});			
		};
		
		Element.setStyle(sourceObj,{textDecoration:'underline'});
		setTimeout("new Effect.Appear('"+sourceObj.id+"Schedule');",1000);
		
		prevStylist=sourceObj.id;	
	};
	
//================================= END: HOURS FUNCTIONS =====================================================================
//================================= START: CONTACT FUNCTIONS =====================================================================

	function hideContactContainer(e){
		Event.stop(e);
		var sourceObj = Event.element(e);
		if(sourceObj.id=='hideLeftColBtn'){
			new Effect.MoveBy('contactTopLeftCol',-285,0);
			var trgBtn = "LeftColBtn";
		}
		else{
			new Effect.MoveBy('contactTopRightCol',90,0);
			var trgBtn = "RightColBtn";
		}
		Element.toggle('hide'+trgBtn,'appear');
		Element.toggle('show'+trgBtn,'appear');
	};

	function showContactContainer(e){
		Event.stop(e);
		var sourceObj = Event.element(e);
		if(sourceObj.id=='showLeftColBtn'){
			new Effect.MoveBy('contactTopLeftCol',285,0);
			var trgBtn = "LeftColBtn";
		}
		else{
			new Effect.MoveBy('contactTopRightCol',-90,0);
			var trgBtn = "RightColBtn";
		}

		Element.toggle('hide'+trgBtn,'appear');
		Element.toggle('show'+trgBtn,'appear');
	};

	function gMaps() {
		if (GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById("mapsearch"));
	        map.setCenter(new GLatLng(49.257264,-123.121444),15);
	        map.setUIToDefault();
			map.addOverlay(new GMarker(map.getCenter()))
			map.openInfoWindowHtml(map.getCenter(),'<h4 id="mapMarkerTitle">Zinc Hair+Academy</h4><p id="mapMarkerDescription">768 W 16th Avenue, Vancouver, BC V5Z 1S7</p>');
	      };
    };

	
//================================= END: CONTACT FUNCTIONS =====================================================================
//================================= START: ABOUT FUNCTIONS =====================================================================
	function hideAboutMsgContainer(e){
		Event.stop(e);
		new Effect.MoveBy('aboutMsgContainer',233,0);
		Element.toggle('hideAboutMsgBtn','appear');
		Element.toggle('showAboutMsgBtn','appear');
	};

	function showAboutMsgContainer(e){
		Event.stop(e);
		new Effect.MoveBy('aboutMsgContainer',-233,0);
		Element.toggle('hideAboutMsgBtn','appear');
		Element.toggle('showAboutMsgBtn','appear');
	};
//================================= END: ABOUT FUNCTIONS =====================================================================
//================================= START: PRESS FUNCTIONS =====================================================================
	function setPressNavListeners(){
		var navObjList = $$('.navObj');		
		navObjList.each(function(item,index){	
			Event.observe(item,'click',movePageObj,true);	
		});			
	};
	
	function movePageObj(e){
		Event.stop(e);
		var srcObj = Event.element(e)
		
		if(srcObj.hasClassName('activePressNav')==true){
			return;
		}
		else{
			setMovePageObj(e);
		};		
	};
	
	function setMovePageObj(e){
		var srcObj = Event.element(e).id;
		var activeBtnList = $$('.activePressNav');
		activeBtnList.each(function(item,index){			
			Element.removeClassName(item,'activePressNav');		
		});		
		
		targetObjMultiple = $(srcObj).innerHTML;
		targetImgInt = ((targetObjMultiple-1) * 487)
		targetTxtInt = ((targetObjMultiple-1) * 350)
		
		if(targetImgInt<0){			
			targetImgInt = -1*targetImgInt
			targetTxtInt = -1*targetTxtInt
		}
		else{
			targetImgInt = targetImgInt/-1
			targetTxtInt = targetTxtInt/-1
		};	
	
			new Effect.Morph('imageContainer', {
			  style: {
			    left:targetImgInt + 'px'
			  }, // CSS Properties
			  duration: 0.5 // Core Effect properties
			});
			
			new Effect.Morph('contentContainer', {
			  style: {
			    left:targetTxtInt + 'px'
			  }, // CSS Properties
			  duration: 0.5 // Core Effect properties
			}); 		

		Element.addClassName(srcObj,'activePressNav');			
	};
//================================= END: PRESS FUNCTIONS =====================================================================
//================================= START: AJAX ====================================================================
function createRequestObject() {
     var ro;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer"){
          ro = new ActiveXObject("Microsoft.XMLHTTP");
     }else{
          ro = new XMLHttpRequest();
     }
     return ro;
};

var http = createRequestObject();

function sndReqArg(type,url,action,serialize) {
     http.open(type, url);
     http.onreadystatechange = action
     if(type=="POST"){
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(serialize);
	 }
	 else{
	 http.send("");
	 }
};
//================================= END: AJAX ====================================================================
//================================= START: RESPONSE HANDLERS ====================================================================

	function hrGetRelatedCountry(){
		if(http.readyState == 1) {				//show loading indicator

		}
		else if(http.readyState == 4) {
			if(http.status==200){				// IF RESPONSE OK
				var response = http.responseText;
				var update = new Array();
				if(response.indexOf('|' != -1)) {
					update = response.split("|");

					$(targetProv).value=update[0]
				}
			}
			else{								// IF RESPONSE NOT OK
				alert('getRelatedCountry: failure. error code: '+ http.status)
			}
		}
	};




