﻿/// <reference path="jquery-1.2.6-vsdoc.js" />

var displayFastScroll = true;

// jQuery plug-in to preload images
jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

// jQuery document ready
$(function() {
    //pre load images
    $.preloadImages("/assets/images/fastscrolllefton.png", "/assets/images/fastscrollrighton.png");

    // rollovers
    $("#mainmenuitems a").hover(function() {
        $(this).parent().attr("class", "selected");
    }, function() {
        $(this).parent().attr("class", "");
    });
    $("#ctl00_imgFastScrollLeft").hover(function() {
        $(this).attr("src", "/assets/images/fastscrolllefton.png");
    }, function() {
        $(this).attr("src", "/assets/images/fastscrollleftoff.png");
    });
    $("#ctl00_imgFastScrollRight").hover(function() {
        $(this).attr("src", "/assets/images/fastscrollrighton.png");
    }, function() {
        $(this).attr("src", "/assets/images/fastscrollrightoff.png");
    });


    // product fastscroll mouse events
    if (Silverlight.isInstalled("2.0.31005.0")) {
        $("#ctl00_imgFastScrollLeft").mousedown(function() {
            if ($("#productfastscrollitems").is(":hidden")) {
                showFastScroll();
            }
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.PreviousProduct();
            }
            catch (err) { }
        });
        $("#ctl00_imgFastScrollRight").mousedown(function() {
            if ($("#productfastscrollitems").is(":hidden")) {
                showFastScroll();
            }
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.NextProduct();
            }
            catch (err) { }
        });
        $("#ctl00_imgFastScrollLeft").mouseup(function() {
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.PreviousProductStop();
            }
            catch (err) { }
        });
        $("#ctl00_imgFastScrollRight").mouseup(function() {
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.NextProductStop();
            }
            catch (err) { }
        });
        $("#ctl00_imgFastScrollLeft").mouseover(function() {
            if ($("#productfastscrollitems").is(":hidden")) {
                //showFastScroll();
            }
        });
        $("#ctl00_imgFastScrollRight").mouseover(function() {
            if ($("#productfastscrollitems").is(":hidden")) {
                //showFastScroll();
            }
        });
        $("#ctl00_imgFastScrollLeft").mouseout(function() {
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.PreviousProductStop();
            }
            catch (err) { }
            //if (displayFastScroll == false) { hideFastScroll(); }
        });
        $("#ctl00_imgFastScrollRight").mouseout(function() {
            try {
                var control = $get("ctl00_Xaml1");
                var content = control.content;
                var netObject = content.page;
                netObject.NextProductStop();
            }
            catch (err) { }
            //if (displayFastScroll == false) { hideFastScroll(); }
        });
        $("#productfastscrollitems").mouseout(function() {
            //if (displayFastScroll == false) { hideFastScroll(); }
        });
    }
    else {
        var fastscrollsampleclickevent = function() {
            $("#ctl00_imgProductFastScrollSample01").slideUp("normal", function() {
                $("#ctl00_imgProductFastScrollSample01").slideDown("normal");
            });
        }
        $("#ctl00_imgFastScrollLeft").click(fastscrollsampleclickevent);
        $("#ctl00_imgFastScrollRight").click(fastscrollsampleclickevent);
    }

    // init newsticker
    $("#ctl00_newsticker").newsticker();
    $("#ctl00_newsticker").css("display", "block");


    // Check if to show fastscroll
    if (displayFastScroll == true) {
        showFastScroll();
    }
    else {
        hideFastScroll();
    }


    // Start slideshow
    setInterval("slideSwitch()", 5000);


    // Menu events
    $('#headermenubottom+ul+li').bind("mouseenter", function() {
        resetmenu = false;
        clearInterval(submenuresetInterval);
    })
    $('#headermenubottom+ul+li').bind("mouseleave", function() {
        resetmenu = true;
        submenuresetInterval = setInterval("resetSubMenu()", 1000);
    })
    $('div.submenu').bind("mouseenter", function() {
        resetmenu = false;
        clearInterval(submenuresetInterval);
    })
    $('div.submenu').bind("mouseleave", function() {
        resetmenu = true;
        submenuresetInterval = setInterval("resetSubMenu()", 1000);
    })

});

// Silverlight
function OnNextClick() {
    var control = $get("Xaml1");
    var content = control.content;
    var netObject = content.page;
    netObject.NextProduct();
}
function OnPreviousClick() {
    var control = $get("Xaml1");
    var content = control.content;
    var netObject = content.page;
    netObject.PreviousProduct();
}
function showFastScroll() {
    if ($.browser.msie) {
        $("#productfastscrollitems").show();
    } else {
        var div1 = document.getElementById("productfastscrollitems");
        //div1.style.display = "block";  //this does not work in FireFox
        div1.style.visibility = "visible";  //this works in FireFox
    }
    $("#fastscrolltoggle").html("<a href='javascript:hideFastScroll()'>Close Fastscroll</a>");
}
function hideFastScroll() {
    if ($.browser.msie) {
        $("#productfastscrollitems").hide();
    } else {
        var div1 = document.getElementById("productfastscrollitems");
        //div1.style.display = "none";  //this does not work in FireFox
        div1.style.visibility = "hidden";  //this works in FireFox
    }
    $("#fastscrolltoggle").html("<a href='javascript:showFastScroll()'>Open Fastscroll</a>");
}

// Product section show/hide
function showInformation() {
    $("#ctl00_cphContent_information").show();
    $("#ctl00_cphContent_features").hide();
    $("#ctl00_cphContent_specification").hide();
    $("#ctl00_producttabs").css("background-image", "url(\'/assets/images/producttabsbg01.png\')");
}
function showFeatures() {
    $("#ctl00_cphContent_information").hide();
    $("#ctl00_cphContent_features").show();
    $("#ctl00_cphContent_specification").hide();
    $("#ctl00_producttabs").css("background-image", "url(\'/assets/images/producttabsbg02.png\')");
}
function showSpecification() {
    $("#ctl00_cphContent_information").css("display", "none");
    $("#ctl00_cphContent_features").css("display", "none");
    $("#ctl00_cphContent_specification").css("display", "block");
    $("#ctl00_producttabs").css("background-image", "url(\'/assets/images/producttabsbg03.png\')");
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ($active.length == 0) $active = $('#slideshow IMG:last');

    var $next = $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
    }

    function swapProductImage(image) {
        $('#ctl00_cphTopImages_imgMain1').attr('src', arrThumbImage[image]);
        $('#ctl00_cphTopImages_imgMain' + (image + 1)).attr('src', arrThumbImage[0].replace(/.jpg/, '-thumb.jpg'));
        var mainimage = arrThumbImage[0];
        arrThumbImage[0] = arrThumbImage[image];
        arrThumbImage[image] = mainimage;
    }