$(window).load(function(){
	
	$('#form1').forms()
	
	$('.vSlider').vSlider({
		show:2,
		duration:400
	})
	
	$('.portfolio li ul li a').fancybox({
		overlayColor:'#000'
	})
	
	$('.sf ul').sprites({
		method:'corners'
	})
	
	$('.sf').superfish({
		autoArrows:false
	})
	
	
	$('.scroll').cScroll({
		duration:700,
		step:100
	}).each(function(){
		var data=$(this).data('cScroll')
		$(this).parent().siblings('.scrollDown,.scrollUp')
			.click(function(){
				if($(this).is('.scrollUp'))
					data.upFu()
				else
					data.downFu()
				return false
			})
	})
	
	var nav=$('nav'),
		content=$('#content')
	
	nav.navs({
		hoverIn:function(li){
			$('>a',li)
				.stop()
				.animate({
					color:'#2eb799'
				},{
					duration:600
				})
		},
		hoverOut:function(li){
			$('>a',li)
				.stop()
				.animate({
					color:'#757575'
				},{
					duration:600
				})
		},
		hover:true
	})
	
	nav.navs(0)
	
	content.tabs(0)
	content.tabs({
		waitWhileAnimation:true,
		duration:300,
		showFu:function(){
			var _=this
			$.when(_.itms).then(function(){
				if(_.n==0)
					_.next.fadeIn(_.duration)
				else
					_.next.toonelIn(_.duration),
					_.next.find('.inner').fadeIn(_.duration/2)
			})			
		},
		hideFu:function(){
			var _=this
			if(_.prev==0)
				_.itms.not(':hidden').fadeOut(_.duration)
			else
				_.itms.not(':hidden').toonelOut(_.duration),
				_.itms.not(':hidden').find('.inner').fadeOut(_.duration/2)
		}
	})
	
	nav.navs(function(n){
		content.tabs(n)
	})
	
	var ctgrs=$('.ctgrs'),
		ctgrs_d=ctgrs.data('_navs')
	ctgrs.navs({
		hover:true,
		blockSame:false,
		hoverIn:function(li){
			$('a',li)
				.stop()
				.animate({
					width:250,
					height:250,
					fontSize:36
				},{
					easing:'easeInQuart'
				})
		},
		hoverOut:function(li){
			$('a',li)
				.stop()
				.animate({
					width:200,
					height:200,
					fontSize:24
				},{
					easing:'easeOutSine'
				})
		}
	})
	
	var clone
	
	ctgrs.navs(function(n,_){
		nav.navs(false)
		clone=ctgrs.clone().addClass('cloned')
		//clone.find('a').click(function(){return false})
		var crds=ctgrs.offsetRoot(),			
			cli=$('li',clone),
			cu=cli.eq(n),
			move=function(n){
				var w=this.width()/1.5,
					h=this.height()/1.5,
					tmp=[
						{left:w,top:h},
						{left:-w,top:h},
						{left:w,top:-h},
						{left:-w,top:-h}
					]
				return tmp[n]
			}
		clone
			.appendTo('body')
			.css({
				left:crds.left,
				top:crds.top
			})
		ctgrs.hide()
		
		cli.css({zIndex:1})
		cli.eq(n).css({zIndex:10})
		
		cu.find('a')
			.animate({
				width:250,
				height:250,
				fontSize:36
			},{
				easing:'easeOutQuart',
				duration:500
			})
		
		cli.each(function(i){
			var th=$(this)
			th
				.animate(move.call(th,i),{
					duration:500,
					easing:'easeOutQuart'					
				})				
		})
				
		$.when(cli,cu).then(function(){
			var a=cu.find('a'),
				root=a.offsetRoot()
				
			clone.css({left:root.left,top:root.top})
			cu.css({left:0,top:0,width:a.width(),height:a.height()})
			cli.not(cu).hide()
			portfolio.tabs(n)
		})	
	})
	
	$('.sha a').textShadow()
	
	var portfolio=$('.portfolio')
	portfolio.tabs({
		blockSame:false,
		showFu:function(){			
			var _=this,
				root=$('.portfolio').offsetRoot()
			$.when(_.itms).then(function(){
				_.next.show()
				clone
					.animate({
						top:root.top,
						left:root.left
					},{
						duration:800,
						complete:function(){
							clone
								.prependTo('.portfolio>ul>li:visible')
								.css({left:0,top:0})
						}
					})
				_.next
					.css({
						width:0,
						visibility:'visible',
						overflow:'visible'
					})
					.stop()
					.animate({
						width:760
					},{
						duration:800,
						complete:function(){
							nav.navs(true)
						}
					})
				$('.sha-img')
					.animate({
						width:'+=140px',
						height:'-=10px'
					},400)
					.animate({
						width:'-=140px',
						height:'+=10px',
						left:'+=140px',
						top:'-=30px'
					},400)
				$('#content>ul>li>.back').css({left:$('#content>ul>li>.back').prop('offsetLeft')}).animate({left:'20px',opacity:1},400)				
			})			
		}
	})
	
	$('>ul>li',portfolio).each(function(){
		var th=$(this)
		$('.next,.prev',th)
			.click(function(){
				$('.vSlider',th).vSlider($(this).is('.next')?'next':'prev')
				return false
			})
	})
	
	
	var back_to_portfolio=function(){
		var portfolio=$('.portfolio'),
			root1=portfolio.offsetRoot(),
			root2=ctgrs.css({visibility:'hidden'}).show().offsetRoot()
		
		clone
			.appendTo('body')
			.css({
				left:root1.left,
				top:root1.top
			})
			.animate({
				left:root2.left,
				top:root2.top,
				opacity:0
			})
		ctgrs.css({visibility:'visible'}).hide().fadeIn(function(){clone.remove()})
		
		ctgrs_d=ctgrs.data('_navs')
		
		ctgrs_d.li.removeClass(ctgrs_d.activeCl)
		ctgrs_d.li.each(function(){ctgrs_d.hoverOut($(this))})

		$('>ul>li:visible',portfolio)
			.animate({
				width:0
			},{
				duration:800,
				complete:function(){
					portfolio.find('>ul>li')
						.hide()
						.width(760)
				}
			})
		$('.sha-img')
			.animate({
				width:'-=140px'
			},400)
			.animate({
				width:'+=140px',
				left:'-=140px',
				top:'+=30px'
			},400)
		$('#content>ul>li>.back').animate({left:'-100%',opacity:0},400)
		sub_nav.navs('close')
	}
	
	$('#content>ul>li>.back')
		.css({left:'-100%',opacity:0})
		.click(function(){
			back_to_portfolio()
			return false
		})
	$('#gspinner').fadeOut()
})


