﻿var rId;
var timer;

function SendEnquiry(url) {
    $.modal("<iframe frameborder='0' src='" + url
    + "' style='width: 470px; height: 600px; border:0px;' allowtransparency='true'  />", {
        overlayCss: { backgroundColor: '#333333' },
        containerCss: { width: 470, height: 590 },
        containerId: 'send-product-enquiry'
    });
}

function theRotator() {
    //Added ClearInterval to prevent delay speed being additive when multiple images lists are on a page. 
    clearInterval(timer);
	//Set the opacity of all images to 0
	$("div#rotator"+rId+" ul li").css({opacity: 0.0});
	//Get the first image and display it (gets set to full opacity)
	$("div#rotator"+rId+" ul li:first").css({ opacity: 1.0 });

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	timer = setInterval('rotate()', 5000);
}



function rotate() {	
	//Get the first image
    var current = ($("div#rotator" + rId + " ul li.show") ? $("div#rotator" + rId + " ul li.show") : $("div#rotator" + rId + " ul li:first"));
	//Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass("show")) ? $("div#rotator" + rId + " ul li:first") : current.next()) : $("div#rotator" + rId + " ul li:first"));	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

$(document).ready(function () {
    $(".productArrows img").animate({
        opacity: 0.0
    }, 0 );

    $(".productArrows").hover(function () {
        $("img", this).stop().animate({
            opacity: 1.0
        }, 500);
    }, function () {
        $("img", this).stop().animate({
            opacity: 0.0
        }, 500);
    });

    $(".srLink").click(function () {
        var srId;
        srId = $(this).attr("id");
        srId = srId.substring(6);

        rId = srId;

        $(this).colorbox({ opacity: 0.65, width: "923px", inline: true, href: "#sr" + srId });

        //Load the slideshow
        theRotator();
    });
    $(".srHLink").click(function () {
        var srId;
        srId = $(this).attr("id");
        srId = srId.substring(7);

        rId = srId;

        $(this).colorbox({ opacity: 0.65, width: "923px", inline: true, href: "#sr" + srId });

        //Load the slideshow
        theRotator();

    });
    $(".srInfo img").click(function () {
        var srId;
        srId = $(this).parents("div.srInfo").attr("id");
        srId = srId.substring(6);

        rId = srId;

        $(this).colorbox({ opacity: 0.65, width: "923px", inline: true, href: "#sr" + srId });

        //Load the slideshow
        theRotator();
    });
});

