fl=0;
$(document).ready(function() {
	// hover
	
	// animate button_enter
	$('.button_enter').hover(function(){
			$(this).find('span').stop().animate({backgroundPosition:'-1px -1px'},400, 'easeOutQuad')
		}, function(){
			$(this).find('span').stop().animate({backgroundPosition:'-200px -200px'},400, 'easeOutQuad')
		}
	)
	
	$('.prev, .next, .close').find('.img_act').css({opacity:0})
	
	$('.prev, .next, .close').hover(function(){
		$(this).find('.img_act').stop().animate({opacity:1})							 
	}, function(){
		$(this).find('.img_act').stop().animate({opacity:0})							 
	})
	
	
	$('.lightbox-image').hover(function(){
		$(this).find('.play').stop().animate({width:55, height:55, top:43, left:163})								
	}, function(){
		$(this).find('.play').stop().animate({width:45, height:45, top:48, left:168})								
	})
	
	// for lightbox
	$("a[data-type^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	
	
	var Img='#'+$(".gallery_big_img img.active").attr('id')
	$(".gallery_big_img img").css({width:0, height:0, top:190, left:30, zIndex:2});
	$(".gallery_big_img img.active").css({width:197, height:290, top:9, left:9, zIndex:1});
	$("#gallery1 a").click(function(){
  		var ImgId = $(this).attr("href");
  		if (ImgId!=Img) {
			$(".gallery_big_img img.active").css({zIndex:1}).stop().animate({width:0, height:0, top:190, left:130}, 600,function(){
				 $(this).removeClass('active');
			})
				 $(ImgId).css({zIndex:2}).stop().animate({width:197, height:290, top:9, left:9}, 600, function(){$(this).css({opacity:'none'})}).addClass('active');
		}
		Img=ImgId;
  	  return false;
   })
	
	
	$('ul#menu').superfish({
      delay:       600,
      animation:   {height:'show'},
      speed:       600,
      autoArrows:  false,
      dropShadows: false
    });
	
	$('#menu > li').hover(function(){
		$(this).find('> a > span').stop().animate({opacity:1},600)							 
	}, function(){
		if (!$(this).hasClass('active')) {
			$(this).find('> a > span').stop().animate({opacity:0},600)							 
		}
	})
	
	//bg animate
	$('#bgSlider').bgSlider({
	  	duration:1000,
	  	images:['images/bg1.jpg','images/bg2.jpg','images/bg3.jpg','images/bg4.jpg'],
	 	preload:false,
	  	spinner:'.bg_spinner',
	  	nextBu:'.next',
	  	prevBu:'.prev'
	 })
		
 });
$(window).load(function() {	
	// scroll
	$('.scroll').cScroll({
		duration:200,
		step:100,
		trackCl:'track',
		shuttleCl:'shuttle'
	})	
	
	// contact form
	$('#ContactForm').forms({
		ownerEmail:'ya.za0za@yandex.ru'
	})
	
	//content switch
	var content=$('#content'),
		nav=$('.menu'),
		footer_nav=$('.footer_menu');
	nav.navs({
		useHash:true,
		hoverIn:function(li){
			$('> a > span',li).stop().animate({opacity:'1'},600);
		},
		hoverOut:function(li){
			$('> a > span',li).stop().animate({opacity:'0'},600);
		},
		hover:true
	})		
	footer_nav.navs({
		useHash:true,
		hover:true
	});
	nav.navs(function(n, _){
		content.cont_sw(n);
		footer_nav.navs(n);
	})
	content.cont_sw({
		showFu:function(){
			var _=this					
			$('#content').css({height:550});
				fl=1;
			$.when(_.li).then(function(){	
				$('#splash').stop().animate({height:'0'}, function(){
				_.next.css({display:'block'}).stop().animate({height:514});	
				})
			});
			var new_h=$(window).height();
			if (new_h>830) {
				p_top=~~(new_h-830)/2+150;
			} else {
				p_top=150
			}
			$('#content').stop().animate({paddingTop:p_top});
			$('.bg1').stop().animate({top:0})
		},
		hideFu:function(){
			var _=this
			$('.bg1').stop().animate({top:-116})
			$('#content').css({height:330});
			fl=0;
			_.li.stop().animate({height:0}, function(){$(this).css({display:'none'})
			$('#splash').stop().animate({height:'300'});});
			var new_h=$(window).height();
			if (new_h>520) {
				p_top=~~(new_h-520)/2+30;
			} else {
				p_top=30
			}
			$('#content').stop().animate({paddingTop:p_top})
		},
		preFu:function(){
			var _=this
			_.li.css({position:'absolute', display:'none'});
		}
	})
})
