// JavaScript Document

	jQuery(document).ready(function() {		
			
			// for the search
		$("input.go").click(function(){
																 window.location = "/category.cfm?kword=" + encodeURIComponent($("input#s").val() );
																 return false;
																 });
			
//tb_init('a.pleasework, area.pleasework, input.pleasework');
		 // 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_body_category',
			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").addClass("cpImageBorder");
				 }
				 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").removeClass();
				 }
				 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();
			}
		});
		
		// this will remove the auto suggest dropdown when they click out of the dropdown.
		jQuery("#s").blur(searchBlur);
		
		function searchBlur(){
				jQuery("#autoSuggestHolder").removeClass();
				jQuery("#autoSuggestHolder").hide();
		}
		
		// this will remove the blur event from the input field when they are in the auto suggest box, so they can click a suggestion and the box will not disappear.
		jQuery("#autoSuggestHolder").mouseover(function(){
			jQuery("#s").unbind("blur");
		});
		//this will rebind the blur event to the input field when they mouse out of the dropdown so if they click now anywhere on the page the auto suggest dropdown will disappear.
		jQuery("#autoSuggestHolder").mouseout(function(){
			jQuery("#s").blur(searchBlur);
		});
		// when they click one of the suggestions it will set the input field with that value and submit the form.
		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();
		}

