$(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'));
	})
	
	
	$("a[rel='colorbox']").colorbox({
		maxWidth:'1000',
		scalePhotos:false,
		opacity:1,
		onComplete:function(){
			$(".panorama img")
				.load(function(){
				var size = {
						w: $(this).width(),
						h: $(this).height()
					};
				$(this).animate({ 
				    left: 958-size.w}, size.w*15 );
				})
		}
	});

	$("div.gallery div.line").each(function(){
		$("a[rel=box]",this).lightBox({
			fixedNavigation:true,
			imageLoading:images.loading,
			imageBtnPrev:images.prev,
			imageBtnNext:images.next,
			imageBtnClose:images.close,
			imageBlank:images.blank,
			txtImage:"Foto",
			txtOf:" von "
		});
	});
	
	
	$("a.[rel=flashvideo]").click(function(){	
		$("#player,#close").show();
		
		$("#player").flash({  
			swf: playerpath,
			width:512,
			height:307,
			flashvars: {
				file: $(this).attr('href'),
				autostart:"true"
				},
			params:{
					wmode: 			'opaque',
					allowfullscreen: 'true',
					allowscriptaccess: 'always'
				}
		});	
		
		return false;
	});
	
	
	
	
	
	
	$(".portfolio .zoom").load(function(){
		if($(this).width() > 750)
			$(this).animate({left: 720-$(this).width()}, $(this).width()*15);}
	);
	
	
	
	
	$("[rel=portfolio]").mouseover(function(){
		
		if($(this).attr('href') != $(".portfolio .zoom").attr('src'))
		{
			$("[rel=portfolio]").removeClass('on');
			
			
			if($(this).attr('href').search('.mov') != -1)
			{
				$('.roundshot embed').attr('src',$(this).attr('href'));
				$('.roundshot param[name=src]').val($(this).attr('href'));
			}
			else if($(this).attr('href').search('.mp4') != -1)
			{
				
				$(".play").children().remove();
				
				$(".play").flash({  
					swf: playerpath,
					width:512,
					height:307,
					flashvars: {
						file: $(this).attr('href'),
						autostart:"true"
						},
					params:{
							wmode: 			'opaque',
							allowfullscreen: 'true',
							allowscriptaccess: 'always'
						}
				});	
				
			}
			else
			{
			$(".portfolio .zoom").stop().fadeOut(function(){
				$(this).remove();
			});
			
			$('<img class="zoom"/>')
				.hide()
				.load(function(){
					$(this).fadeIn();
					
					if($(this).width() > 750)
						$(this).animate({left: 720-$(this).width()}, $(this).width()*15);
				})
				.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)
		
	$(".playVideo").flash({  
		swf: playerpath,
		width:512,
		height:307,
		flashvars: {
			file: $(".playVideo").attr("title"),
			autostart:"true"
			},
		params:{
				wmode: 			'opaque',
				allowfullscreen: 'true',
				allowscriptaccess: 'always'
			}
	});	
	
	$("#contact").validate({
		highlight: function(element, errorClass){
			$(element).addClass(errorClass).mouseover(function(e){
				if($(this).hasClass("email")){
					$("div.pflicht").text(pflichtfeld.email);}
				else{
					$("div.pflicht").text(pflichtfeld.text);}
				$("div.pflicht")
					.css("top",(parseInt(e.pageY)-40+getScrollY())+"px")
					.css("left",(parseInt(e.pageX)-39)+"px")
					.show();
			}).mousemove(function(e){
				$("div.pflicht")
					.css("top",(parseInt(e.clientY)-40+getScrollY())+"px")
					.css("left",(parseInt(e.clientX)-39)+"px");
			}).mouseout(function(){
				$("div.pflicht").hide();
			});
	  	},
	  	unhighlight: function(element, errorClass, validClass){
	  		$(element).removeClass(errorClass).mouseover(function(){
				$("div.pflicht").hide();
			}).mousemove(function(){
				$("div.pflicht").hide();
			});			 	
	  	},			  				  						
		errorPlacement: function(error, element){}											
	});
		
});

function getScrollY(){
	var scrOfY = 0;
	if(typeof(window.pageYOffset) == 'number'){
		/* Für Netscape */
		scrOfY = window.pageYOffset;
	}else if(document.body && document.body.scrollTop){
		/* Für DOM */
		scrOfY = document.body.scrollTop;
	}else if(document.documentElement && document.documentElement.scrollTop){
		/* Für IE6 */
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