;(function($){var c=['DOMMouseScroll','mousewheel'];$.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var i=c.length;i;)this.addEventListener(c[--i],handler,false);else this.onmousewheel=handler},teardown:function(){if(this.removeEventListener)for(var i=c.length;i;)this.removeEventListener(c[--i],handler,false);else this.onmousewheel=null}};$.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}});function handler(a){var b=[].slice.call(arguments,1),delta=0,returnValue=true;a=$.event.fix(a||window.event);a.type="mousewheel";if(a.wheelDelta)delta=a.wheelDelta/120;if(a.detail)delta=-a.detail/3;b.unshift(a,delta);return $.event.handle.apply(this,b)}})(jQuery);

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'V\']=h.i[\'y\'];h.M(h.i,{B:\'C\',y:9(x,t,b,c,d){6 h.i[h.i.B](x,t,b,c,d)},14:9(x,t,b,c,d){6 c*(t/=d)*t+b},C:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t+b;6-c/2*((--t)*(t-2)-1)+b},12:9(x,t,b,c,d){6 c*(t/=d)*t*t+b},Q:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t+1)+b},O:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t+b;6 c/2*((t-=2)*t*t+2)+b},P:9(x,t,b,c,d){6 c*(t/=d)*t*t*t+b},L:9(x,t,b,c,d){6-c*((t=t/d-1)*t*t*t-1)+b},S:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t+b;6-c/2*((t-=2)*t*t*t-2)+b},F:9(x,t,b,c,d){6 c*(t/=d)*t*t*t*t+b},J:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t*t*t+1)+b},K:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t*t+b;6 c/2*((t-=2)*t*t*t*t+2)+b},N:9(x,t,b,c,d){6-c*8.A(t/d*(8.g/2))+c+b},R:9(x,t,b,c,d){6 c*8.n(t/d*(8.g/2))+b},X:9(x,t,b,c,d){6-c/2*(8.A(8.g*t/d)-1)+b},11:9(x,t,b,c,d){6(t==0)?b:c*8.j(2,10*(t/d-1))+b},15:9(x,t,b,c,d){6(t==d)?b+c:c*(-8.j(2,-10*t/d)+1)+b},16:9(x,t,b,c,d){e(t==0)6 b;e(t==d)6 b+c;e((t/=d/2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t/=d)<(1/2.k)){6 c*(7.o*t*t)+b}m e(t<(2/2.k)){6 c*(7.o*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.o*(t-=(2.17/2.k))*t+.18)+b}m{6 c*(7.o*(t-=(2.19/2.k))*t+.1a)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.z(x,t*2,0,c,d)*.5+b;6 h.i.r(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|5625||sqrt|easeOutBounce|||abs|asin|undefined||swing|easeInBounce|cos|def|easeOutQuad|525|easeInCirc|easeInQuint|easeOutCirc|easeInOutCirc|easeInElastic|easeOutQuint|easeInOutQuint|easeOutQuart|extend|easeInSine|easeInOutCubic|easeInQuart|easeOutCubic|easeOutSine|easeInOutQuart|easeOutElastic|easeInOutElastic|jswing|easeInBack|easeInOutSine|easeOutBack|easeInOutBack||easeInExpo|easeInCubic|easeInOutQuad|easeInQuad|easeOutExpo|easeInOutExpo|25|9375|625|984375|easeInOutBounce'.split('|'),0,{}))

