﻿var $k = jQuery.noConflict();

$k(document).ready(
		function() {

		    if (jQuery.browser.safari && document.readyState != "complete") {
		        //console.info('ready...');
		        setTimeout(arguments.callee, 100);
		        setImageWidth();
		        return;
		    }
		    else { setImageWidth(); }
		    $k("a[rel='search']").click(function() { doSearch() });
		    $k("#searchKeyword").keypress(function(e) { return submitKeyword(e.keyCode, e.which) });

		    //			$k("a[rel='folder']").each(function(){
		    //			if($k(this).href == window.location.pathname)
		    //			       $k(this).href = "javascript:null();";});

		    $k("a[rel='folder']").click(function() {
		        $k("ul.left-subNav").hide("slow");
		        if ($k(this).next(".left-subNav").is(":hidden")) {
		            $k(this).next(".left-subNav").show("slow");
		        }
		        else { $k(this).next(".left-subNav").hide("slow"); }
		    });

		    $k("ul.left-subNav").hide();

		    $k("ul.left-subNav").each(function(i) {
		        if ($k(this).find("a.active").length > 0) {
		            $k(this).show();
		        }
		    });

		});

function setImageWidth() {
    if ($k("ol.product-dimensions").length > 0) {
        var xe = 544 - 10 - $k("ol.product-dimensions")[0].offsetWidth - parseInt($k(".product-image img")[0].width); //429,144
        $k("ol.product-meta").css("max-width", xe);
    }
}
function submitKeyword(keyCode, which) {
    if (which == null) {
        if (event.keyCode == 13) {
            doSearch();
            return false;
        }
    }
    else if (which > 0) {
        if (which == 13) {
            doSearch();
            return false;
        }
    }
}

function doSearch() {
    var currentUrl = window.location.href;
    var searchInput = document.getElementById("searchKeyword").value;

    window.location = "http://" + location.host + "/Search-Results.aspx?search=" + searchInput + "&site=True";
}

