//document.write('<a href="#"><div id="rightArea">&nbsp;</div></a>');
//document.write('<a href="#"><div id="leftArea">&nbsp;</div></a>');


window.onresize = resize; 
function resize(){
  onStageResize();
}

$(document).ready(function(){ 
   $("#slider").css('left', '0')
   onStageResize();
}); 


$(document).mousemove(function(e){
      slideTO(e.pageX, e.pageY)
});

var moving = 'false';
 
function slideTO(x, y){  
	
	if(y >= 270 && y <= 450){
		if( x > windowSize[0]-305 && moving != 'left'){ 
			var proz = 100/-parseFloat($('#wrapper').width()-windowSize[0])*parseFloat($("#slider").css('left'));
		 	proz = 100-proz;
			var time = parseFloat($('#wrapper').width()-windowSize[0])-parseFloat($("#slider").css('left'));  
		 	$("#slider").animate({left: -parseFloat($('#wrapper').width()-windowSize[0])}, 8000*proz/100, 'linear');    
			moving = 'left';
		} else if( x < 305 && moving != 'right'){
		   // var time = parseFloat($("#slider").css('left'));   
			//var need = parseFloat($("#slider").css('left')); 
			var proz =  100/-parseFloat($('#wrapper').width()-windowSize[0])*(-parseFloat($('#wrapper').width()-windowSize[0])-parseFloat($("#slider").css('left')));
		   	proz = 100-proz;
			$("#slider").animate({left: '0'}, 8000*proz/100, 'linear'); 
			moving = 'right';
		} else if( x > 305 && x < windowSize[0]-305){
			$("#slider").stop();
			moving = 'false';
		}
	} else {
		$("#slider").stop();
		moving = 'false';
	}
}


function onStageResize(){
	windowSize = getWindowSize();    
}

function getWindowSize(){      	
	if( typeof( window.innerWidth ) == 'number' ) {
   		this.maxW = window.innerWidth;
   	    this.maxH = window.innerHeight;
   	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
   		/* IE 6+ in 'standards compliant mode' */
   	   this.maxW = document.documentElement.clientWidth;
   	   this.maxH = document.documentElement.clientHeight;
   	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   	    /* IE 4 compatible */
   	    this.maxW = document.body.clientWidth;
   	    this.maxH = document.body.clientHeight;
    } 
	return Array(this.maxW, this.maxH)
}

function toogle( img ){
	if(img.offsetHeight == 180){
		$(img).animate({
		    width: '612px',
		    height: '450px'
		  }, 800 );
	} else {
		$(img).animate({
		    width: '245px',
		    height: '180px'
		  }, 800 );
	}
} 
