
var currentid = 0;
var myInterval = null;
var myProductInterval = null;
var delay = 0;

function rotateimages() {
    if ($('div').hasClass("SectionLanding_Query")) {
        if (currentid > 2) {
            currentid = 0;
        }

    }
    if (currentid > 3) {
        currentid = 0;
    }
    var $container = $('#article-rotator');
    var $contentArea = $container.find('#content-area');
    $navthumb = $(".nav-thumb");
    $currentactive = $(".main-content");
    $activeThumbImage = $("#article-list li a");
    $currentactive.removeClass("active");
    $activeThumbImage.css('background-position', 'top left');
    $navthumb.parent().hide();
    slideArrow(currentid + 1);
    $navthumb.eq(currentid).parent().fadeIn("slow", function () { $activeThumbImage.eq(currentid).css("background-position", "bottom left"); currentid = currentid + 1; });
}

function DisplayProducts(objProduct, obj) {

    $("#spotlight").find('span').css({ "display": "none" });
    $(".product_title").css("display", "none");
    $("." + objProduct).find('span').fadeIn();
    $("." + objProduct).css({ "right": "-100px", "top": "-100px" })
    $(".product_bigimg").css({ "width": "244px", "height": "200px", "padding-left": "0px" });
    $(".product1 .product_bigimg").css({ "width": "207px", "height": "170px", "padding-left": "18px" });
    $("." + objProduct).animate({ "right": "0px", "top": "0px" }).fadeIn("slow");
    $(".product_bigimg").delay("1000").animate({ "width": "170px", "height": "141px", "float": "left", "padding-left": "28px" });
    $(".product_title").delay("1500").fadeIn("slow");
    var item_width = $('#product_list li').outerWidth() + 2;
    var left_indent = parseInt($('#product_list').css('left')) - item_width;
    if (obj) {
        $('#product_list:not(:animated)').delay(500).animate({ 'left': left_indent }, 500, function () {


            //...and if it slided to right we put the first item after the last item
            $('#product_list li:last').after($('#product_list li:first'));
            $('#product_list').css({ 'left': '0px' });


        });
    }

}
function SlideShowProducts() {

    if ($("#product_list").css("left") == "-328px") {
        $("#product_list").css({ "left": "0px" }, "slow");
    }
    if ($("#product_list").css("left") == "0px") {
        DisplayProducts($('#product_list li:first').attr('rel'), true);
    }




}
function slideArrow(currentItemId) {
    if (currentItemId == 1) {
        if ($('div').hasClass("SectionLanding_Query"))
        { $(".animate_arrow").stop().animate({ "left": "70px" }); }
        else
            $(".animate_arrow").stop().animate({ "left": "84px" });
    }
    else if (currentItemId == 2) {
        if ($('div').hasClass("SectionLanding_Query"))
        { $(".animate_arrow").stop().animate({ "left": "220px" }); }
        else
            $(".animate_arrow").stop().animate({ "left": "260px" });
    }
    else if (currentItemId == 3) {
        if ($('div').hasClass("SectionLanding_Query"))
        { $(".animate_arrow").stop().animate({ "left": "380px" }); }
        else
            $(".animate_arrow").stop().animate({ "left": "440px" });
    }
    else if (currentItemId == 4) {
        $(".animate_arrow").stop().animate({ "left": "620px" });
    }
}
function settime() {
    myInterval = setInterval("rotateimages()", 10000);
    myProductInterval = setInterval("SlideShowProducts()", 12000);
}

settime();

$(document).ready(function (e) {
    var $container = $('#article-rotator');
    var $articles = $container.find('#article-list li a');
    var $navthumb = $(".nav-thumb");
    rotateimages();
    SlideShowProducts();
    $activeThumbImage = $("#article-list li a");
    $articles.bind('mouseenter', function () {
        clearInterval(myInterval);
        var Currentatag = $(this);
        var currentItemId = $(this).attr('name');
        $navthumb.parent().hide();
        slideArrow(currentItemId);
        $("#" + currentItemId).fadeIn("slow", function () { $activeThumbImage.css('background-position', 'top left'); $(Currentatag).css("background-position", "bottom left") });
    });

    $articles.bind('mouseout', function () {
        myInterval = window.setInterval("rotateimages()", 10000);
    });

    //For products

    $("#product_list li").find('img').bind('mouseenter', function () {

        clearInterval(myProductInterval);
    });
    $("#product_list li").find('img').bind('mouseout', function () {
        clearInterval(myProductInterval);
        myProductInterval = window.setInterval("SlideShowProducts()", 12000);
    });


    $("#product_list li").bind('click', function () {
        var productId = $(this).attr("rel")
        DisplayProducts(productId, false);

        if ($(this).position().left == "0") {
            $("#product_list").delay(1000).animate({ "left": "-82px" }, "slow", function () {
                //...and if it slided to right we put the first item after the last item
                $('#product_list li:last').after($('#product_list li:first'));
                $('#product_list').css({ 'left': '0px' });
            });
        }
        if ($(this).position().left == "82") {
            $("#product_list").delay(1000).animate({ "left": "-164px" }, "slow", function () {
                //...and if it slided to right we put the first item and next item after the last item
                $('#product_list li:last').after($('#product_list li:first'));
                $('#product_list li:last').after($('#product_list li:nth-child(1)'));
                $('#product_list').css({ 'left': '0px' });
            });
        }
        if ($(this).position().left == "164") {
            $("#product_list").delay(1000).animate({ "left": "-246px" }, "slow", function () {
                //...and if it slided to right we put the last item after the first item
                $('#product_list').css({ 'left': '0px' });
                $('#product_list li:first').before($('#product_list li:last'));
            });
        }

    });

});


