// JavaScript Document

	jQuery(document).ready(function() {		
			

		 // for quick view
		// add a click event to the close button which assign tb_remove to the event. tb_remove is a function in thickbox.js to close the thickbox.
		jQuery('#quickViewTop img').live("click", function() {
					tb_remove();
				});
		
		// options that are passed to ajaxSubmit function
		var options = {
			target: '#main_content',
			cache: false,
			beforeSubmit: hideMain
		};
			
		// function called by ajax submit before it submits the form to show the ajax loader image
		function hideMain() {
			jQuery("#mainMiddle").hide();
			jQuery("#mainMiddleLoading").show();
		}
		
		// add event to the left nav and the top options which will submit the form and display the new data
		jQuery("div.left_nav_cell span a").live("click", function(){
			if (jQuery(this).siblings("input:checkbox").attr("checked")){
				 jQuery(this).siblings("input:checkbox").attr("checked", "");
				 if (jQuery(this).attr("class") === "side-nav"){
				 	jQuery(this).removeClass().addClass("side-nav");
				 	jQuery(this).children("img").attr("border", "");
				 }
				 jQuery("#lnForm").ajaxSubmit(options);
			}
			else{
				 jQuery(this).siblings("input:checkbox").attr("checked", "checked");
				 if (jQuery(this).attr("class") === "side-nav2"){
				 	jQuery(this).removeClass().addClass("side-nav2");
				 	jQuery(this).children("img").attr("border", "1");
				 }
				 jQuery("#lnForm").ajaxSubmit(options);
			}
		});
		
		// add event to the selected options to remove that option
		jQuery("ul#cpOptionsSelected li").live("click", function(){
				 var inputId = jQuery(this).attr("class");
				 jQuery("#"+inputId).attr("checked", "");
				 jQuery("#lnForm").ajaxSubmit(options);
		});
		
		// add event to the show more brands on the left nav that when clicked will show more brands
		jQuery("#lnBrandMore").live("click", function(){
				jQuery(this).siblings().removeClass();
				jQuery(this).hide();
		});
				
		
		// add event to the search input that on keyup will make an ajaxcall to get suggestions.
		jQuery("#s").keyup(function(){
			if (jQuery(this).val().match('^[a-zA-Z0-9]+$')){
				jQuery("#autoSuggestHolder").addClass("on");
				jQuery("#autoSuggest").empty();
				
				jQuery("#searchAjaxLoader").show();
				var completeUrl = "/autoSuggest.cfm?searchText=" + jQuery(this).val();
				
				jQuery("#autoSuggest").load(completeUrl, 
					function(response){
							if (response.indexOf("<ul>") < 0){// if am checking if it returned any results based on if we find a ul in it, if there is no ul indexOf will return -1
								jQuery("#autoSuggestHolder").removeClass();
								jQuery("#autoSuggestHolder").hide();
								return false;
							}
							jQuery("#searchAjaxLoader").hide();
						});
			}
			else{
				jQuery("#autoSuggestHolder").removeClass();
				jQuery("#autoSuggestHolder").hide();
			}
		});
		
		jQuery("#s").blur(searchBlur);
		
		function searchBlur(){
				jQuery("#autoSuggestHolder").removeClass();
				jQuery("#autoSuggestHolder").hide();
		}
		
		jQuery("#autoSuggestHolder").mouseover(function(){
			jQuery("#s").unbind("blur");
		});
		
		jQuery("#autoSuggestHolder").mouseout(function(){
			jQuery("#s").blur(searchBlur);
		});

jQuery("#autoSuggest ul li").live("click", function(){
			jQuery("#s").val(jQuery(this).html());
			jQuery("#search_form").submit();
			});
	});
	
			// used for magic zoom so the alt image will be displayed in the magic zoom
		function changeZoomImage() {
		
		// Step 1
		// Stop Magic Zoom
		MagicZoom_stopZooms();
		
		
		// Step 2
		// Re-initialize Magic Zoom
		MagicZoom_findZooms();
		}
		
