var date, hour, minute;

$(document).ready(function(){
	$('.screenshots ul').css('width', $('.screenshots img').length * $('.screenshots img').width())
	$('.iphone_emulator').append('<span class="iphone_time"></span>');
	applyTime()
	
	$('.screenshots li').attr('title','More screenshots...').css('cursor','pointer').click(function(){
		if($('.screenshots ul').is(':not(:animated)')){
			if($(this).is(':last-child')){
				$('.screenshots li').filter(':not(:last-child)').appendTo($('.screenshots ul'));
				$('.screenshots ul').css('margin-left', '0')
			};
			var existingMargin = $('.screenshots ul').css('margin-left');
			$('.screenshots ul').animate({marginLeft : (existingMargin.split('px')[0] - $('.screenshots img').width())},500);
			$(this).removeClass('current').next().addClass('current');
		}
	});
	
	var slideShow = window.setInterval('slideScreens()',3000);
	var updateTime = window.setInterval('applyTime()',20000);
});

function slideScreens(){
  $('.screenshots li.current').click();
};

function applyTime(){
	date = new Date();
	hour = date.getHours();
	minute = date.getMinutes();

	if(hour.toString().length == 1) hour = '0' + hour;
	if(minute.toString().length == 1) minute = '0' + minute;
	
	$('.iphone_time').html(hour+':'+minute);
};