//© Denis Seleznev 2008, info@webfilin.ru
// air_photoalbum v1.0

$(window).resize(function()
{
	$('#tu').css('left', Math.floor($('#measurer').width()/2-750/2)+'px');
});

$(window).load(function()
{
	$('#tu').css('left', Math.floor($('#measurer').width()/2-750/2)+'px');
	$('#tu').animate({top:'300px'}, 4000, 'linear', showK);
	
	if ($.browser.msie)	$('#tu img').each(function(){this.galleryImg=false;});
	
	$('#goodbye').click(function()
	{
		$(window).unbind('resize');
		$('#goodbye').hide();
		$('#tu').animate({left:'-1000px'}, 3000);
		$('#tu img').css({left:'', top:'', width:'100px', height:'75px'}).unbind('click');
		$('#tu9').css({top:'50px'});
		$('#tu10').css({top:'100px'});
		$('#tu11').css({top:'150px'});
		$('#tu12').css({top:'-50px'});
		$('#tu13').css({top:'-100px'});
		$('#tu14').css({top:'-150px'});
		$('#tu7').css({top:'-30px'});
		$('#tu8').css({top:'-60px'});		
	});
});

function mouseover()
{
	$('#tu img').removeClass('selected');
	$(this).addClass('selected');
}

function mouseout()
{
	$('#tu img').removeClass('selected');
}
	
var widthTu=640;
var heightTu=480;
var smallWidthTu=100;
var smallHeightTu=75;
var oldx;
var oldy;

var deg=0;
var showTraska=true;

function zoomTu(event)
{
	initBeforeOpen()
	$(this).addClass('active').animate({top:'-100px', left:'50px', width:widthTu+'px', height:heightTu+'px'}, 1000, 'linear', showBigImage);
	oldy=$(this)[0].offsetTop;
	oldx=$(this)[0].offsetLeft;
	$(this).unbind('click');
	showTraska=false;
}

function showBigImage()
{
	$(this).click(closeTu).css('cursor', 'pointer').get(0).src=$(this)[0].src.replace(/small\//, '');
	$('#author').show();
}

function closeTu(id)
{	
	$(this).animate({top:oldy+'px', left:oldx+'px', width:smallWidthTu+'px', height:smallHeightTu+'px'}, 1000, 'linear', initAfterClose);
	$(this).unbind('click');
	showTraska=true;
	$('#author').hide();
}

function initBeforeOpen()
{
	$('#tu img').unbind('mouseover').unbind('click').unbind('mouseout').css('cursor', 'default');
}

function initAfterClose()
{
	$('#tu img').removeClass('active').mouseover(mouseover).click(zoomTu).mouseout(mouseout).css('cursor', 'pointer');
}

function showK()
{
	$('#tu9').animate({top:'50px'}, 2000);
	$('#tu10').animate({top:'100px'}, 2000);
	$('#tu11').animate({top:'150px'}, 2000);

	$('#tu12').animate({top:'-50px'}, 2000);
	$('#tu13').animate({top:'-100px'}, 2000);
	$('#tu14').animate({top:'-150px'}, 2000);

	$('#tu7').animate({top:'-30px'}, 2000);
	$('#tu8').animate({top:'-60px'}, 2000, 'linear', function(){
		$('#goodbye-container').show();
		$('#tu img').mouseover(mouseover).click(zoomTu).mouseout(mouseout);
	});	
	
	traska();
}

function traska()
{
	if (showTraska)
	{
		deg++;
		var y=Math.floor(30*Math.sin(2*Math.PI*deg/360));
		$('#tu').css('margin-top', y+'px');
	}
	
	setTimeout('traska()', 30);
}