var slideshow_speed = 5000;
var slideshow_running = true;
var active_slide = 0;

jQuery(document).ready(function () {
    if (jQuery('#hotscot_slideshow img').size() > 1) {
        var txt = '';
        jQuery('#hotscot_slideshow img').each(function (itm) {
            if (itm == 0) {
                txt += '<a href="JavaScript:void(0);" class="on">' + itm + '</a>';
            } else {
                jQuery(this).hide();
                txt += '<a href="JavaScript:void(0);">' + itm + '</a>';
            }
        });
        jQuery('#hotscot_slideshow').append('<div class="slideshow_points">' + txt + '</div>');

        jQuery('#hotscot_slideshow a').each(function (itm) {
            jQuery(this).hover(function () {
                //stop slideshow
                slideshow_running = false;
                jQuery('#hotscot_slideshow a').removeClass('on');
                jQuery('#hotscot_slideshow a:eq(' + itm + ')').addClass('on');
                jQuery('#hotscot_slideshow img').hide();
                jQuery('#hotscot_slideshow img:eq(' + itm + ')').show();
                active_slide = itm;
            }, function () {
                //restart slideshow
                slideshow_running = true;
            });
        });

        var slideshow_on = window.setInterval(runSlide, slideshow_speed);
    }
});

function runSlide() {
	if(slideshow_running){
		slideshow_running = false;
		var nextSlide = active_slide + 1;
		if (nextSlide >= jQuery('#hotscot_slideshow img').size()) {
			nextSlide = 0;
		}


        jQuery('#hotscot_slideshow img:eq(' + active_slide + ')').fadeOut(1000, function () {
            jQuery('#hotscot_slideshow a').removeClass('on');
            jQuery('#hotscot_slideshow a:eq(' + nextSlide + ')').addClass('on');
            jQuery('#hotscot_slideshow img:eq(' + nextSlide + ')').fadeIn(1000, function () {
				slideshow_running = true;
				active_slide++;
				if (active_slide >= jQuery('#hotscot_slideshow img').size()) {
					active_slide = 0;
				}
			});
		});
	}
}
