$(function(){
	$(['images/bg1.jpg','images/bg2.jpg','images/bg3.jpg','images/bg4.jpg','images/bg5.jpg']).bgSlider({pags:'.pags li a',slideshow:true,interval:10000,preload:true})
	
	$('header a.shattle').live('click',function(){
		var h=$('header')
		if(h.hasClass('hidden'))
			h.animate({width:'980px'},'slow')
		else
			h.animate({width:'301px'},'slow')
		h.toggleClass('hidden')
		return false
	})
	
	var fader=function(){
		$('header nav ul li:not(.active) a').stop().animate({opacity:.7},'fast')
	},top=true,h
	$('header nav li:not(.active) a').live('click',function(){
		var c=$('#content'),href=this.href.toString(),id=href.slice(href.indexOf('#'))
		if(top)
			$('#main').css({top:$('#main').attr('offsetTop')+'px'}).animate({top:'69px'},function(){$(id+', footer').fadeIn()}),
			$('header nav li').removeClass('active'),
			$(this.parentNode).addClass('active'),
			top=false
		else 
			$('#main').css('top','69px')
			$('>li',c).hide(),
			$('header nav ul li').removeClass('active'),
			$(id,c).fadeIn()
		$(this).parent().addClass('active').find('a').stop().animate({opacity:1},'fast')
		fader()
		return false
	})
	$('footer .privacy a').live('click',function(){
		$('#content>li').hide()
		$('header nav li').removeClass('active')
		$('#privacy').fadeIn()
		fader()
		return false
	})
	$('header h1 a').live('click',function(){
		if(!top)
			$('#content>li,footer').slideUp(),		
			$('#main').animate({top:document.body.offsetHeight/10*3+'px'},function(){this.style.top='30%'}).find('nav li').removeClass('active'),
			fader(),
			top=true
		return false
	})
	$('header nav ul li:not(.active) a').live('mouseover',function(){
		$(this).stop().animate({opacity:1})
	})
	$('header nav ul li:not(.active) a').live('mouseout',function(){
		$(this).stop().animate({opacity:.7})
	})
	fader()
	
	$('a.button').live('mouseover',function(){
		$(this).stop().animate({top:'-6px'},200,function(){
			$(this).animate({top:0},200)
		})
	})
	
	$('#thumbs a').live('click',function(){
		$('#pic img').attr('src',this.href)
		$('#thumbs .current').removeClass('current')
		$(this).addClass('current')
		return false
	})
	
	$('#pic img').bind('load',function(){
		$(this).css({opacity:0}).animate({opacity:1})
	})
	
	$('a[rel=prev],a[rel=next]').live('click',function(){
		var thumbs=[],curr=i=0
		$('#thumbs a').each(function(){
			thumbs.push(this)
			if($(this).hasClass('current'))
				curr=i
			i++
		})
		thumbs=[].concat(thumbs.slice(curr),thumbs.slice(0,curr))
		if(this.rel!='prev')
			thumbs.push(thumbs.shift())
		else
			thumbs.unshift(thumbs.pop())
		$(thumbs).removeClass('current').eq(0).addClass('current')
		$('#pic img').attr('src',thumbs[0].href)
		$('#thumbs a.current').trigger('changeImg')
		return false
	})
	
	$('#thumbs a').each(function(){
		var tmp=new Image()
		tmp.src=this.href
	})
	
	$('#thumbs a.current').live('changeImg',function(){
		$('#thumbs>ul>li').each(function(){
			if($('.current',this).length)				
				$(this.parentNode).animate({left:'-'+this.offsetLeft+'px'})
		})
		return false
	})
	
	$('#thumbs li>a').css({opacity:0.7}).live('mouseover',function(){$(this).stop().animate({opacity:1})}).live('mouseout',function(){$(this).stop().animate({opacity:0.7})})
	
	$('a.button').trigger('mouseover')
	$('#content>li,footer').hide()

})
