$(document).ready(function() {
	// hover
	$('#nav #button').click(function(){
		if ($(this).hasClass('hidden')) {
			$(this).removeClass('hidden');
			$('#nav nav').stop().animate({height:45})			
		} else {
			$(this).addClass('hidden');
			$('#nav nav').stop().animate({height:0})
		}
		return false
	})
	
	$('#menu > li > a').eq(1).css({background:'#4482b7'})
	$('#menu > li > a').eq(2).css({background:'#8facda'})
	$('#menu > li > a').eq(3).css({background:'#c6d3eb'})
	$('#menu > li > a').eq(4).css({background:'#f34243'})
	$('#menu > li > a').eq(5).css({background:'#424346'})
	
	$('#content > ul > li').eq(1).find('.title span').css({background:'#4482b7'})
	$('#content > ul > li').eq(2).find('.title span').css({background:'#8facda'})
	$('#content > ul > li').eq(3).find('.title span').css({background:'#c6d3eb'})
	$('#content > ul > li').eq(4).find('.title span').css({background:'#f34243'})
	$('#content > ul > li').eq(5).find('.title span').css({background:'#424346'})
	
	$('#menu > li').hover(function(){
		$(this).find('> a').stop().animate({height:45})						   
	}, function(){
		if (!$(this).hasClass('with_ul')&&!$(this).hasClass('active')) {$(this).find('> a').stop().animate({height:6})}
	})
	
	$('#icons .act').css({width:0, marginLeft:18})
	$('#icons a').hover(function(){
		$(this).find('.img').css({zIndex:1}).stop().animate({width:0, marginLeft:18}, 'easeOutQuad')
		$(this).find('.act').css({zIndex:2}).stop().animate({width:35, marginLeft:0}, 'easeOutQuad')					 
	}, function(){
		$(this).find('.act').css({zIndex:1}).stop().animate({width:0, marginLeft:18}, 'easeOutQuad')
		$(this).find('.img').css({zIndex:2}).stop().animate({width:35, marginLeft:0}, 'easeOutQuad')					 
	})
	
	$('.close span').css({opacity:0})
	
	$('.close').hover(function(){
		$(this).find('span').stop().animate({opacity:1}, function(){$(this).css({ opacity:'none'})})					   
	}, function(){
		$(this).find('span').stop().animate({opacity:0})					   
	})
	
	$('.list1 a').hover(function(){
		$(this).stop().animate({paddingLeft:35}, function(){$(this).animate({paddingLeft:30})})						 
	}, function(){
		$(this).stop().animate({paddingLeft:20}, function(){$(this).animate({paddingLeft:25})})						 
	})
	
	/*
	// for lightbox
	$("a[data-type^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	*/
	
	
	$('ul#menu').superfish({
      delay:       600,
      animation:   {height:'show'},
      speed:       600,
      autoArrows:  false,
      dropShadows: false
    });
	
	
	
		
 });
$(window).load(function() {	
	//bg animate
	
	$('#pagination a').each(function(e){
		$(this).data({num:e})							 
	})
	
	$('#menu a').each(function(e){
		$(this).data({num:e})							 
	})
	
	$('#pagination a').click(function(){
		num=$(this).data('num');
		if (!$(this).parent().hasClass('active')) {
			$('#caption .active').stop().animate({left:-1500},600, function(){
				$('#caption li').eq(num).addClass('active').stop().animate({left:0},600)														
			}).removeClass('active');
		}
	});
	
	$('#bgStretch').bgStretch({
			align:'leftTop',
			navigs:$('#pagination').navigs()
		})
		.sImg({
			spinner:$('<div class="spinner"></div>').css({opacity:.7}).hide()
	})
	
	$('#pagination li').eq(0).addClass('active');
	$('#caption li').eq(0).addClass('active').stop().animate({left:0},600)
	
	// scroll
	$('.scroll').cScroll({
		duration:700,
		step:100,
		trackCl:'track',
		shuttleCl:'shuttle'
	})	
	
	
	//content switch
	var content=$('#content'),
		nav=$('.menu');
	nav.navs({
		useHash:true
	})	
	nav.navs(function(n, _){
		content.cont_sw(n);
		$('#menu > li > a').stop().animate({height:6})
		if (_.n!=-1) {
			$('#menu > li').eq(_.n).find('> a').stop().animate({height:45})
		} else {
			$('#menu > li').addClass('active').find('> a').stop().animate({height:45});
		}
	})
	content.cont_sw({
		showFu:function(){
			$("#bgStretch").fadeOut('slow');
			var bgImgCs = $("#menu .active a").attr('rel');
			$("#bgStretch").prepend('<img alt="" src="images/'+bgImgCs+'" class="customOverlay" style="width: 100%; height: 100%; position: absolute; z-index: 1500; left: 0px; top: 0px;">').fadeIn('slow');
			
			var _=this			
			$.when(_.li.find('.box')).then(function(){
			$.when(_.li.find('.title span')).then(function(){
				$.when(_.li.find('.bg_cont')).then(function(){	
					_.next.css({display:'block'}).find('.bg_cont').stop().animate({width:'100%', marginLeft:0}, 'easeOutCirc', function(){
						_.next.find('.title span').stop().animate({height:48})
						_.next.find('.close').stop().animate({width:53})											
						_.next.find('.box').css({visibility:'visible'}).stop().animate({opacity:1}, function(){$(this).css({opacity:'none'})})																													 
					});	
				});
			});
			});
			$('#splash').stop().animate({left:-3000},1200)
		},
		hideFu:function(){
			var _=this
			_.li.find('.box').stop().animate({opacity:0}, function(){
				$(this).css({visibility:'hidden'})
				_.li.find('.close').stop().animate({width:0})		
				_.li.find('.title span').stop().animate({height:0}, function(){
					_.li.find('.bg_cont').stop().animate({width:0, marginLeft:470}, 'easeOutCirc', function(){
						_.li.css({display:'none'})
					});
				});
			})
			$('#splash').stop().animate({left:0},1200)
		},
		preFu:function(){
			var _=this
			_.li.css({position:'absolute', display:'none'});
		}
	})
	$('#menu > li').addClass('active').find('> a').css({height:45});
	var h_cont=820;
	function centre() {
		var h=$(document).height();
		if (h>h_cont) {
			m_top=~~(h-h_cont)/2;
		} else {
			m_top=0;
		}
		$('.main').stop().animate({marginTop:m_top})
	}
	centre();
	$(window).resize(centre);
	
	
	
})

$('.close').live("click", function(){
		$('.customOverlay').remove();
	});
	
	
	
	
	

$(window).bind("load", function() { 

       var footerHeight = 0,
           footerTop = 0,
           $footer = $("#footer");

       positionFooter();

       function positionFooter() {

                footerHeight = $footer.height();
                footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";

               if ( ($(document.body).height()+footerHeight) < $(window).height()) {
                   $footer.css({
                        position: "absolute"
                   }).animate({
                        top: footerTop
                   })
               } else {
                   $footer.css({
                        position: "static"
                   })
               }

       }

       $(window)
               .scroll(positionFooter)
               .resize(positionFooter)

});


