// JavaScript Document
jQuery(document).ready(function($) {
	//Hide Admin Bar Buttons
	$("#wp-admin-bar-comments, #adminbarsearch-wrap, #wp-admin-bar-wpseo-kwresearch").hide();
	$('.hideall').css({'margin-left': '-9999em','position':'absolute', 'width': '5px', 'height': '5px', 'overflow':'hidden'});
	//Search Box (remove default text on focus, then put back in)
	$('#cs').focusin(function(){
		var sv = $('#cs').attr('value'); 
		if( sv == 'Enter your keyword' ){ $(this).attr('value', '');}
	});
	$('#cs').focusout(function(){
		var sv = $('#cs').attr('value'); 
		if( !sv ){ $(this).attr('value', 'Enter your keyword');}
	});
	$('#SearchClasses').hover(function(){
		var sv = $('#cs').attr('value'); 
		if( sv == 'Enter your keyword' ){ $('#cs').attr('value', '').addClass('default');}
	},function(){
		if( $('#cs').hasClass('default') ){
			$('#cs').attr('value', 'Enter your keyword').removeClass('default');
		}
	});
	/*Apply active class on parent when hovering on submenu
	$('nav li li a').hover(function(){
			$(this).parent().parent().parent().addClass('active');
		}, function(){
			$(this).parent().parent().parent().removeClass('active');
	});*/
	
	//Add margins to menu li to fill width
	var MenuW = 0;
	$('header nav>ul>li').each(function(){
		MenuW = MenuW + $(this).find('a').width();
	});
	if( MenuW < 680 ){
		var TotalLi = ($('header nav>ul>li').length - 1);
		var Pad = Math.floor(((682 - MenuW)/TotalLi)/2);
		$('header nav>ul>li').each(function(){
			$(this).css('padding', '0 '+Pad+'px');
		});
		$('header nav>ul>li:first').css('padding-left', 0);
		$('header nav>ul>li:last').css('padding-right', 0);
	}
	//Size Footer for fixed Home Height
	function HomeFooter(){
		var HomeH = $(window).height();
		var IsHome = $('.home').length;
		//$('#Sidebar nav').append(HomeH+' ');
		if( IsHome ){
			if( HomeH > 655){
				$('.home .push').css('height', HomeH-555+'px');
				$('.home footer, .home footer #Footer').css('height', HomeH-545+'px');
				$('.home #Wrapper').css('margin-bottom', 0-HomeH+545+'px');
			}else{
				$('.home .push').css('height', '140px');
				$('.home footer, .home footer #Footer').css('height', '150px');
				$('.home #Wrapper').css('margin-bottom', '-150px');
			}
		}
	}
	HomeFooter();
	$(window).resize(function(){HomeFooter()});
	
	//Home Feature Slides
	var speed = $('#Slides').attr('class');
	var int = setInterval(function(){FeatureCycle();}, speed);
	var MenuLI = '.home #Sidebar li';
	var Slide = '#Slides .slide';
	var z = 1;
	var currentFeature = 0;
	var totalF = $(MenuLI).length;
	$('#Slides img:not(:first)').css({'opacity':0});
	
	$('.slide:not(:eq(0)) span').css({opacity:0});
	$(MenuLI+' a').hover(function(){
		clearInterval(int);
		currentFeature = $(this).parent().index();
		updateFeature();	
		z++;	
	}, function(){
		int = setInterval(function(){FeatureCycle();}, speed);
	});	
	$(Slide).click(function(){
		var cur = $(this).index();
		var alink = $(MenuLI+':eq('+cur+') a').attr('href');
		window.location = alink;
	});
	
	
	function FeatureCycle(){		
		if( currentFeature == (totalF-1) ){
			currentFeature = 0;	
		}else{
			currentFeature++;
		}
		updateFeature();		
	}
	function updateFeature(){
		var prev = $(MenuLI+'.current_page_item').index();
		$(MenuLI).removeClass('current_page_item');
		$(Slide+':eq('+currentFeature+')').css({opacity:0});
		$(Slide+':eq('+prev+')').css({opacity:1});
		
		$(MenuLI + ':eq('+(currentFeature)+')').addClass('current_page_item');
		$(Slide+':eq('+currentFeature+')').css('z-index', z).animate({opacity:1}, 600);
		
		z++;	
	}
	
	
});
