/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/
$(document).ready(function() {

	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() { 
	


		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
		
			for(var i=1; i<20; i++){
				if(document.getElementById('pp'+i)) document.getElementById('pp'+i).style.background='';
			}		
		
			if(document.getElementById('p'+this.id)){ 

							$("#p"+this.id).animate({scrollTop: 0}, 400, function() {
                                                                location.hash = "#"+this.id;
                                                        });			
			
				//$.scrollTo("#p"+this.id, 800);
				document.getElementById('p'+this.id).style.background='url(images/menu_body_ac.png) repeat-x top'; 
				document.getElementById('p'+this.id).style.height='82px';
				document.getElementById('p'+this.id).style.width='860px';
			}
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 }else{ 
		 
			if(document.getElementById('p'+this.id)){ 
				document.getElementById('p'+this.id).style.background=''; 
				document.getElementById('p'+this.id).style.height='82px';
				document.getElementById('p'+this.id).style.width='860px';				
			}		 
		 
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();
	
	
if(location.hash!=""){
	h=location.hash;
	h=h.replace(/#/,'');
	document.getElementById('p'+h).style.display='block';
	document.getElementById(h).style.background='url(images/menu_body_ac.png) repeat-x top'; 
	document.getElementById(h).style.height='82px';
	document.getElementById(h).style.width='860px';	
	$(h).animate({scrollTop: 0}, 400, function() {
                                                                location.hash = "#"+h;
                                                        });	
}	

});


