$(document).ready(function(){
	
	$('table.button').mouseover(function() {
		$(this).addClass('active');
	}).mouseout(function() {
		$(this).removeClass('active');
	});
	 
    $('.image-slider-photo').each(function() {
		var a = Math.floor(Math.random()*11) - 5;
		$(this).transform({ rotate: a, translate: [a,a] });
	}).click(function() {
		var el = this;
		
		if ($(this).hasClass('active')) 
			el = $(this).prev()[0] || $(this).siblings().last()[0];			
			
		$('a[rel=' + el.id + ']').trigger('click');
	});
	 
	$('#image-slider-nav a').click(function() {
		if ($(this).hasClass('active'))
			return false;
			
		$('.image-slider-photo.prev').removeClass('prev');
		$('.image-slider-photo.active').removeClass('active').addClass('prev');
		$('#image-slider-nav a.active').removeClass('active');
		
		$('#' + $(this).attr('rel')).hide().addClass('active').fadeIn('slow');
		
		$(this).addClass('active');
		
		return false;
	});
	
	// autoscrolling
	startAutoScroller();
	
	$('#image-slider').mouseover(function() {
		clearInterval(autoScrollerId);
	}).mouseout(function() {
		startAutoScroller();
	});
	
	function startAutoScroller() {
		autoScrollerId = setInterval(function () {
	      	$('.image-slider-photo.active').trigger('click');
	    }, 4000);
	}
}); 
