	// /////////////////////////////////////////////////////
	// Mountain Equipment
	// Version 1.2	
	
	// ------------------------------------------------------------------
	// Dropdown menus and navigation
	// ------------------------------------------------------------------
	
	var navLevel = new Array();
	var meNavDefaultLink = "/index.php/category/";
	
	//navLevel[0] = "#navX";
	//navLevel[1] = "#nav12";
	//navLevel[2] = "#nav123";


	// initDropDowns - Show and hide functions for the menu drop down effect
	me_initDropDowns = function() {
		// Show menu on click
		jQuery("div.navBox > span").each(
			function() {
				jQuery(this).click(	
					function() {
						jQuery(this).siblings("div.dropDown").slideDown(300);
					}
				);
			}
		);
		// Hide menu when mouse leaves
		jQuery("div.navBox").each(
			function() {
				jQuery(this).bind("mouseleave",
					function() {
						jQuery(this).children("div.dropDown").slideUp(300);
					}
				);
			}
		);

		// Set dafault link for "Go"
		jQuery("#navBoxGoLink").attr("href", meNavDefaultLink);

		// Show menus with current settings selected shown
		jQuery("#navBox0").nextAll(".navBox").fadeOut(1);
		for (var level=0; level<4; level++) {
			if (navLevel[level]) {
				me_setNav(level,navLevel[level],jQuery("#"+navLevel[level]+" > a").text());
			}
		}
		
		// Show refine by on click
		jQuery("div#refine_by > span").click( function() { jQuery("div#filter_sort").slideDown(300); } );
		
		// Hide refine menu when mouse leaves
		jQuery("div#filter_sort").bind( "mouseleave", function() { jQuery("div#filter_sort").slideUp(300);} );

		
	}

	me_showMenu = function(level) {
		//var parentNavId = null;
		var navId = "nav0";

		if (level > 0 ) {
			if (navLevel[level-1] == null) {
				return(false);	// Parent not set
			}
			navId = navLevel[level-1];
		}

		// Add contents to nav box / drop down
		var boxId = "navBox" + level;
		jQuery("#" + boxId + " div.dropDown").empty();
		
		//var caption = jQuery(navLevel[level]+" > a").text();
		//jQuery(boxId+" > span").text(caption);
		//alert('boxid=' + jQuery("#" + boxId).width());
		//alert('boxid dropdown=' + jQuery("#" + boxId + " div.dropDown").width());

		
		jQuery("#" + navId + " > ol > li").each(
			function(i) {
				//alert(jQuery(this).width());
				var navOptionId = this.id;
				var captionText = jQuery("#" + navOptionId + " > a").html();
				var aElement = document.createElement('a');
				jQuery(aElement).attr({
					href: "#"
				})
				.addClass("navOption")
				.html(captionText)
				.bind("click", function(){ me_setNav(level,navOptionId,captionText)} )
				.appendTo("#" + boxId + " div.dropDown");	
				
				
			}
		);
		if(jQuery("#" + boxId + " div.dropDown").width() < jQuery("#" + boxId).width()) {
			jQuery("#" + boxId + " div.dropDown").width(jQuery("#" + boxId).width());
		}

	}

	me_setNav = function(level, id, caption) {
		navLevel[level] = id;
		var navId = "#navBox" + level;
		
		var navLink = jQuery("#" + id + " > a").attr("href");
		jQuery("#navBoxGoLink").attr("href", navLink || meNavDefaultLink);

		// Clear sub option dropdown captions
		jQuery(navId).nextAll(".navBox").fadeOut(1);
		jQuery(navId).nextAll(".navBox").children("span").text("All");
		if(jQuery("#"+id+" > ol").length > 0) {
			jQuery(navId).next(".navBox").fadeIn(300);
		}

		// Disable sub drop downs where there are no sub options

		// Add selected option's text to dropdown caption
		jQuery(navId+" > span").html(caption);

		// Animate-close the drop down
		jQuery(navId).children("div.dropDown").slideUp(300);
	}

	// ------------------------------------------------------------------
	// Ajax / overlays
	// ------------------------------------------------------------------
	
	me_keywordSearch = function(formId,fieldId) {
		var searchString = new String(jQuery("#"+fieldId).attr('value'));
		var pattern = new RegExp("\\w+","g");		
		if (!pattern.test(searchString)){
			return false;
		}
		
		var formDataString = jQuery("#"+formId).serialize();
		var formAction = jQuery("#"+formId).attr("action");

		jQuery("#defaultModalWindow > .modalContent").html("");		
		me_openModalWindow("defaultModalWindow");
		jQuery("#defaultModalWindow .modalAjaxLoader").show();
				
	 	jQuery.ajax({
			type: "POST",
			url: formAction,
			data: formDataString,
			dataType: "html",
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert("ERROR: "+textStatus + "\n error thrown: " + errorThrown);	
			},
			success: function(data, textStatus){
  				//alert("SUCCESS: "+data);
  				jQuery("#defaultModalWindow > .modalContent").html(data);
  				jQuery("#defaultModalWindow .modalAjaxLoader").hide();
			}		
		 });
		
	}

	
	
	// ------------------------------------------------------------------
	// Forms ** not working
	// ------------------------------------------------------------------
	
	function Me_searchForm(form, field, emptyText) {
        this.myForm   = jQuery("#"+form);
        this.myField  = jQuery("#"+field);
        this.myEmptyText = jQuery("#"+emptyText);

		this.mySubmit = function(event) {
	    	alert('checking');
	        if (this.myField.value == this.myEmptyText || this.myField.value == ''){
	            event.preventDefault();
	            return false;
	        }
	        return true;
		}		
	
	    this.myFocus = function(event){
	        if(this.myField.attr('value')==this.myEmptyText){
	            this.myField.attr('value','');
	        }
	    }
	
	    this.myBlur = function(event){
	        if(this.myField.attr('value')==''){
	            this.myField.attr('value',this.myEmptyText);
	        }
	    }

        this.myForm.bind('submit', this.mySubmit);
        this.myField.bind('focus', this.myFocus);
        this.myField.bind('blur', this.myBlur);
        this.myBlur();

	}

    	