var last_page=0;
var width=778;
$(document).ready(function() {
	
	// hover
	
	$('.prev, .next').hover(function(){
		$(this).stop().animate({opacity:0.5})					  
	}, function(){	
		$(this).stop().animate({opacity:1})					  			  
	})
	
	$('#content > ul > li').each(function(num){
		$(this).data({num:num})								  
	})
	
	$('.button1 strong').css({opacity:0})
	
	$('.button1').hover(function(){
		$(this).find('strong').stop().animate({opacity:1})						 
	}, function(){
		$(this).find('strong').stop().animate({opacity:0})						 
	})
	
	$("#gallery1").jCarouselLite({
			btnNext: "#next",
		 	btnPrev: "#prev",
       		mouseWheel: true,
			visible: 3,
			speed: 600,
        	vertical: true,
			easing: 'easeOutCirc'
	});
	
		
	var Img='.'+$(".gallery1_big_img img#active").attr('class')
	$(".gallery1_big_img img").css({opacity:0});
	$(".gallery1_big_img img#active").css({opacity:1});
	$("#gallery1 a").click(function(){
  		var ImgId = '.'+$(this).attr("href").slice(1);
  		if (ImgId!=Img) {
			 $(Img).stop().animate({opacity:0}, 600, function(){$(this).css({display:'none'})})
			 $(Img).attr({id:''});
			 $(ImgId).css({display:'block'}).stop().animate({opacity:1}, 600, function(){});
			 $(ImgId).attr({id:'active'})
		}
		Img=ImgId;
  	  return false;
   })
	
	$('ul#menu').superfish({
      delay:       600,
      animation:   {height:'show'},
      speed:       600,
      autoArrows:  false,
      dropShadows: false
    });
	
	
	$('.splash_menu').roundabout({
			 shape: 'theJuggler',
        	 minScale: 0.5, // tiny!
        	 maxScale: 1, // tiny!
			 easing:'easeOutExpo',
			 clickToFocus:'true',
			 focusBearing:'1',
			 duration:800,
			 tilt:'0',
			 reflect:true
	});
	
	$('.splash_menu a').css({opacity:0})
	
	$('.splash_menu a').hover(function(){
		$(this).stop().animate({opacity:0.4})						
	}, function(){
		$(this).stop().animate({opacity:0})						
	})
	
	
 });
$(window).load(function() {	
	
	//content switch
	var content=$('#content'),
		nav=$('.menu');
	nav.navs({
		useHash:true,
		hoverIn:function(li){
			$('> span', li).stop().animate({opacity:1})
		},
		hoverOut:function(li){
			if (!li.hasClass('with_ul') || !li.hasClass('sfHover')) {
				$('> span', li).stop().animate({opacity:0})
			}
		}
	})	
	$('.prev').click(function(){
		if (!$('#menu > li').eq(0).hasClass('active')) {
			nav.navs('prev')
			location.hash=$('#menu > .active > a').attr('href');
		}
		return false
	})
	$('.next').click(function(){
		if (!$('#menu > li').eq($('#menu > li').length-1).hasClass('active')) {
			nav.navs('next');
			location.hash=$('#menu > .active > a').attr('href');
		}
		return false
	})
	
	nav.navs(function(n, _){
		content.cont_sw(n);
		if (_.n==-1) {
			$('.prev').stop().animate({left:58})
			$('.next').stop().animate({left:800})
		} else {
			$('.prev').stop().animate({left:8})
			$('.next').stop().animate({left:868})
		}
	})
	content.cont_sw({
		showFu:function(){
			var _=this			
			if (_.next.attr('id')=='page_contacts') {
				$('#map').html('<iframe width="300" height="330" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="googlemap.html"></iframe>');
			}
			if (_.next.attr('id')=='page_contacts') {
				$('#formsent').html('<iframe width="200" height="186" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="contactform.htm"></iframe>');
			}
			
			_.next.css({display:'block',left:-left_pos}).stop().animate({left:0},800, 'easeOutCirc', function(){
				last_page=_.next.data('num')																			   
			});	
			
			$('#splash').stop().animate({marginLeft:-2000},600,'easeOutCirc', function(){
				$('#content > ul, .prev, .next, .shadow').stop().animate({marginLeft:0},600,'easeOutCirc', function(){
					$('.menu').stop().animate({marginLeft:0},600,'easeOutCirc')																								
				})													 
			})
		},
		hideFu:function(){
			var _=this
			if (_.next.data('num')>last_page) {
				left_pos=-width
			} else {
				left_pos=width
			}
			_.next.siblings().stop().animate({left:left_pos},800, 'easeOutCirc', function(){
				_.next.siblings().css({display:'none'})
			})
		},
		preFu:function(){
			var _=this
			_.li.css({left:width, display:'none', position:'absolute'});
			$('#content > ul, .prev, .next, .shadow').css({marginLeft:-2000})
			$('.menu').css({marginLeft:-200})
		}
	})
	
	var h_cont=734;
	function centre() {
		var h=$(window).height();
		var w=$(window).width();
		if (h>h_cont) {
			m_top=~~(h-h_cont)/2;
		} else {
			m_top=0;
		}
		$('header').stop().animate({paddingTop:m_top})
		$('.menu').stop().animate({top:m_top+268})
		if (w>1200) {
			$('.main').css({margin:'0 auto'})	
		} else {
			$('.main').css({margin:'0 0 0 150px'})	
		}
	}
	centre();
	$(window).resize(centre);
	
})
