
$(window).load(function(){
	$('#content,#gallery').show()
	$('.wrap:not(.scroll)').each(function(){
		var th=$(this)
		th.css({width:th.width(),height:th.height()})
	})
    $('.scroll').jScrollPane({
	   showArrows:false,
	   scrollbarWidth:40,
	   dragMaxHeight:70
	})
	
	$('#gallery ul>li').eq(0).addClass('current')
	$('#gallery ul>li').eq(-1).addClass('last')
	
	$('#gallery .tip').each(function(){
		var th=$(this)
		th.data('fheight',th.height()).css({height:0})
	})
	
	$('.h2').hover(function(){
		$(this).stop().animate({backgroundColor:'#b1d453'})
	},function(){
		$(this).stop().animate({backgroundColor:'#d8d4ca'})
	})
	
	$('#gallery,.gal_next,.gal_prev').hide()
	
	$('#content>li').eq(0).addClass('_vis').siblings().hide()
	
})
$(function(){
	var keeper=$('#content'),block=false
		css={act:{backgroundColor:'#fff',color:'#474747'},def:{backgroundColor:'#474747',color:'#bdbbb4'}},
		show_item=function(itm){
			$('>._vis',keeper).stop().animate({width:0,height:0},function(){
				$(this).removeClass('_vis').hide()				
			})
			itm.css({width:0,height:0}).show().stop().animate({width:'100%',height:'100%'}).addClass('_vis')
		},
		show_gallery=function(){
			$('#gallery,.gal_next,.gal_prev').fadeIn()
		},
		hide_gallery=function(){
			$('#gallery,.gal_next,.gal_prev').fadeOut()
		},
		gall_chng=function(){
			var ul=$('#gallery ul')
			if(!block)ul.animate({top:-ul.find('.current').attr('offsetTop')},function(){block=false})
			wheel_block=false
		}
		
	$('nav').delegate('li:not(.active) a','mouseenter mouseleave',function(){
		var th=$(this)
		th.stop().animate(th.toggleClass('hover').is('.hover')?css.act:css.def,300)
		return false
	})
	
	$('.button').live('hover',function(){
		var th=$(this)
		th.toggleClass('hover')
		if(th.is('.hover'))
			th.stop().animate({backgroundColor:'#b1d453'},300)
		else
			th.stop().animate({backgroundColor:'#d8d4ca'},300)
	})
	
	$('nav').delegate('a','click',function(){
		if(~this.parentNode.className.indexOf('active'))return false
		var id=this.href.slice(this.href.indexOf('#'))
		$(this).css(css.act)
			.parent().addClass('active')
			.siblings().removeClass('active')
			.find('a').removeClass('hover').stop().animate(css.def,300)
		$(document).trigger('subPageChange',id)
		show_item($(id))
		return false
	})
	
	$('a[rel=nav]').live('click',function(){
		var id=this.href.slice(this.href.indexOf('#'))
		$(document).trigger('subPageChange',id)
		$('nav li').removeClass('active').find('a').removeClass('hover').stop().animate(css.def,300)
		show_item($(id))
		return false
	})
	
	$(document).bind('subPageChange',function(e,data){
		if(data=='#page2')
			show_gallery()
		else
			hide_gallery()
	})
	
	
})

