$(document).ready(function() {
	// hover
		
	$('#menu a span').css({opacity:'0.75'})
	$('footer .bg').css({opacity:'0.75'})
	$('.buttons .img_act').css({opacity:'0'})
	$('.footer_menu').css({opacity:'0', display:'none'})
	
	$('.prev, .next').hover(function(){
		$(this).find('.img_act').stop().animate({opacity:'1'},600)							 
	}, function(){
		$(this).find('.img_act').stop().animate({opacity:'0'},600)							 
	})
	
	$('#icons a').hover(function(){
		$(this).find('img').stop().animate({opacity:'0.3'})						 
	}, function(){
		$(this).find('img').stop().animate({opacity:'1'})						 
	})
	
	$('.lightbox-image span').css({opacity:'0'})
	
	$('.lightbox-image').hover(function(){
		$(this).find('span').stop().animate({opacity:'0.4'},800)
		$(this).find('img').stop().animate({marginTop:'-10%', marginLeft:'-10%', width:'120%', height:'120%'})
	}, function(){
		$(this).find('span').stop().animate({opacity:'0'},800)
		$(this).find('img').stop().animate({marginTop:'0%', marginLeft:'0%', width:'100%', height:'100%'})
	})
	
	// tool tip
	$('.normaltip').aToolTip({
    	toolTipClass: 'aToolTip'});

	/*
	//contact form
	$('#ContactForm').forms({
		ownerEmail:'ya.za0za@yandex.ru'
	})
	
	*/
	// for lightbox
	$("a[data-type^='prettyPhoto']").prettyPhoto({theme:'dark_square'});
	
		
	
	//bg animate
	$('#bgSlider').bgSlider({
	  	duration:1000,
	  	images:['images/bg_img1.jpg','images/bg_img2.jpg','images/bg_img3.jpg','images/bg_img4.jpg','images/bg_img5.jpg'],
	 	preload:false,
	  	spinner:'.bg_spinner',
	  	nextBu:'.buttons > .next',
	  	prevBu:'.buttons > .prev'
	 })
		
 });

$(window).load(function() {	
	// scroll
	$('.scroll').cScroll({
		duration:700,
		step:100,
		trackCl:'track',
		shuttleCl:'shuttle',
	})		
	
	//content switch
	
	var content=$('#content'),
		nav=$('.menu'),
		footer_nav=$('.footer_menu');
	nav.navs({
		useHash:true,
		hoverIn:function(li){
			$('> span',li).stop().animate({opacity:'1'},600);
		},
		hoverOut:function(li){
			$('> span',li).stop().animate({opacity:'0.75'},600);
		},
		hover:true
	})		
	nav.navs(function(n, _){
			content.cont_sw(n);
			$('#footer_menu li').removeClass('active')
			if (_.n >=0) $('#footer_menu li').eq(_.n).addClass('active')
	})
	content.cont_sw({
		showFu:function(){
			var _=this					
			$('.footer_menu').css({display:'block'}).stop().animate({opacity:'1'});
					$('header .wrapper').stop().animate({height:'0'},600,'easeOutCirc', function(){
					$('.footer_menu').css({display:'block'}).stop().animate({opacity:'1'});
					$('footer, footer .bg').stop().animate({width:'940'});
						$.when(_.li.find('.box')).then(function(){	
							$('header .wrapper').stop().animate({height:'0'},600,'easeOutCirc');
							$('footer, footer .bg').stop().animate({width:'940'}, function(){
							$('#content').css({display:'block'})
							_.next.css({display:'block'}).find('.box').stop().animate({height:'100%'},600,'easeOutCirc')});
						});		
					});
		},
		hideFu:function(){
			var _=this
			$('.footer_menu').stop().animate({opacity:'0'}, function(){$(this).css({display:'none'})});
				_.li.find('.box').stop().animate({height:'0'}, 600, 'easeInCirc', function(){
					_.li.css({display:'none'});
					$('#content').css({display:'none'})
					$('footer, footer .bg').stop().animate({width:'345'}, function(){
						$('header .wrapper').stop().animate({height:'100%'},600,'easeOutCirc');
						$('.footer_menu').stop().animate({opacity:'0'}, function(){$(this).css({display:'none'})});
					})												  
			})
			
			
		},
		preFu:function(){
			var _=this
			_.li.css({position:'absolute', display:'none'});
			_.li.find('.box').css({height:'0'});
			$('#content').css({display:'none'})
		}
	})
	
	var h_cont=750;
	setHeight();
	h=new_h;
	center_box();
	function setHeight(){
		new_h=$(window).height();
	}
	setInterval(setNew,60);
	function setNew(){
		setHeight();
		if ((h!=new_h)) {
			h=new_h;
			center_box();
		}
	}
	function center_box(){
		if (h>h_cont) {
			m_top=~~((h-h_cont)/2);
		} else m_top=0
		$('.main').stop().animate({marginTop:m_top},1000, 'easeOutCirc');
		h_cont_new=h_cont;
	}	
})

