$(document).ready(function() {
	// hover
	
	$('footer a').hover(function(){
		$(this).find('span').stop().animate({width:'100%', left:0})						 
	}, function(){
		$(this).find('span').stop().animate({width:0, left:'50%'})						 
	})
	
	
	$('ul#menu').superfish({
      delay:       600,
      animation:   {top:'show'},
      speed:       600,
      autoArrows:  false,
      dropShadows: false
    });
	
	$('#gallery1 span').css({opacity:0})
	
	$('#gallery1 a').hover(function(){
		$(this).find('span').stop().animate({opacity:0.5})							
	} ,function(){
		$(this).find('span').stop().animate({opacity:0})							
	})
	
	$("#gallery1 a").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over'
	});
	
	
	$(".google_map").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over'
	});
	
	$(".google_map").click(function(){
		$('#google_map').html('<iframe width="598" height="418" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Brooklyn,+New+York,+NY,+United+States&amp;aq=0&amp;sll=37.0625,-95.677068&amp;sspn=61.282355,146.513672&amp;ie=UTF8&amp;hq=&amp;hnear=Brooklyn,+Kings,+New+York&amp;ll=40.649974,-73.950005&amp;spn=0.01628,0.025663&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>')							
	})
	
	$('.list1 a').hover(function(){
		$(this).stop().animate({paddingLeft:30}, 600, 'easeOutElastic')						 
	}, function(){
		$(this).stop().animate({paddingLeft:20}, 600, 'easeOutElastic')						 
	})
	
	$('#icons a').hover(function(){
		$(this).stop().animate({marginTop:-5, paddingBottom:5}, 600, 'easeOutElastic')					 
	}, function(){
		$(this).stop().animate({marginTop:0, paddingBottom:0}, 600, 'easeOutElastic')					 
	})
	
	$('.link1').hover(function(){
		$(this).stop().animate({paddingRight:22}, 600, 'easeOutElastic')
	}, function(){
		$(this).stop().animate({paddingRight:17}, 600, 'easeOutElastic')
	})
	
 });
$(window).load(function() {	
	
	
	// scroll
	$('.scroll').cScroll({
		duration:700,
		step:63,
		trackCl:'track',
		shuttleCl:'shuttle'
	})	
	
	
	//content switch
	var content=$('#content'),
		nav=$('.menu');
	nav.navs({
		useHash:true,
		hoverIn:function(li){
			$('> span',li).stop().animate({width:172, height:172},{step:function(now){
					$(this).css({borderWidth:(86-now/2)})
				}, duration:300, easing:'easeOutCirc'
			})					
		},
		hoverOut:function(li){
			if (!li.hasClass('with_ul') || !li.hasClass('sfHover')) {
				$('> span',li).stop().animate({width:0, height:0},{step:function(now){
						$(this).css({borderWidth:(86-now/2)})																
					}, duration:300, easing:'easeInCirc'
				})					
			}
		}				
	})	
	content.tabs({
		actFu:function(_){
			if (_.prev) {
				_.prev.find('.pad').stop().animate({opacity:0},200, function(){
					$(this).css({visibility:'hidden'})
					_.prev.find('.box').stop().animate({top:203, left:470, width:0, height:0},300,'easeOutCirc', function(){
						_.prev.css({display:'none'});
						if (_.curr) {
							_.curr.css({display:'block'}).find('.box').stop().animate({top:0, left:0, width:940, height:405},900,'easeOutBounce', function(){
								_.curr.find('.pad').css({visibility:'visible'}).stop().animate({opacity:1},200);
							});
						} else {
						}
					})
				})
			} else {
				if (_.curr) {
					_.curr.css({display:'block'}).find('.box').stop().animate({top:0, left:0, width:940, height:405},900,'easeOutBounce', function(){
						_.curr.find('.pad').css({visibility:'visible'}).stop().animate({opacity:1},200);
					});
				} else {
				}
			}
		},
		preFu:function(_){						
			_.li.css({display:'none'});
			_.li.find('.box').css({top:203, left:470, width:0, height:0});
			_.li.find('.pad').css({opacity:0, visibility:'hidden'});
		}
	})
	nav.navs(function(n, _){
		if (n=='close' || n=='#!/') {
			$('#content').stop().animate({height:0});
			$('#logo').stop().animate({width:354, height: 181})
			$('#slogan').stop().animate({marginLeft:127})
			$('h1').stop().animate({paddingTop:127, paddingLeft:293, paddingBottom:43})
			$('header').stop().animate({height:571})
			$('.submenu').css({visibility:'hidden'})
			$('.submenu').parent().removeClass('with_ul')
			random_position();
			ball(1)
		} else {
			$('#content').stop().animate({height:405})
			$('#logo').stop().animate({width:142, height: 72})
			$('#slogan').stop().animate({marginLeft:0})
			$('h1').stop().animate({paddingTop:0, paddingLeft:0, paddingBottom:28})
			$('header').stop().animate({height:327})
			$('.submenu').css({visibility:'visible'})
			$('.submenu').parent().addClass('with_ul')
		}
		content.tabs(n);
	})
	
	function ball(i){
		var th=$('#menu > li').eq(i-1);
		th.delay(180*i).stop().animate({top:0},500, 'easeOutElastic')
		if (i<$('#menu > li').length) ball(i+1)	
	}
	
	function random_position(){
		$('#menu > li').each(function(){
			r=1
			if (Math.random()<0.5) {r=-1}						  
			$(this).css({top:r*800})
		})
	}
	
	
	var m_top=0,
		h_cont=840
	function centre() {
		var h=$(window).height();
		if (h>h_cont) {
			m_top=(h-h_cont)/2;
		} else {
			m_top=0
		}
		$('.main').stop().animate({paddingTop:m_top})
		
	}
	centre();
	$(window).resize(centre);
	
})