$(function(){

	
	$("[rel=lightbox]").lightBox({
		imageLoading:images.loading,
		imageBtnPrev:images.prev,
		imageBtnNext:images.next,
		imageBtnClose:images.close,
		imageBlank:images.blank,
		txtImage: '',
		txtOf: ''
	});
	
	$(".partner img").hover(function(){
		$(this).attr('src',$(this).attr('src').replace('.gif','_on.gif'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace('_on.gif','.gif'));
	})
	
	
	$("[rel=portfolio]").mouseover(function(){
		
		$("[rel=portfolio]").removeClass('on');
		
		$(".portfolio .zoom").fadeOut(function(){
			$(this).remove();
		});
		
		$('<img class="zoom"/>')
			.hide()
			.load(function(){
				$(this).fadeIn();
			})
			.attr('src',$(this).attr('href'))
			.prependTo('.portfolio .img');
		
		$(this).addClass('on');
		return false;
	}).click(function(){
		return false;
	});
	
	$(".portfolio .img")
		.mouseenter(function(){$(".overlay",this).stop(true,true).fadeIn('fast');})
		.mouseleave(function(){$(".overlay",this).stop(true,true).fadeOut('fast');});
	
	$(".gnext").click(function(){
		var o = $(".portfolio .images .on");
		(o.next().length ? o.next() : $(".portfolio .images a:first"))
			.mouseover();
	});
	$(".gprev").click(function(){
		var o = $(".portfolio .images .on");
		(o.prev().length ? o.prev() : $(".portfolio .images a:last"))
			.mouseover();
	})
	
	function play()
	{
		if(!fades[fadeIdx])
			fadeIdx = 0;
		
		$("<img />")
			.hide()
			.load(function(){
				var size = {
					w: $(this).width(),
					h: $(this).height()
				};
				
				$(this).siblings()
					.fadeOut(1200,function(){
						$(this).remove();
					});
				
				$(this)
					.css({
						width: 1000,
						top: ((310-size.h)*0.5)+'px',
						left: '0px'
					})
					.fadeIn(1200,function(){
						$(this)
							.animate({
								width: size.w
							}, 10000/*)
							.animate({
								top: ((310-size.h)*0.6)+'px',
								left: '-100px'
							}, 10000*/,function(){
								if(fades.length>1)
									window.setTimeout(play,2000);
							})
					})
			})
			.attr('src',fades[fadeIdx++])
			.prependTo(".header");
	}
	
	var fadeIdx = 0;
	var fades = [];
	$('.header.fade a').each(function(){
		fades.push($(this).attr('href'));
	}).remove();
	if(fades!="")
		play(fades);
	else{	
		$('.header a').each(function(){
			$("<img />").attr("src",$(this).attr("href")).prependTo(".header");
		});
	}
	
	function toEnable()
	{
		tot = window.setTimeout(function(){
			$("#clone").remove();
			},2000)
	}

	function toDisable()
	{
		window.clearTimeout(tot);
	}

	tot = null;
	$(".navi > li > a")
		.mouseenter(function(){
			toDisable();
			$("#clone").remove();
			$(this)
				.next(".second")
				.clone()
					.hide()
					.attr("id","clone")
					.css("position","absolute")
					.css("top",$(this).offset().top+$(this).outerHeight())
					.css("left",$(this).offset().left)
					.appendTo("body")
					.mouseover(toDisable)
					.mouseout(toEnable)
					.show()
		})
		.mouseout(toEnable)
});
