﻿$(document).ready(function () {

    //set title
    var title = $('#rotator > *').eq(0);
    var titleVal = title.attr("alt");
    var $name = $('.imageTitle');
    $name.text(titleVal);

    //set price
    var price = $('#rotator > *').eq(0);
    var priceVal = price.attr("id");
    var $price = $('.imagePrice');
    $price.text(priceVal);

});

var intervalId;
function Rotate() {
    var $active = $('#rotator IMG.active');
    if ($active.length == 0) $active = $('#rotator IMG:last');

    var $activemap = $('#imgmap IMG.active');
    if ($activemap.length == 0) $activemap = $('#imgmap IMG:last');

    var $next = $active.next().length ? $active.next() : $('#rotator IMG:first');
    var $nextmap = $activemap.next().length ? $activemap.next() : $('#imgmap IMG:first');

    $active.addClass('last-active');
    $activemap.addClass('last-active');

    $next.css().addClass('active');
    $nextmap.css().addClass('active');

    // set title
    var title = $next.attr('alt');
    var $title = $('.imageTitle');
    $title.text(title);

    var price = $next.attr('id');
    var $price = $('.imagePrice');
    $price.text(price);


    $active.removeClass('active last-active');
    $activemap.removeClass('active last-active');

}

function DisplayFavorite(selectedIndex) {
    //  alert(selectedIndex);
    clearInterval(intervalId);

    var $active = $('#rotator IMG.active');
    var $activemap = $('#imgmap IMG.active');

    $active.addClass('last-active');
    $activemap.addClass('last-active');

    $active.removeClass('active last-active');
    $activemap.removeClass('active last-active');

    //nth attribute starts with 1 so we'll need to add +1
    var index = selectedIndex + 1;
    var $displayimg = $('#rotator :nth-child(' + index + ')');
    var $displaymap = $('#imgmap :nth-child(' + index + ')');

    $displayimg.addClass('active');
    $displaymap.addClass('active');

    //set title
    var title = $('#rotator > *').eq(selectedIndex);
    var titleVal = title.attr("alt");
    var $name = $('.imageTitle');
    $name.text(titleVal);

    //set price
    var price = $('#rotator > *').eq(selectedIndex);
    var priceVal = price.attr("id");
    var $price = $('.imagePrice');
    $price.text(priceVal);

}

function ShopNow() {  
    var activeProduct = $('#rotator .active');
    var productName = activeProduct.attr("name");   
    var formshop = $("#frmshop");
    formshop.attr("action",  productName );   // --> webproductName,hidden somewhere..lose the "/url" path part
    formshop.submit();

}
function Reset() {
  
    $(function () {
        intervalId = setInterval("Rotate()", 3000);
    });
}
$(function () {
    intervalId = setInterval("Rotate()", 3000);
});