$(window).load(function () {
	pix=new Array(	
		'/images/bg_about_hover.png',
		'/images/bg_production_hover.png',
		'/images/bg_partners_hover.png',
		'/images/bg_press_hover.png'
	)
	pic=new Array()
	
	for(i=0;i<=pix.length-1;i++){
		pic[i]=new Image();
		pic[i].src=pix[i];
	}	
});
		
$(document).ready(function() {
	initMainMenu();
	initMainSlider();			
	initCarousel();	
});

initCarousel = function(){
	 
	$('.roundabout-holder img.moveable').focus(function() {		
	    $('.wrap_descr').html('<h1><a href="'+$(this).attr('data-url')+'">'+$(this).attr('title')+'</a></h1>').fadeIn(200);											
		$(this).click(function(){
			if( $(this).hasClass('roundabout-in-focus') ){
				$(location).attr('href',$(this).attr('data-url'));
			}
		});	
	}).blur(function() {
		$('.wrap_descr').html('').fadeOut(100);
	}); 
	 	 
	$('.roundabout-holder').roundabout({		
		minScale: 0,
		maxScale: 1.0,
		minOpacity: 1,
		btnNext: '#next',
		btnPrev: '#prev',
		childSelector: '.moveable',
		tilt: -6,
		startingChild: 2
		
	 }); 
}

initMainSlider = function(){		
    $(function () {       
		$('.anythingSlider').anythingFader({
			easing: "easeInOutExpo",
			autoPlay: true,               
            delay: 8000,                  
            startStopped: false,          
            animationTime: 500,           
            hashTags: true,                             
			buildNavigation: false,        
            pauseOnHover: false,                           
            navigationFormatter: false			
         });                    
    });
	$(".anythingSlider").hover(
		function(){
			$("#start-stop").click();
		},
		function(){
			$("#start-stop").click();
		}
	);
}

var img_src_active,img_src_init; 

function mouseenterAnimate($this,img_src_active){			
	$this.find('img').attr('src',img_src_active).stop().animate(
		{width:'129px',height:'130px'},
		{duration:500,queue:false}
	);  	
}

function mouseleaveAnimate($this,img_src_init){	               	
	$this.find('img').stop().animate(
		{width:'68px',height:'66px'},
		{duration:500,queue:false,
			complete:function(){ 
				$this.find('img').attr('src',img_src_init); }
		}
	);	
}

initMainMenu = function(){   	
	/*******************************************************/
	$('#press a').mouseenter(function() {		
		mouseenterAnimate($(this),pic[3].src);			
	});
	$('#press a').mouseleave(function() {
    	mouseleaveAnimate($(this),'/images/bg_press.png');		
	});		
	/*******************************************************/	
	$('#partners a').mouseenter(function() {			
		mouseenterAnimate($(this),pic[2].src);
	});
	$('#partners a').mouseleave(function() {			
		mouseleaveAnimate($(this),'/images/bg_partners.png');
	});
	/*******************************************************/
	$('#production a').mouseenter(function() {			
		mouseenterAnimate($(this),pic[1].src);			
	});	
	$('#production a').mouseleave(function() {			
		mouseleaveAnimate($(this),'/images/bg_production.png');			
	});	
	/*******************************************************/	
	$('#about a').mouseenter(function() {			
		mouseenterAnimate($(this),pic[0].src);	
	});
	$('#about a').mouseleave(function() {									
		mouseleaveAnimate($(this),'/images/bg_about.png');						
	});
	/*******************************************************/	
}
