﻿//Top Sellers

var offerCurrentItem = 1;
var offerScrollCount = 2; // The number of items to scroll per click
var offerListCount = 0;
var i = 0;
var offerList, offerListItem, offerListHeight, offerViewHeight, offerViewCount;
    

$(document).ready(function() {
    offerListHeight = 0;
    offerViewHeight = 0;
    
    offerListCount = $('#topSellersList li').length; 
    offerListHeight = ($('#topSellersList > li').select()) ? $('#topSellersList > li').select().outerHeight(true) : 1;
    
    $("#topSellersView").css("height", (offerListHeight * offerScrollCount) + "px");
    
    offerViewHeight = ($('#topSellersView')) ? $('topSellersView').outerHeight(true) : 1;
    offerViewCount = Math.floor(offerViewHeight / offerListHeight);

    $("#tsUp").select().click(function(el){
        el.preventDefault();
        if (offerCurrentItem > 1){
            offerCurrentItem -= offerScrollCount;
            moveTSScroller()
        }
    });
    
    $("#tsDown").select().click(function(el){
        el.preventDefault();
        if (offerCurrentItem <= offerListCount - offerScrollCount){
            offerCurrentItem += offerScrollCount;
            moveTSScroller()
        }        
    });
    
    function moveTSScroller(){
        var moveHeight = -((offerCurrentItem - 1) * offerListHeight);
        $("#topSellersList").animate({
            top: moveHeight 
        }, 500);
        
        //alert("List height: " + offerListHeight + ", View height: " + (offerListHeight * offerScrollCount) + ", Move height: " + moveHeight);
        
        if (offerCurrentItem > offerListCount - offerScrollCount) {
            $("#tsDown").addClass("disabled");
            $("#tsUp").removeClass("disabled");
        } else if (offerCurrentItem <= 1) {
            $("#tsUp").addClass("disabled");
            $("#tsDown").removeClass("disabled");
        } else {
            $("#tsDown").removeClass("disabled");
            $("#tsUp").removeClass("disabled");
        }
    }
    
    //Product details thumbnail switcher
    /*$('div#productImageThumbs img').each(function(sel){
        Event.observe(sel, 'click', function(event){
            event.stop();
            var fullSizeURL = sel.up('a').href;
            var mediumSizeURL = sel.up('a').rel;
            
            $('productImage').down('a').href = fullSizeURL;
            $('productImage').down('img').src = mediumSizeURL;            
        });
    });*/
    
	if($('div.productImage').length > 0){
	    $('div.productImage a').lightBox({
	        imageLoading: '/cms/outertemplates/images/lightbox/lightbox-ico-loading.gif',
	        imageBtnClose: '/cms/outertemplates/images/lightbox/lightbox-btn-close.gif',
	        imageBtnPrev: '/cms/outertemplates/images/lightbox/lightbox-btn-prev.gif',
	        imageBtnNext: '/cms/outertemplates/images/lightbox/lightbox-btn-next.gif'
        }); 
    }
	
});