﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

$("tab_system").ready(function() {

    hideTabbingStuff();
    for (var i = 1; i <= 4; i++) {
        $("#tab_" + i).click(function() {
            hideTabbingStuff();
            showTabStuff(this);
        });
    }

    for (var i = 1; i <= 4; i++) {
        if ($("[rid=" + i + "]").html() == "") {
            $("#tab_" + i).remove();
        }
    }

    showTabStuff($("div.tabbed_content_menu:first"));
});


$("image_container").ready(function() {
    $("#a_zoom").hide();
    $("#a_seevideo").hide();
    var imagePath = $("img[id='product_image']").attr("src");
    var bigImagePath = imagePath.replace(/-z/, "-k");
    if ($("#video_container").length <= 0) {
        $("#a_seeimage").hide();
        if (urlExists(bigImagePath))
            $("#a_zoom").show();
        else
            $("#a_zoom").hide();
        //$("div.product_image_taskbar").remove();
        //$("#product_image_container").height("288px");
    }
});





$(document).ready(function() {
    $("input[alt='Add To Cart']").click(function() {
        if ($("input[name='style_id']")) {
            $("#product_detail_form").append($("input[name='style_id']"));
        }
        if ($("#l1desc").length > 0) {
            $("#product_detail_form").append("<input type='hidden' name='l1desc' value='" + $("#l1desc").val() + "'/>");
        }
        $("#product_detail_form").submit();
    });

    $("input[acc='1']").each(function() {
        if ($(this)[0].checked) {
            $("#product_detail_form").append("<input type='hidden' name='accessory' id='" + $(this)[0].id + "' value='" + $(this)[0].value + "' />");
        }
    });

    $("input[acc='1']").click(function() {
        var elementInQuestion = document.getElementById($(this).attr("id"));
        if (elementInQuestion.checked) {
            $("#product_detail_form").append("<input type='hidden' name='accessory' id='" + elementInQuestion.id + "' value='" + elementInQuestion.value + "' />");
        }
        else {
            $("#product_detail_form input[id='" + elementInQuestion.id + "']").remove();
        }
    });






    // disables magic zoom requirement stuff..
    $("a[rel='main_image']").attr("href", "javascript:void(0);");
    //$("a[id='main_image']").attr("href", "javascript:void(0);");


    $("#a_seeimage").click(function() {
        showImage();
    });

    $("#a_seevideo").click(function() {
        showVideo();
    });

    $("#a_zoom").mouseenter(function() {
        $("#a_zoom").attr("href", $("a[id='main_image']").attr("href"));
    });


    $("a[rel='main_image']").click(function() {
        var imagePath = $(this).attr("rev");                
        $("img[id='product_image']").attr("src", imagePath);
        $("a[id='main_image']").attr("href", imagePath.replace(/-z/, "-k"));
        showImage();
    });
});


function showOverlay(time) {
    window.setTimeout(function() {
        $("#dialog").dialog({
            bgiframe: true,
            width: 570,
            hide: 'explode',
            position: [$(window).width() - 585, $(window).height() - 200],
            show: { effect: "fadeIn", duration: 3000 }


        });
    }, time)
}

$("#xq").ready(function() {
	if (document.getElementById("overlayhyperlink")) {
		$("#overlayhyperlink").attr("href", "/shop.axd/AddToCartBP?qty=1&sourcecode=" + overlayPromoCode + "&edp_no=" + overlayProductEdp);
	}
});


function showImage() {
    //$("#image_container").css("z-index", "2");
    //$("#video_container").css("z-index", "1");
    var imagePath = $("img[id='product_image']").attr("src");
    var bigImagePath = imagePath.replace(/-z/, "-k");
    
    $("#image_container").css("visibility", "visible");
    $("#video_container").css("visibility", "hidden");
    if ($("#video_container").length > 0) { $("#a_seevideo").show(); }
    if (urlExists(bigImagePath))
        $("#a_zoom").show();
    else
        $("#a_zoom").hide();
    $("#a_seeimage").hide();  
}

function showVideo() {
    //$("#image_container").css("z-index", "1");
    //$("#video_container").css("z-index", "2");
    $("#image_container").css("visibility", "hidden");
    $("#video_container").css("visibility", "visible");
    $("#a_seeimage").show();
    $("#a_zoom").hide();
    $("#a_seevideo").hide();
}

function submitForm(frmName, frmAction) {
    //var frm = document.forms[frmName];
    $("form[name='" + frmName + "']").attr("action", frmAction).submit();
    //frm.action = frmAction;
    //frm.submit();
}

function initTaskbar() {

    var zip = $("#product_image").attr("zoom_image_path");
    if (zip.search("unavailable") != -1) {
        $(".taskbar_zoom").hide();
    }
}

function hideTabbingStuff() {    
    for (var i = 1; i <= 4; i++) {
        $("#tab_" + i).attr("class", "tabbed_content_menu blur_" + i);
        $("#content_" + i).hide();
    }    
}

function showTabStuff(_obj) {
    var _tabNo = $(_obj).attr("tid");
    $("#tab_" + _tabNo).removeClass("blur_" + _tabNo);
    $("#tab_" + _tabNo).addClass("focus_" + _tabNo);
    $("#content_" + _tabNo).show('slow');
}
