$(function(){
	var subP=false
	$('nav .mmenu>li>a,a.enter').append($('<span class="sbg"></span>').css({background:'#fff',opacity:0,zIndex:-1}))
	$('#content').hide()
	$('nav a.enter .sbg').css({background:'#ff5500'})
			
	$('a.enter')
		.bind('click',function(){
			show_subpages()
			return false
		})
	$('a[rel=nav]').one('click',function(){
		show_subpages()
	})
	
	$('nav a')
		.bind('mouseenter',function(){
			$('.sbg',this)
				.stop()
				.animate({
					opacity:1
				},{
					duration:500
				})
		})
		.bind('mouseleave',function(){
			if(!$(this).parent().is('.active'))				
			$('.sbg',this)
				.stop()
				.animate({
					opacity:0
				},{
					duration:500
				})
		})
	
	var navs=$('nav>.mmenu>li'),
		nav_rfrsh=window.nav_rfrsh=function(){
			navs
				.each(function(){
					var th=$(this)
					if(th.is('.active'))
						th
							.find('.sbg')
							.stop()
							.animate({
								backgroundColor:'#ff5500',
								opacity:1
							},{
								duration:600
							})
					else
						th
							.find('.sbg')
							.stop()
							.css({backgroundColor:'#fff'})
							.animate({
								opacity:0
							},{
								duration:600
							})
				})
		}	
	
	$('.soc-ico li a').each(function(){
		var th=$(this),
			im,sp,
			img=$('img',th)
				.wrap('<span></span>')
			img
				.parent()
					.css({
						width:'29px',
						height:'28px',
						overflow:'hidden',
						display:'block',
						position:'absolute'
					})
					.clone()
						.appendTo(th)
						.find('img')
							.css({
								marginTop:'-28px'
							})
			sp=$('span',this).eq(1)
			th
				.bind('mouseenter',function(){
					sp
						.stop()
						.animate({opacity:0})
				})
				.bind('mouseleave',function(){
					sp
						.stop()
						.animate({opacity:.90})						
				})
		
	})
})

function show_subpages(){
	subP=true
	$('header')
		.stop()
		.animate({
			marginTop:0
		},{
			duration:800,
			complete:function(){
				$('#content')
					.fadeIn(1000)
				$('.soc-ico').fadeIn(1000)
				$('nav').css({overflow:'visible'})
			}
		})
		.find('nav a.enter')
			.stop()
			.animate({
				right:'-100%'
			},{
				duration:400,
				complete:function(){
					$(this).remove()
					$('header nav ul.mmenu')
						.stop()
						.animate({
							top:'0'
						},{
							duration:400
						})
				}
			})
}
