jQuery(document).ready(function($){
	
	//open shopby menu on mouseover, close on mouseout with delay
	jQuery('.shopby_item').hover(
			function() {
				jQuery('.shopby_item img').attr("src", "/wp-content/themes/coker/images/arrow.png");
				var id = jQuery(this).attr('id');
				var div = "#"+id;
				var newDiv = new Array();
				clearTimeout(jQuery(div).data('timeoutId'));
				newDiv = id.split('_');
				jQuery('#'+newDiv[1]).fadeIn("slow");
				jQuery('#img_'+newDiv[1]).attr("src", "/wp-content/themes/coker/images/arrow_hover_flip.png");
			},
			function() {
				var id = jQuery(this).attr('id');
				var newDiv = new Array();
				newDiv = id.split('_');
				var someelement = this;
			    var timeoutId = setTimeout(function(){ jQuery('#'+newDiv[1]).fadeOut("fast"); jQuery('#img_'+newDiv[1]).attr("src", "/wp-content/themes/coker/images/arrow.png");}, 400);
				var div = "#"+id;
			    jQuery(div).data('timeoutId', timeoutId); //set the timeoutId, allowing us to clear this trigger if the mouse comes back over
			}
		);
	
	//continue to leave shopby menu open on mouseover, close on mouseout with delay
	jQuery('.shopby_etc').hover(
		function() {
			var id = jQuery(this).attr('id');
			clearTimeout(jQuery("#shopby_"+id).data('timeoutId'));
		},
		function() {
			var id = jQuery(this).attr('id');
		    var timeoutId = setTimeout(function(){ jQuery('#'+id).fadeOut("fast"); jQuery('#img_'+id).attr("src", "/wp-content/themes/coker/images/arrow.png");}, 300);
		    jQuery("#shopby_"+id).data('timeoutId', timeoutId); //set the timeoutId, allowing us to clear this trigger if the mouse comes back over
		}
	);
	
	
	//zoom social icons on mouseover
	jQuery('#header_social img').hover(
			function() {
				var add = 10;
				var newWidth = jQuery(this).width() + add;
				var newHeight = jQuery(this).height() + add;
				jQuery(this).width(newWidth);
				jQuery(this).height(newHeight);
			},
			function() {
				var add = 10;
				var newWidth = jQuery(this).width() - add;
				var newHeight = jQuery(this).height() - add;
				jQuery(this).width(newWidth);
				jQuery(this).height(newHeight);
			}
	);
	
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	}; 
	
	//open contact window if side contact tab is clicked
	jQuery('#contactSide').click(
		function() {
			jQuery('#contactWindow').show();
	});
	
	//open contact window if email icon is clicked
	jQuery('#contactLink').click(
		function() {
			jQuery('#contactWindow').show();
	});
	
	//close contact window if close icon is clicked
	jQuery('#contactWinClose').click(
			function() {
				jQuery('#contactWindow').hide();
	});
	
	//close contact window if esc key is pressed
	jQuery(document).keyup(function(e) {
		if (e.keyCode == 27) { 
			if(jQuery('#hiddenFAQClose').is(':visible')) {
				jQuery('#hiddenFAQClose').click(); 
			} else {
				jQuery('#contactWinClose').click(); 
			}
			
			
		}   // esc
	});
	
	jQuery('#readMoreFaq').live('click',
		function(e) {
			e.preventDefault();
			jQuery('#hiddenFAQ').show();
	});
	
	//close contact window if close icon is clicked
	jQuery('#hiddenFAQClose').live('click',
			function() {
				jQuery('#hiddenFAQ').hide();
				jQuery('#faqText').html('').load('/Toptext/');
	});
	
	jQuery('#faqReload').click(
			function(e) {
				e.preventDefault();
				jQuery('#faqText').html('').load('/Toptext/');
	});
	
	jQuery('.asfImage').hover(
			function() {
				var name = $(this).attr('name');
				jQuery(this).attr('src', '/wp-content/themes/coker/images/all-site-footer/'+name+'-color.png');
			},
			function() {
				var name = $(this).attr('name');
				jQuery(this).attr('src', '/wp-content/themes/coker/images/all-site-footer/'+name+'-gray.png');
			}
		);
	
	jQuery('.cat-plus').click(function(e) {
		if(jQuery(this).parent().children('ul.children').is(':visible')) {
			jQuery(this).parent().children('ul.children').hide(); 
			jQuery(this).attr('src', '/wp-content/themes/coker/images/plus.png');
		}else {
			jQuery(this).parent().children('ul.children').show(); 
			jQuery(this).attr('src', '/wp-content/themes/coker/images/minus.png');
		}
		
	});
});
