﻿/// <reference path="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" />

$(document).ready(function () {
    setupProductImages();
});
function setupProductImages() {
    noOfImages = $("#ProductImages li img").size();

    if (noOfImages > 1) {
        $("#ProductImages li img").mouseover(hoverOverImage);
        runNextStep();
    }
}
function hoverOverImage() {
    setMainImage(this);
    window.clearTimeout(timeOutID);
}
function setMainImage(thumbnail) {
    var iconSrc = $(thumbnail).attr("src");
    $("#MainImage").attr("src", iconSrc.replace("60.jpg", "300.jpg"));
}
var currentImage = 0;
var noOfImages = 0;
var timeOutID = 0;
function runNextStep() {
    timeOutID = window.setTimeout(stepThroughSlideShow, 5000);
}
function stepThroughSlideShow() {
    currentImage++;
    if (currentImage >= noOfImages)
        currentImage = 0;

    setMainImage($("#ProductImages li img")[currentImage]);

    runNextStep();
}

$(document).ready(function () {
    if (!($.browser.msie && $.browser.version.substr(0, 1) < 7))
        runSlideShow();
});
function runSlideShow() {
    window.setTimeout(showNextSlideShowImage, 2000);
}
function showNextSlideShowImage() {
    var slideShow = $(".SlideShow");
    slideShow.each(function () {
        var current = $(this).children(":visible");

        current.fadeOut();
        if (current.next().length == 0)
            current.siblings().first().fadeIn();
        else
            current.next().fadeIn();
    });
    runSlideShow();
}

// IE Fixes
$().ready(function () {
	if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
		$(".CategoryList img, .ProductList img")
			.click(function () {
				window.location.href = $(this).parents("a").first().attr("href");
			})
			.hover(function () {
				$(this).css("cursor", "hand");
			});
	}
});
