$(function(){
	
	$("#tabs").tabs();
	
	var tab = window.location.search.match(/tab=(.*)/); 
	if(tab)	$("#tabs").tabs('select',tab[1]);

	$.validator.messages = {
			required:"Pflichtfeld",
			email: "Ung\u00fcltige E-Mail Adresse",
			minlength: jQuery.format("Verwenden Sie mindestens {0} Zeichen")
		};
	
	$("[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'));
	})
	
	$(".fade").innerfade({
		containerheight:310,
		timeout:8000,
		speed:"slow"
	});
	
	$('.examples').html($('.hiddenExamples').html());
	
	$("ul.selectpreview a")
	.click(function(){

		$(".preview").hide();
		$("ul.selectpreview a").removeClass('on');
		
		var idcontent = $(this).attr('href');

		$(idcontent).show();
		$("ul.selectpreview  a[href^="+idcontent+"]").addClass('on');
		$('input[name=data[template]]').val(idcontent.match(/#preview-(.*)/)[1]);		
		
		return false;				
	});


	
	$("[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 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)
		
		$("form[name=Login]").submit(function(){
			if($("[name=txtuser]",this).val().match(/@/))
			{
				$(this).attr('action','http://admin.immoserver.ch/Authentication/login');
				$('[name=txtuser]',this).attr('name','data[username]');
				$('[name=txtpass]',this).attr('name','data[password]');
			}
		});


		 
		$("#contact").validate();
		$("#register").validate({
			rules: {
				'data[user][password]': {
					required: true,
					minlength: 6
				}
			}
		});
		
	
		$("input[name=txtuser]").focus();	
});

