$(document).ready(function() {
	/**
	 * Roll hover images
	 */
	var preload = new Array();
    $('img.roll').each(function (i) {
        //let's preload
        var img = new Image();
        img.src = this.src.replace(/([_-])off([._-])/, '$2on$2');
        preload.push(img);
        $(this).hover(
            function () { // over
                $(this).attr('src',this.src.replace(/([_-])off([._-])/, '$1on$2'));
            },
            function () { // out
                $(this).attr('src',this.src.replace(/([_-])on([._-])/, '$1off$2'));
            }
        );
    });

	/**
	 * SlideShow
	 */
	
	var images = $(".slideshow img");
	var imageSum = images.size();
	var currentImage = $(images[0]);
	var slideId = 0;

	images.css({position: 'absolute', display: 'none'});
	currentImage.fadeIn();

	rotate = function() {
		currentImage.fadeOut();

		if (++slideId >= imageSum) slideId = 0;

		currentImage = $(images[slideId]);
		currentImage.fadeIn();
	}; 

	rotateSwitch = function(){		
		play = setInterval(function(){
			rotate();
		}, 5000);
	};

	rotateSwitch();

	$(".slideshow a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});
});
