var timeout;
var delay = 5000;




$(document).ready(function() {

	

	$('#tabs').tabs({
		fx: { opacity: 'toggle' }
	});
	
	$('#tabs li a').click(function() {
		clearTimeout(timeout);
	});
	
	$('#tabs').click(function() {
		clearTimeout(timeout);
	});
	
	$('#project div.images').delay(250).fadeIn('slow');
	$('#subNavigation a').wrapInner('<span></span>');
	
	startRotation();
});

$(window).load(function() {
	$('#reklamfilm img').click(function(e){
		clearTimeout(timeout);
		$(e.currentTarget).hide();
	
	var $player = $('<iframe></iframe>');
	$player.attr({
		src:'http://player.vimeo.com/video/28307379?api=1&autoplay=1&player_id=vimeoplayer',
		width:'495',
		height:'278'}
	);
	$('#reklamfilm .images').append($player);
	
	});

	$('ul.designers').each(function() {
		var ul = $(this);
		
		var maxHeight = 0;
		ul.children('li').each(function() {
			var height = $(this).height();
			if (height > maxHeight) {
				maxHeight = height;
			}
		}).height(maxHeight);
	});
});

function startRotation() {
	timeout = setTimeout(
		function() {
			var selected = $('#tabs').tabs('option', 'selected');
			if (selected == 0) {
				selected = 1;
			}
			else if (selected == 1) {
				selected = 2;
			}
			else {
				selected = 0;
			}
			$('#tabs').tabs('option', 'selected', selected);
			startRotation();
		},
		delay
	);
}
