﻿function clearText(sender, text) {
    
    if ($(sender).val() == text)
        $(sender).val("");
}

function restoreText(sender, text) {
    
    if ($(sender).val() == "")
        $(sender).val(text);
}

// pause flash movie player
function PauseMovie(flashName) {
    try
    {
        var theFlash = document.getElementById("flv" + flashName);
        if (theFlash != null)
            theFlash.PauseMovie();
    } catch (e)
    {}
}

// pause flash movie player
function PlayMovie(flashName) {
    try
    {
        var theFlash = document.getElementById("flv" + flashName);
        if (theFlash != null)
            theFlash.PlayMovie();
    } catch (e)
    {}
}

// show tab content on the product pages
function openTab(tabId, link) {
    var tabName = tabId;
    
    if (link != "")
    {
        window.location = link;
        return;
    }
    
    if (tabName == "" || tabName == null)
    {
        $(".tab").each(function() {
            if (tabName == "" || tabName == null)
            {
                tabName = $(this).attr("id");
            }
        });
    }

    $(".productTabContent").each(function() {
        
        // general tab content and tab link control
        if ($(this).attr("tabName") == tabName)
        {
            $("#" + $(this).attr("tabName")).addClass("on");
            $(this).show();
        }
        else
        {
            $("#" + $(this).attr("tabName")).removeClass("on");
            $(this).hide();
        }
    });
    
    // custom tab content control
    if (tabName == "video")
        showVideo();
        
    if (tabName == "videoTutorial")
    {
        showTutorialVideo();
    }
    if (tabName == "pictures")
    {
        showPicture("", "");
        $("#pictureBox").load(function(){
            centerObjectVertically("pictureBox");
        });
    }
    if (tabName == "animation")
    {
        showAnimation();
    }
    if (tabName == "accessories")
    {
        showAccessories();
    }
    else
    {
        $("#productDescriptionArea").show();
        $("#accessoryDescriptionArea").hide();
    }
}

function showAccessories() {
    
    $("#pictureBox").hide();
    $("#accessoryPictureBox").show();
    $("#accessoryDescriptionArea").show();
    $("#productDescriptionArea").hide();
    $("#flashVideoPlayer").hide();
    $("#flashVideoPlayerTutorial").hide();
    $("#flashAnimation").hide();
    PauseMovie("flashVideoPlayer");
    
    $("#accessoryArea").show();
    
    centerObjectVertically("accessoryPictureBox");
}

function showTutorialVideo() {
    $("#pictureBox").hide();
    $("#accessoryPictureBox").hide();
    $("#flashVideoPlayer").hide();
    $("#flashVideoPlayerTutorial").show();
    $("#flashAnimation").hide();
    $("#accessoryArea").hide();
    $("#accessoryDescriptionArea").hide();
    PauseMovie("flashVideoPlayer");
}

// show flash video and hide picture box
function showVideo() {
    $("#pictureBox").hide();
    $("#accessoryPictureBox").hide();
    $("#flashVideoPlayerTutorial").hide();
    $("#flashVideoPlayer").show();
    $("#flashAnimation").hide();
    $("#accessoryArea").hide();
    $("#accessoryDescriptionArea").hide();
    PlayMovie("flashVideoPlayer");
}

function showAnimation() {
    $("#pictureBox").hide();
    $("#accessoryPictureBox").hide();
    $("#flashVideoPlayerTutorial").hide();
    $("#flashVideoPlayer").hide();
    $("#flashAnimation").show();
    $("#accessoryArea").hide();
    $("#accessoryDescriptionArea").hide();
    PauseMovie("flashVideoPlayer");
}

// show picture box and hide flash video
function showPicture(fileName, linkButton) {

    // stop playing the movies
    PauseMovie("flashVideoPlayer");

    var width = 718;
    
    // hide video tab and show selected image
    $("#flashVideoPlayer").hide();
    $("#flashVideoPlayerTutorial").hide();
    $("#flashAnimation").hide();
    $("#accessoryArea").hide();
    $("#accessoryDescriptionArea").hide();
    $("#accessoryPictureBox").hide();
    
    // set the file name of the picture
    if (fileName != "")
    {
        $("#pictureBox").attr("src", "ShowImage.ashx?size=" + 718 + "&isWidth=True&image=" + fileName);
        centerObjectVertically("pictureBox");
    }

    $("#pictureBox").show();
    centerObjectVertically("pictureBox");

    // highlight the selected picture
    if (linkButton != "")
    {
        // deselect every image, select clicked image
        $(".pictureContainer a").each(function () {
            $(this).removeClass();
        });
        $(linkButton).addClass("on");
    }
} 

function initializePicture(fileName)
{
    $("#pictureBox").attr("src", "ShowImage.ashx?size=" + 718 + "&isWidth=True&image=" + fileName);
    centerObjectVertically("pictureBox");
}

function showHideAdditionalInfo() {
    $("#additionalInfo").toggle();
}

/* accessories */
function showAccessoryDescription(accessoryId, fileName, show)
{
    // hide all accessory info
    //$(".accessoryMainImage").each(function(){$(this).hide();});
    $(".accessoryDescription").each(function(){$(this).hide();});
    

    //show accessory description
    var description = $("#accessoryDescription" + accessoryId).html();
    $("#accessoryDescriptionArea").html(description);
    
    
    // show image
    if (fileName != "")
    {
        $("#accessoryPictureBox").attr("src", "ShowImage.ashx?size=" + 718 + "&isWidth=True&image=" + fileName);
        centerObjectVertically("accessoryPictureBox");
    }
}


function centerObjectVertically(objName)
{
    var obj = $("#" + objName);
    var topMargin = ($(obj).parent().height() - $(obj).height()) / 2;
    var leftMargin = ($(obj).parent().width() - $(obj).width()) / 2;
    $(obj).css("margin-top", topMargin);
    $(obj).css("margin-left", leftMargin);
}