/***********************************************************************************************************************
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 :(.
************************************************************************************************************************/

function myPopup(thisurl) {
window.open( thisurl, "myWindow", 
"status = 1, height = 660, width = 950, resizable = 0" )
}



$(document).ready(function() {
			
	//TopNav menu
	var imagename = $('body').attr("class");
	var fullimagepath = "images/" + imagename + "-on.png";
	$('#'+imagename ).attr("src", fullimagepath);
	
	//Accordion Menu int code
	var IDname = $('.sidebar').attr("rel");
	$('#'+IDname+'Sidemenu').attr("class","sub-item-on").removeAttr("onMouseOut").removeAttr("onClick").removeAttr("onmouseover");


	$('#'+IDname+'Sidemenu').click(function(e){
		e.preventDefault();								
		//window.event.cancelBubble = true;
		return false;  
	});
	
	$('#'+IDname+'Sidemenu').mouseout(function(e){
		e.preventDefault();
		//window.event.cancelBubble = true;
		$(this).attr("class","sub-item-on");
		return false; 
	})
	
	$('#'+IDname+'Sidemenu').mouseover(function(e){
		e.preventDefault();
		//window.event.cancelBubble = true;
		$(this).attr("class","sub-item-on");
		return false; 
	})
	
	//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) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** 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 Expect the pages section
	********************************************************************************************************************/	
	$('.accordionContent').hide();
	$('#'+IDname+'Sidemenu').parent().parent().parent().parent().slideDown('normal');
	
	/*FOR VIDEO*/
	$(".showvideo").click(function(e) {
		var thisurl = $(this).attr("href");
		myPopup(thisurl);
		e.preventDefault();		
	});

	/*For rollover*/
	$(".sub-item-long-off").mouseover(function() {
			$(this).addClass('sub-item-long-on');
		}).mouseout(function() {
			$(this).removeClass('sub-item-long-on');										
	});
	

});

