var dStart = function()
{
	this.animation_out = true ; 
	
	this.w_width = 0 ;
	this.w_height = 0 ;
	
	this.init = function ()
	{
		this.w_width = $(window).width();
		this.w_height = $(window).height();
		this.pics_resize () ;
		window.onload = function ()
		{
			dStart.animation () ;
		}
	}
	
	
	this.pics_resize = function ()
	{
		var pic = $("#first_pic") ;
		var eye_l = $("#eye_l") ;
		var eye_r = $("#eye_r") ;
		var param =
		{
			pic_width: pic.attr("width"),
			pic_height: pic.attr("height"),
			eye_l_width: eye_l.attr("width"),
			eye_l_height: eye_l.attr("height"),
			eye_r_width: eye_r.attr("width"),
			eye_r_height: eye_r.attr("height")
		} ;

		var k = this.w_width / this.w_height > param.pic_width / param.pic_height ?
			this.w_height / param.pic_height :
			this.w_width / param.pic_width ;
		
		param.new_pic_width = Math.round ( k * param.pic_width) ;
		param.new_pic_height = Math.round ( k * param.pic_height) ;
		
		pic.css
		({
			width: param.new_pic_width,
			height: param.new_pic_height
		});
		
		var m_top = Math.round ( ( this.w_height - param.new_pic_height ) / 2 )
		if ( m_top < 0 ) m_top = 0 ; 
		$("#content").css
		({
			width: param.new_pic_width
		});
		$("#all").css
		({
			'padding-top': this.w_height > param.new_pic_height ?
				 Math.round ( ( this.w_height - param.new_pic_height ) / 2 ) : 0
		});

		eye_l.css
		({
			width: Math.round ( k * param.eye_l_width ), 
			height: Math.round ( k * param.eye_l_height ),
			left: Math.round ( k * 184 ),
			top: Math.round ( k * 239 )
		});
		eye_r.css
		({
			width: Math.round ( k * param.eye_r_width ), 
			height: Math.round ( k * param.eye_r_height ), 
			left: Math.round ( k * 523 ),
			top: Math.round ( k * 219 )
		});
		
		$("#text").css({
			width: param.new_pic_width,
			'font-size': ( k * 3.2 ) + "em",
			left: Math.round ( k * 0 ),
			top: Math.round ( k * 380 )
		});
		
		
	} ;
	



	this.animation = function ( v )
	{
		if ( this.animation_out )
		{
			this.animation_out = false ; 
			$("#eye_l,#eye_r").fadeTo ( 3000, 1, function (){
				dStart.animation () ;
			} );
		}
		else
		{
			this.animation_out = true ; 
			$("#eye_l,#eye_r").fadeTo ( 3000, 0, function (){
				dStart.animation () ;
			} );
		}
			
		
	} ;


	

};

dStart = new dStart ;

$(document).ready(function(){
	dStart.init() ;
});