;(function(d){d.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,b){d.fx.step[b]=function(a){if(a.state==0){a.start=getColor(a.elem,b);a.end=getRGB(a.end)}a.elem.style[b]="rgb("+[Math.max(Math.min(parseInt((a.pos*(a.end[0]-a.start[0]))+a.start[0]),255),0),Math.max(Math.min(parseInt((a.pos*(a.end[1]-a.start[1]))+a.start[1]),255),0),Math.max(Math.min(parseInt((a.pos*(a.end[2]-a.start[2]))+a.start[2]),255),0)].join(",")+")"}});function getRGB(a){var b;if(a&&a.constructor==Array&&a.length==3)return a;if(b=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(a))return[parseInt(b[1]),parseInt(b[2]),parseInt(b[3])];if(b=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(a))return[parseFloat(b[1])*2.55,parseFloat(b[2])*2.55,parseFloat(b[3])*2.55];if(b=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(a))return[parseInt(b[1],16),parseInt(b[2],16),parseInt(b[3],16)];if(b=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(a))return[parseInt(b[1]+b[1],16),parseInt(b[2]+b[2],16),parseInt(b[3]+b[3],16)];if(b=/rgba\(0, 0, 0, 0\)/.exec(a))return e['transparent'];return e[d.trim(a).toLowerCase()]}function getColor(a,b){var c;do{c=d.curCSS(a,b);if(c!=''&&c!='transparent'||d.nodeName(a,"body"))break;b="backgroundColor"}while(a=a.parentNode);return getRGB(c)};var e={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]}})(jQuery);

$.fn.offsetRoot=function(root){
	if(root==undefined)
		root='body'
	var th=this,
		tmp=this[0],
		ret={left:tmp.offsetLeft,top:tmp.offsetTop}
	while(!$(tmp).is(root))
		tmp=tmp.offsetParent,
		ret.left+=tmp.offsetLeft,
		ret.top+=tmp.offsetTop
		
	return ret
}

//prototype extends
Array.prototype.lastIndexOf=Array.prototype.lastIndexOf||function(val,i){
i=this.length-i||this.length
while(--i^-1)
	if(this[i]==val)
		return i
return -1
}

Array.prototype.indexOf=Array.prototype.indexOf||function(val,i){
i=i-1||-1
while(++i^this.length)
	if(this[i]==val)
		return i
return -1
}
