﻿
$("document").ready(function() {
    ShowProductDesc();
    ShowProductImages();
});

$(function() {

$("#description").click(function() {
        $("#product-specs a[class]").removeAttr("class");
        ShowProductDesc();
    });
    $("#specifications").click(function() {
        $("#product-specs a[class]").removeAttr("class");
        $("#specifications a").attr("class", "selected_tab");
        $("#SpecificationsContent").show();
        $("#DescriptionContent").hide();
        $("#DimentionContent").hide();
        $("#AccessoriesContent").hide();
        $("#DownloadsContent").hide();
    });
    $("#dimensions").click(function() {
        $("#product-specs a[class]").removeAttr("class");
         $("#dimensions a").attr("class", "selected_tab");
        $("#DimentionContent").show();
        $("#SpecificationsContent").hide();
        $("#DescriptionContent").hide();
        $("#AccessoriesContent").hide();
        $("#DownloadsContent").hide();
    });
    $("#accessories").click(function() {
        $("#product-specs a[class]").removeAttr("class");
        $("#accessories a").attr("class", "selected_tab");
        $("#AccessoriesContent").show();
        $("#DownloadsContent").hide();
        $("#DescriptionContent").hide();
        $("#SpecificationsContent").hide();
        $("#DimentionContent").hide();
    });
    $("#downloads").click(function() {
        $("#product-specs a[class]").removeAttr("class");
         $("#downloads a").attr("class", "selected_tab");
        $("#DownloadsContent").show();
        $("#DescriptionContent").hide();
        $("#SpecificationsContent").hide();
        $("#DimentionContent").hide();
        $("#AccessoriesContent").hide();
    });
});

function ShowProductDesc() {
    $("#description a").attr("class", "selected_tab"); //css("background-color", "#30303E");
    $("#DescriptionContent").show();
    $("#SpecificationsContent").hide();
    $("#DimentionContent").hide();
    $("#AccessoriesContent").hide();
    $("#DownloadsContent").hide();
}

function ShowProductImages() {
    $("#ImagesContainer").show();
    $("#animated_gif").hide();
    $("#video_fold").hide();
    $("#LifeStyleImagesContainer").hide();
}

function ShowLifeStyleImages() {
    $("#ImagesContainer").hide();
    $("#animated_gif").hide();
    $("#video_fold").hide();
    $("#LifeStyleImagesContainer").show();
}

function ShowRatation() {
    $("#ImagesContainer").hide();
    $("#animated_gif").show();
    $("#video_fold").hide();
    $("#LifeStyleImagesContainer").hide();
}

function ShowVideo() {
    $("#ImagesContainer").hide();
    $("#animated_gif").hide();
    $("#video_fold").show();
    $("#LifeStyleImagesContainer").hide();
}

//imgid,imageurl
function SwapImage(maincontrolid,imgid) {
    var mainImgOriginal = $("#" + maincontrolid).attr("src");
    var newThumbImg = mainImgOriginal.replace("maxwidth=490&maxheight=390", "maxwidth=175&maxheight=120");
   
    var thumbImgOriginal = $("#" + imgid).attr("src");
    var NewMainImg = thumbImgOriginal.replace("maxwidth=175&maxheight=120", "maxwidth=490&maxheight=390");
//    alert("New Main:" + NewMainImg);
//    alert("New Thumb:" + newThumbImg);
    $("#" + maincontrolid).attr("src", NewMainImg);
    $("#" + imgid).attr("src", newThumbImg);
}

function SwapImageByColor(imgurl) {
    if (imgurl.length > 0) {
        var mainImgOriginal = $("#ProdMain").attr("src");
        var NewMainImgurl = "ImageHandler.ashx?maxwidth=490&maxheight=390&path=" + imgurl; //color img url
        //    var ThumbImgList = $("#thumbcontainer img");
        //    alert(ThumbImgList.length);
        if (mainImgOriginal != NewMainImgurl) {//if main img not equal to color img url
            NewMainImgurl = NewMainImgurl.replace("maxwidth=175&maxheight=120", "maxwidth=490&maxheight=390");
            $("#ProdMain").attr("src", NewMainImgurl); //replace main img with color img url

            $("#thumbcontainer img").each(function(index) {
                // alert(index + ': ' + $(this).attr("src"));
                if ($(this).attr("src").indexOf(imgurl) != -1) {
                    // alert("Found same thumb");
                    mainImgOriginal = mainImgOriginal.replace("maxwidth=490&maxheight=390", "maxwidth=175&maxheight=120");
                    //   alert(mainImgOriginal);
                    $(this).attr("src", mainImgOriginal);
                }
            });
        }
    }
}
