/****************************** NAVIGATION *******************************/

/**
 * Multi-level Drop Down Menu (multi-ddm)
 * March 26, 2009
 * Corey Hart @ http://www.codenothing.com
 * @timer: [Default 500] Time in milliseconds to hold menu's open on mouseouts
 * @parentMO: CSS class to add/remove from parent menu on mouseover/mouseouts
 * @childMO: CSS class to add/remove to ALL child menus
 * @levels: Array of CSS classes in order of appearance on drop downs
 * @parentTag: List type of the parent menu ('ul' or 'ol')
 * @childTag: List type of each menu level ('ul' or 'ol')
 * @tags: List type of each level in order ('ul' or 'ol' for each)
 * @numberOfLevels: [Default 5] Number of levels the menu has. Will default to 
 * 	length of levels array when childMO is null.
 */ 
(function(jQuery){
	jQuery.fn.dropDownMenu = function(options){
		var menus = new Array();
		var css;
		var tag;
		var internal;
		var timeout;
		var settings = jQuery.extend({
			timer: 500,
			parentMO: null,
			childMO: null,
			levels: [],
			parentTag: 'ul',
			childTag: 'ul',
			tags: [],
			numberOfLevels: 5
		},options||{});

		// Set number of levels
		if (settings.tags.length > 0){
			settings.numberOfLevels = settings.tags.length;
		}else if (settings.levels.length){
			settings.numberOfLevels = settings.levels.length;
		}

		// Set css levels with childMO
		if (settings.childMO){
			for (var i=0; i<settings.numberOfLevels; i++) settings.levels[i] = settings.childMO;
		}

		// Set tag levels with tag
		if (settings.tags.length < 1){
			for (var i=0; i<settings.numberOfLevels; i++) settings.tags[i] = settings.childTag;
		}

		// Run through each level
		menus[0] = jQuery(this).children('li');
		for (var i=1; i<settings.numberOfLevels+2; i++){
			// Tags/CSS
			css = (i==1) ? settings.parentMO : settings.levels[i-2];
			tag = (i==1) ? settings.parentTag : settings.tags[i-2];

			// level selector
			menus[i] = menus[i-1].children(settings.tag).children('li');

			// Action
			menus[i-1].attr({rel: css+';'+tag}).mouseover(function(){
				if (timeout) clearTimeout(timeout);
				internal = jQuery(this).attr("rel").split(";");
				jQuery(this).siblings('li').children('a').removeClass(internal[0]).siblings(internal[1]).hide();
				jQuery(this).children('a').addClass(internal[0]).siblings(internal[1]).show();
			}).mouseout(function(){
				internal = jQuery(this).attr("rel").split(";");
				if (internal[0] == settings.parentMO){
					timeout = setTimeout(function(){closemenu();}, settings.timer);
				}
			});
		}

		// Allows user option to close menus by clicking outside the menu on the body
		jQuery(document).click(function(){closemenu();});

		// Closes all open menus
		var closemenu = function(){
			for (var i=menus.length; i>-1; i--){
				if (menus[i] && menus[i].attr("rel")){
					internal = menus[i].attr("rel").split(";");
					menus[i].children(internal[1]).hide().siblings('a').removeClass(internal[0]);
				}
			}
			jQuery('a', menus[0]).removeClass(settings.parentMO);
			if (timeout) clearTimeout(timeout);
			}
		};
	})(jQuery);


/****************************** TABBED PANELS *******************************/


(function(jQuery){ 
     jQuery.fn.extend({  
         tabify: function() {
			function getHref(el){
				hash = jQuery(el).find('a').attr('href');
				if(hash)
					return hash.substring(0,hash.length-4);
				else
					return false;
				}
		 	function setActive(el){
				jQuery(el).addClass('active');
				if(getHref(el))
					jQuery(getHref(el)).show();
				else
					return false;
				jQuery(el).siblings('li').each(function(){
					jQuery(this).removeClass('active');
					jQuery(getHref(this)).hide();
				});
			}
			return this.each(function() {
				var self = this;
				
				jQuery(this).find('li>a').each(function(){
					jQuery(this).attr('href',jQuery(this).attr('href') + '-tab');
				});
				
				function handleHash(){
					if(location.hash)
						setActive(jQuery(self).find('a[href=' + location.hash + ']').parent());
				}
				if(location.hash)
					handleHash();
				setInterval(handleHash,100);
				jQuery(this).find('li').each(function(){
					if(jQuery(this).hasClass('active'))
						jQuery(getHref(this)).show();
					else
						jQuery(getHref(this)).hide();
				});
            }); 
        } 
    }); 
})(jQuery);







/****************************** DOCUMENT READY *******************************/
jQuery(document).ready(function(){
						   
	// pane-list
	jQuery("ul.pane-list li, ol.pane-list li, p.pane-list, div.pane-list").click(function(){
    	window.location=jQuery(this).find("a").attr("href");return false;
		});
	
	// navigation
	jQuery('#multi-ddm').dropDownMenu({parentMO: 'parent-hover', childMO: 'child-hover1'});

	// sliding panels
	jQuery("#firstpane div.menu_head").click(function(){
		jQuery(this).css({}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
       	jQuery(this).siblings("div.menu_head").css({});
		//jQuery(this).css({color:"#5B6C84"});
		jQuery(this).siblings("div.menu_head").css({});
		//jQuery(this).siblings().css({color:"#5B6C84"});
		});

	// tabbed panels
	jQuery('#menu').tabify();

}); //close doc ready

/***********************************************************************************************************************
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) {
			
			//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
	********************************************************************************************************************/	
	$('.accordionContent').hide();

});

