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", "/skin/frontend/default/coker_new/images/arrow.png");
			var id = jQuery(this).attr('id');
			var newDiv = new Array();
			var div = "#"+id;
			clearTimeout(jQuery(div).data('timeoutId'));
			newDiv = id.split('_');
			jQuery('#'+newDiv[1]).fadeIn("slow");
			jQuery('#img_'+newDiv[1]).attr("src", "/skin/frontend/default/coker_new/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", "/skin/frontend/default/coker_new/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", "/skin/frontend/default/coker_new/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();
	});
	
	//open contact window if side contact tab is clicked
	jQuery('#catalog-request-link').click(
		function(e) {
			e.preventDefault();
			jQuery('#catalogRequestWindow').show();
			jQuery('#contactWindow').hide();
	});
	
	//close contact window if close icon is clicked
	jQuery('#catalogWinClose').click(
		function() {
			jQuery('#catalogRequestWindow').hide();
			jQuery('#contactWindow').hide();
			jQuery('#catalog-win-return').html('');
	});
	
	//close contact window if clicked outside
	var mouse_is_inside = false;

    $('#contactWindow').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });
    
    $("body").mouseup(function(){ 
        if(! mouse_is_inside) $('#contactWindow:visible').hide();
    });
    
    //close catalog window if clicked outside
	var mouse_is_inside = false;

    $('#catalogRequestWindow').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });
    
    $("body").mouseup(function(){ 
        if(! mouse_is_inside) {
        	$('#catalogRequestWindow:visible').hide();
        	jQuery('#catalog-win-return').html('');
        }
        
    });
    

	
	//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', '/skin/frontend/default/coker_new/images/all-site-footer/'+name+'-color.png');
		},
		function() {
			var name = $(this).attr('name');
			jQuery(this).attr('src', '/skin/frontend/default/coker_new/images/all-site-footer/'+name+'-gray.png');
		}
	);
	
	//submit catalog request
	jQuery('#catalog-submit').live('click',
			function(e) {
				e.preventDefault();
				var data = {action:'catalog-request'};
				jQuery(".catalog-input").each(function(i) {
					if(jQuery(this).is(':checkbox')) {
						jQuery(this).is(":checked") ? data.emailList='yes' : data.emailList='no';
					} else {
						name = jQuery(this).attr('name');
						value = jQuery(this).val();
						data[name]=value;
					}
		        });
				
				jQuery.post("/tools/ajax.php", data, function(result){
				   jQuery("#catalog-win-return").html(result);
				  });
		});

});
