/* -----------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
	
	boe.chicodev.com
	Stylesheet: public/main.js
	Author: Brent White, chicowebdesign.com
	Version: November 01, 2009
	
--------------------------------------------------------------------------------------
----------------------------------------------------------------------------------- */
jQuery(document).ready(function(){

	/* -----------------------------------------------------------------------------------
	CLICK HANDLERS FOR FUN-FACTS LINKS ON THE OUR TEAM PAGE
	----------------------------------------------------------------------------------- */
	jQuery("a.fun-facts").click(function(){
		var link=jQuery(this);
		var img=link.children("img");
		img.slideToggle('slow');
		return false;
	});
	
	
	
	/* -----------------------------------------------------------------------------------
	LAST CHILD / FIRST CHILD : ADD FIRST / LAST CLASSES
	----------------------------------------------------------------------------------- */
	jQuery('li:last-child').addClass('last');
    jQuery('li:first-child').addClass('first');
    
	/* -----------------------------------------------------------------------------------
	ODD CHILD / EVEN CHILD : ADD ODD / EVEN CLASSES
	----------------------------------------------------------------------------------- */
	jQuery('ul.resources li:odd').addClass('even');
	jQuery('ul.resources li:even').addClass('odd');
	
	/* -----------------------------------------------------------------------------------
	HEADER -- NAVIGATION
	----------------------------------------------------------------------------------- */
	function HeaderNavigation() {
		headerNavigationObject = this;
		jQuery('#header .navigation *').each(function(){
			jQuery(this).mouseover(function(){
				clearTimeout(headerNavigationObject.windowTimeout);
			})
		});
		jQuery('#header .navigation li a').each(function () {
			if (this.parentNode.parentNode.className == 'navigation') {
				jQuery(this).wrapInner('<span></span>');
			};
		});
		jQuery('#header .navigation > li a span').bind('mouseover', function(){
			headerNavigationObject.swapList(this.parentNode.parentNode.id);
		});
		jQuery('#header .navigation > li')
		.each(function(i){
			jQuery(this).attr('id','main_'+i);
		})
		.each(function(){
			if (jQuery(this).hasClass("active")) {
				headerNavigationObject.main_navigation = this;
			}
		});
		jQuery('#header .navigation').bind('mouseout', function(){
			headerNavigationObject.windowTimeout = window.setTimeout(function(){
				jQuery("#header .navigation li.hover").removeClass('active');
				jQuery("*").removeClass('hover');
				headerNavigationObject.swapList(headerNavigationObject.main_navigation.id);
				jQuery("*").removeClass('hover');
			}, 1000)
		});
	}
	HeaderNavigation.prototype.swapList = function(i){
		jQuery('#header .navigation li').each(function(){
			if (this.parentNode.className == 'navigation') {
				if (this.id == i) {
					jQuery(this).addClass('active');
					jQuery(this).addClass('hover');
				} else {
					jQuery(this).removeClass('active');
					jQuery(this).removeClass('hover');
				}
			}
		});
		return true;
	};
	headerNavigation = new HeaderNavigation();
	
	/* -----------------------------------------------------------------------------------
	HEADER -- NAVIGATION -- SINGLE UL MULTIPLE COLUMNS
	----------------------------------------------------------------------------------- */
	$("#header .navigation li ul").each(function(i){
		var navcnt = $(this).children().length;
		
		$(this).addClass("left_column");
		
		if(navcnt>=1){
			var newul = $(this).parent().append("<ul class=\"right_column\"></ul>").children("ul.right_column");
			$(this).css("width","302px");
			for(var j=Math.floor((navcnt+1)/2); j<navcnt; j++){
				newul.append("<li>" + $(this).children().eq(j).html()+"</li>");
			}
			var k=Math.floor((navcnt+1)/2);
			while($(this).children().length>k){
				$(this).children().eq(k).remove();
			}
		}
	
	});

	/* -----------------------------------------------------------------------------------
	LEFT COLUMN -- NAVIGATION
	----------------------------------------------------------------------------------- */
	function LeftColumnNavigation() {
		leftColumnNavigationObject = this;
		jQuery('#content .left_column .navigation ul *').each(function(){
			jQuery(this).mouseover(function(){
				clearTimeout(leftColumnNavigationObject.windowTimeout);
			})
		});
		jQuery('#content .left_column .navigation ul > li a').bind('mouseover', function(){
			leftColumnNavigationObject.swapList(this.parentNode.id);
		});
		jQuery('#content .left_column .navigation ul > li')
		.each(function(i){
			jQuery(this).attr('id','main_'+i);
		})
		.each(function(){
			if (jQuery(this).hasClass("active")) {
				leftColumnNavigationObject.main_navigation = this;
			}
		});
		jQuery('#content .left_column .navigation ul').bind('mouseout', function(){
			leftColumnNavigationObject.windowTimeout = window.setTimeout(function(){
				leftColumnNavigationObject.swapList(leftColumnNavigationObject.main_navigation.id);
			}, 1000)
		});
		jQuery('#content .left_column .navigation ul ul').each(function(i){
			jQuery(this).attr('id','sub_'+i);
		});
		jQuery('#content .left_column .navigation ul ul li').each(function(){
			if (this.className != 'active') {
				jQuery(this).mouseover(function(){
					jQuery(this).addClass('active');
				}).mouseout(function(){
					jQuery(this).removeClass('active');	
				})
			}
		});
	}
	LeftColumnNavigation.prototype.swapList = function(i){
		jQuery('#content .left_column .navigation ul li').each(function(){
			if (this.parentNode.parentNode.className == 'navigation') {
				if (this.id == i) {
					jQuery(this).addClass('active');
				} else {
					jQuery(this).removeClass('active');
				}
			}
		});
		return true;
	};
	leftColumnNavigation = new LeftColumnNavigation();
	
	/* -----------------------------------------------------------------------------------
	HOME -- MODULE -- H2
	----------------------------------------------------------------------------------- */
	jQuery('#home .module li h2').css({"opacity":0.90});
	
});