function move(direction) {
    // alert(direction);
    var moveBy = 99;
    var scrollPos = $('#thumbs').scrollTop();
    if (direction == 'up') { moveBy = moveBy * -1 };
    $('#thumbs').animate({ scrollTop: moveBy }, 800, 'swing', function () { window.setTimeout(function () { setMoveBtns(); }, 0) });

}

function setTabs()
{  
    $("ul.tabs").tabs("div.panes > div");
        var tabHeight = 0;
        var maxTabHeight = 300;
        var api = $("ul.tabs").data("tabs");
        var tabs = api.getPanes();
        tabs.each(function () {
            if ($(this)[0].scrollHeight > tabHeight) { tabHeight = $(this)[0].scrollHeight; }
            api.next();
        });
        if (tabHeight > maxTabHeight) { tabHeight = maxTabHeight; }
        api.click(0);
        tabs.each(function () {
            $(this).height(tabHeight);

        });

}

function setThumbs() {

	$('.jqzoom').jqzoom({
		zoomType: 'innerzoom',
		preloadImages: false,
		title: '',
		preloadText:'Loading...',
		alwaysOn:false
	});
/*
    var currentImg = -1;
    $('#thumbs ul img').each(function () {
        $(this).click(function () {
            currentImg = $(this).attr('pos');
            setMainImg(myImgs[currentImg], currentImg);
        });
    });
    $('#thumbs li').each(function () {
        $(this).mouseenter(function () {
            $(this).toggleClass('thumbliOver');
        }).mouseleave(function () {
            $(this).toggleClass('thumbliOver');
        });
    });
	*/
}

var isDownSet = false;
var isUpSet = false;
function setMoveBtns() {
    var thumbs = $('#thumbs');
    var isTop = thumbs.scrollTop() == 0;
    var isBottom = thumbs[0].scrollHeight - thumbs.scrollTop() == thumbs.outerHeight();
    var isMiddle = (isTop == false && isBottom == false);
    var dhtml = $('#debug').html();

    if (isTop && isBottom) {return; }

   // $('#debug').html(dhtml + '<br>top: ' + isTop + ', bottom: ' + isBottom + ', middle: ' + isMiddle + ', isUpSet: ' + isUpSet + ', isDownSet: ' + isDownSet);
    if (isMiddle || isTop) {
        if (!isMiddle) { $('#bUp').unbind().removeClass().addClass('bUp').attr('title', 'You are at the top'); isUpSet = false; }
        if (!isDownSet) {
            $('#bDown').attr('title', 'Scroll Down')
	        .click(function () { move('down'); })
	        .mouseenter(function () { $(this).removeClass().addClass('bDownOver'); })
	        .mouseleave(function () { $(this).removeClass().addClass('bDown'); });
            isDownSet = true;
        }
    }
    if (isMiddle || isBottom) {
        if (!isMiddle) { $('#bDown').unbind().removeClass().addClass('bDown').attr('title', 'You are at the bottom'); isDownSet = false; }
        if (!isUpSet) {
            $('#bUp').attr('title', 'Scroll Up')
	        .click(function () { move('up'); })
	        .mouseenter(function () { $(this).removeClass().addClass('bUpOver'); })
	        .mouseleave(function () { $(this).removeClass().addClass('bUp'); });
            isUpSet = true;
        }
    }
}

function setMainImg(img,pos) {
    var url = '/ImageGen.ashx?image=' + img + '&width=500&height=500&pad=true';
    $('.thumbliLocked').removeClass().addClass('thumbli');
    $('#li' + pos).removeClass('thumbli').addClass('thumbliLocked');
    $('.mainimg').fadeTo(100, 0, function () {
        $('.mainimg').attr('src', url).load(function () { $(this).fadeTo('slow', 1); });
    });


}

function preloadImages(arr) {
    for (var i = 0; i < arr.length; i++) {
        var url = '/ImageGen.ashx?image=' + arr[i] + '&width=500&height=500&pad=true';
       // alert(url);
        jQuery("").attr("src", url);
    }
}

(function ($) {
    // VERTICALLY ALIGN FUNCTION
    $.fn.vAlign = function () {
        return this.each(function (i) {
            var ah = $(this).height();
            var ph = $(this).parent().height();
            var mh = Math.ceil((ph - ah) / 2);
            $(this).css('margin-top', mh);
        });
    };
})(jQuery);

jQuery(function () {
    $('.pimg').each(function () {
        $(this).mouseenter(function () {
            $(this).toggleClass('pimgOver');
        }).mouseleave(function () {
            $(this).toggleClass('pimgOver');
        });
    });

    $('.prodouter').each(function () {
        $(this).click(function () { location.href = $(this).attr('link'); });
    });
});
