var curLargeImage = "";
var inZoom = false;
function fixLeftNavHeight(newHeight){//makes the left nav and content sections equal heights
	var navHeight = $("div.leftNav").height();//height of the left nav
	if (navHeight <= newHeight){//make 'em equal
	   $("div.leftNav").css("height", (newHeight - 16) + "px");
	}
}
function showProdDetails(el, vertBase, horizBase){
		$(el).css(vertBase,0).css(horizBase,0).show();
}
function changeDetailTab(newDisplay){//changes the tab/content for product details (right next to main image)
    $("div#productCopy > div").fadeOut("fast");
    $("ul#detailTabs a").each(function(){
        $(this).removeClass("currentTab");
    });
    switch(newDisplay){
        case "lnkDetails":
        $("a#lnkDetails").addClass("currentTab");
        $("div#prodDetails").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkInspiration":
        $("a#lnkInspiration").addClass("currentTab");
        $("div#prodInspiration").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkDesignElements":
        $("a#lnkDesignElements").addClass("currentTab");
        $("div#prodDesignElements").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkStonesStuff":
        $("a#lnkStonesStuff").addClass("currentTab");
        $("div#prodStonesStuff").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkWearIt":
        $("a#lnkWearIt").addClass("currentTab");
        $("div#prodWearIt").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkJewelryCare":
        $("a#lnkJewelryCare").addClass("currentTab");
        $("div#prodJewelryCare").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
        case "lnkShare":
        $("a#lnkShare").addClass("currentTab");
        $("div#prodShare").jScrollPane({showArrows:false,scrollbarWidth:11,dragMaxHeight:50,dragMinHeight:50, scrollbarMargin:10}).show();
        break;
    }
}
function addToBag(){//add it to the shopping cart
    var oid = $("input#sku").val();//size chosen
    var qty = parseInt($("input#txtQty").val());//quantity entered
    var resultMsg = "";

    if (oid.length==0) {
        alert("Please select a color and size.");
    } else if (qty.length==0 || oid=="NaN") {
        alert("Please indicate the quantity.");
    } else {
        location.href="/_addtobag.aspx?OID="+oid+"&QTY="+qty;
    }
}

function addToWishList(){//add it to the wish list, need an ajax post back to occur here...
    var oid = parseInt($("input#sku").val());//size chosen
    var qty = parseInt($("input#txtQty").val());//quantity entered
    var resultMsg = "";

    if (oid.length==0) {
        resultMsg = "Please select a color and size.";
    } else if (oid.length==0) {
        resultMsg = "Please indicate the quantity.";
    } else {
        resultMsg = "Adding item(s) to your wishlist...";
        $.ajax({
            type: "POST",
            url: "/ajx/wishlist_add.aspx",
            data: "OID="+oid+"&QTY="+qty,
            dataType: "json",
            success: function(objJSONresult){
                resultMsg = objJSONresult.ResponseText;
                $("div.bottomDetailsMsg").text(resultMsg).fadeIn();//display success or fail message
            }
        });    
    }
  
    $("div.bottomDetailsMsg").hide().empty().text(resultMsg).fadeIn();//display success or fail message
    fixLeftNavHeight($("div.contentWhiteBG").height());
}    
$(function(){//bring it
	fixLeftNavHeight($("div.contentWhiteBG").height());
	var $ulAlt = $("div#altViews").children("ul");
	if ($ulAlt.children("li").size() > 1){
	    $("div#altViews").easySlider(//for the alternate views
		    {
			    prevId: 'prevAlt',
			    prevText: '',	
			    nextText: '',
			    nextId: 'nextAlt'
		    }
	    );
	}
	if($("div.collectionSlides").children("ul").children("li").size() > 1){
	    $("div.collectionSlides").easySlider(//for the rest of the collection
		    {
			    prevId: 'prevCollect',
			    prevText: '',	
			    nextText: '',
			    nextId: 'nextCollect'
		    }
	    );
	}
	
	$("ul.topLevelLeftNav > li > a").click(function(){//toggles the left hand navigation on clicking category titles
		$("ul.leftSubLevelNav").each(function(){
		    $(this).slideUp();
		});
		$(this).siblings("ul.leftSubLevelNav").slideToggle();
		return false;
	});
	$("ul#detailTabs a").click(function(){//change the productContent copy
	    var thisLinkID = $(this).attr("id");
	    $("#prodDetails, #prodDesignElements, #prodStonesStuff, #prodJewelryCare, #prodInspiration, #prodWearIt, #prodShare").jScrollPaneRemove();
	    changeDetailTab(thisLinkID);
	    return false;
	});
	$("a#addToBag").click(function(){
	    addToBag();
	    return false;
	});
	$("a#addToWish").click(function(){
	    addToWishList();
	    return false;
	});
	$("a#prodZoom").click(function(){
	    if (curLargeImage.length>0) $("img#imgLarge").attr("src",curLargeImage);
	    document.getElementById("FlashID").zoomToggle();
	    inZoom=!inZoom;
	    return false;
	});
});
function doScaleRuler(val) {
    if (val != $("img#imgLarge").attr("src")) curLargeImage = $("img#imgLarge").attr("src");
    if (inZoom) {inZoom=false; document.getElementById("FlashID").zoomToggle();}
    $("img#imgLarge").attr("src",val);
}
function swapZoom(full,zoom) {
    curLargeImage = full;
    $("img#imgLarge").attr("src",full);
    var mov = swfobject.getObjectById("FlashID");
    if (mov) mov.newZoomImage(zoom);
}
