$(document).ready(function(){
	number(0);
	
    var leftPage = $('#page').offset().left;
	$('img#menu_large').css('left', leftPage);
	
	// animation for page transition
	$('ul#home-nav li a').click(function(){
		$('img#menu_large').fadeIn();
		$('div#overlay').fadeIn();
		var linky = $(this).attr('href');
		$('img#menu_large').animate({
		    width: 81,
		    height: 63,
		    left: 673+leftPage,
		    top: 43
		  }, 1300, function() {
		    location.href = linky;
		  });
		return false;
	});
});

function number(count) {
	var totalSetsNum = 4;

    if (count < totalSetsNum) {
    	count++
    } else {
    	count = 1;
    }
			
	$('img.home-image').each(function(){ 
		var t = $(this);
		t.attr('src',t.attr('src').replace(/set[0-9]/, 'set'+count));
		
	});
	
	setTimeout("appear("+count+")", 1000);
}

function appear(count) {
	$('img#image1').fadeIn('fast', function() {
		$('img#image2').fadeIn('fast', function() {
			$('img#image3').fadeIn('fast', function() {
				$('img#image4').fadeIn('fast', function() {
					setTimeout("disappear("+count+")", 2000);
					//alert(count);
				});
			});
		});  
	});
}

function disappear(count) {
	$('img#image4').fadeOut('fast', function() {
		$('img#image3').fadeOut('fast', function() {
			$('img#image2').fadeOut('fast', function() {
				$('img#image1').fadeOut('fast', function() {
					number(count);
				});
			});
		});
	});
}

