//init
	var IE='\v'=='v';
	
	aspect = 1559 / 1920;
	wcow = 358 / 1920;
	hcow = 476 / 1559;
	widthFromHeight = 476 / 358;
	
	
	
	if(IE || navigator.appVersion == '5.0 (Windows; ru)') {
		forIE();
	}else{
		forCSS3();
	}



function forCSS3(){
$(document).ready(function(){
	$('#cowIE').css({
		display:'none'
	});
	$('#cowCSS3').css({
		display:'block'
	});

	//1)
	RandomPosition();	
	//2)	
	//Calculate();
	////////////////////////////

            $('#retinacss3').animate({top:'+=200'},{step:function(){
                Calculate()
                },duration:300})
                .animate({top:'-=150'},{step:function(){
                Calculate()
                },duration:300})
                .animate({top:'+=50'},{step:function(){
                Calculate()
                },duration:300})
            //Calculate();

    
///////////////////////////////////

	/* This code is executed on the document ready event */

	$("#retinacss3").draggable({
		containment:'window',
		drag:function(event,ui){
			Calculate(ui);
		}
		
	})
	
});

$(window).resize(function(){
	Calculate();
});

function Calculate(ui)
{

	newHeight = aspect * $(window).width();
	size = $(window).width()+'px '+newHeight+'px';

	$("#retinacss3").css({
			'background-size': size,
			'-moz-background-size': size,
			'-webkit-background-size': size,
			'-o-background-size': size,
			'-khtml-background-size': size
	});
		
	if(ui)
	{x = ui.position.left;
		y = ui.position.top;
	}else{
		x = $('#retinacss3').position().left;
		y = $('#retinacss3').position().top;
	}
	
	
	widthcow = wcow * $(window).width();
	//************88888888
	heightcow = widthcow * widthFromHeight;
	sizecow = widthcow+'px '+heightcow+'px';
	margin_t = -(heightcow - widthcow + 12);
	
	$("#cow").width(widthcow).height(heightcow);
	$("#retinacss3").width(widthcow-8).height(widthcow-14);
	$("#cow").css({
		'background-size': sizecow,
		'-moz-background-size': sizecow,
		'-webkit-background-size': sizecow,
		'-o-background-size': sizecow,
		'-khtml-background-size': sizecow,
		'margin-top': margin_t,
		'margin-left': '-4px'
	});
	
	heightFon = $(window).width() * 1559 / 1920 ;
	raznost = heightFon - $(window).height();
	
	//alert (heightFon +' - '+$(window).height()+' = '+raznost + ' ->WIDTHwin:'+$(window).width());
	backpos = '-'+(x)+'px -'+(y+raznost)+'px';
	//alert(backpos);
	$("#retinacss3").css({
		'background-position'	: backpos	
	});	
	
}

	function RandomPosition()
	{
		x =  Math.round(Math.random()*$(window).width());
		y =   Math.round(Math.random()*$(window).height());
		if(x < 0 )
		{
			x+=358;
		}if(x >= ($(window).width() - 358) )
		{
			x-=358;
		}if(y > $(window).height()-358)
		{
			y-=358;
		}
		
		$('#retinacss3').css({left:x,top:y});
		
	}
}


function forIE(){
$(document).ready(function(){
//1)
	RandomPositionIE();	
//2)
/* $("#cowIE").draggable({
                containment:'window',
		drag:function(event,ui){
			CalculateIE(ui);
		}		
	}); */
//////////////////////////////
    $('#cowIE').animate({top:'+=200'},{step:function(){
                CalculateIE()
                },duration:300})
                        .animate({top:'-=150'},{step:function(){
                CalculateIE()
                },duration:500})
                        .animate({top:'+=50'},{step:function(){
                CalculateIE()
                },duration:700}).draggable({
                    containment:'window',
                    drag:function(event,ui){
			CalculateIE(ui);
		}
                });
   
///////////////////////////////////
	CalculateIE();


        
});



$(window).resize(onResize);

function onResize()
{
	CalculateIE();
	
};

function RandomPositionIE()
{
		x =  Math.random()*$(window).width();
		y =  Math.random()*$(window).height();
		if(x < 0 )
		{
			x+=358;
		}if(x >= ($(window).width() - 358) )
		{
			x-=358;
		}if(y > $(window).height()-358)
		{
			y-=358;
		}
		
		$("#cowIE").css({left:x,top:y});

};
function CalculateIE(ui)
{
			if(ui)
			{x = ui.position.left;
				y = ui.position.top;
			}else{
				x = $('#cowIE').position().left;
				y = $('#cowIE').position().top;
			}
			
			bottom = $(window).height() - y - $('#cowIE').height() ;
			
			wid = $(window).width();
			
		
			$('.fonPosle').css({
				left:-x,
				width: wid
			});
			
			///////�������� 2 ������ �� 20 ��������///////////
			$('#fon2').css({
				left:-x-24,
				bottom:-57-bottom,
				width: wid
			});
			$('#fon1').css({
				left:-x-52,
				bottom:-bottom-30,
				width: wid
			});
			//////////////////////
}
}


