$(document).ready(function(){
	
	$(".navi a:not(a.active),.subnavi a:not(a.active,a.formular)").mouseenter(function(){
		$(this).stop().animate({color:$(".navi a.active").css("color")},500);
	}).mouseleave(function(){
		$(this).stop().animate({color:$(this).parent("li").css("color")},350);
	});
	
	$(".formular").mouseenter(function(){
		$(this).find("span").stop().animate({color:$(".navi a.active").css("color")},500);
		$(this).children("a").stop().animate({border:"1px solid "+$(".navi a.active").css("color")},500);
	}).mouseleave(function(){
		$(this).find("span").stop().animate({color:"#c6cacb"},500);
		$(this).children("a").stop().animate({border:"1px solid #c6cacb"},500);
	});
	
	$("#kontaktformular .close").click(function(){
		$("#kontaktformular").hide();
	});
	
	$("a.openform").click(function(){
		$("#kontaktformular").show();
		return false;
	});

	$(".navi li").mouseover(function(){
		$(this).children("ul").show();
	}).mouseout(function(){
		$(this).children("ul").hide();
	});
	
	$(".news").each(function(){
		$("a[rel=newsimage]",this).lightBox({
			fixedNavigation:true,
			imageLoading:images.loading,
			imageBtnPrev:images.prev,
			imageBtnNext:images.next,
			imageBtnClose:images.close,
			imageBlank:images.blank,
			txtImage:"Bild",
			txtOf:" von "
		});
	});
	
	var text_f_01 = $(".flashtext .text01").html();
	var text_f_02 = $(".flashtext .text02").html();
	var text_f_03 = $(".flashtext .text03").html();
	var text_width = $(".flashtext").width()+47;
	var color = "rgb(31,46,47)";
	if($(".text h1").css("color") != undefined)
		color = $(".text h1").css("color");
	color = rgb2hex(color);

	$(".flashtext").html("").flash({
		swf: flashitems.image,
		width:500,
		height:96,
		flashvars:{
			text01:text_f_01,
			text02:text_f_02,
			text03:text_f_03,
			color01:color,
			color02:color,
			color03:color
		},
		params:{wmode:'transparent'}
	});
	$(".flashtext").width(text_width);
	
	var text_s_01 = $(".slogan .sl").html();
	var text_s_02 = $(".slogan .name").html();
	$(".slogan").html("").flash({
		swf: flashitems.slogan,
		width:264,
		height:150,
		flashvars:{
			text01:text_s_01,
			text02:text_s_02,
			color01:color,
			color02:color
		},
		params:{wmode:'transparent'}
	});
	
	$(".fade").innerfade({
		containerheight:303,
		timeout:6000,
		speed:3000
	}); 

	
	$("a[rel=player]").each(function(){
		var video = '/resources/video.mp4';
		var image = '/resources/video.jpg';
		var skin = '/resources/bekle/bekle.xml';
		var swf = '/resources/player-licensed.swf';
		var player = $('<div class="player"/>');
		var autostart =  false;
		
		
		if($(this).hasClass('autoplay'))
			autostart = true;
		
		$(this).after(player).remove();
		
		$(player).flash({  
			swf: swf,
			width:640,
			height:360,
			flashvars: {
				file: video,
				image: image,
				autostart: autostart,
				skin: skin,
				controlbar: 'over',
				"controlbar.idlehide": true
				},
			params:{
					wmode: 				'opaque',
					allowfullscreen: 	'true',
					allowscriptaccess: 	'always'

				}
		});
	});

	

	
	$("#request").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 rgb2hex(rgb) 
{
	if(rgb.substr(0,1) == '#')
		return '0x'+rgb.substr(1);
	
	 rgb = rgb.replace(/[rgb\)\(]/g,'').split(',');
	 function hex(x) {
	  hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
	  return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
	 }
	return  '0x'+hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
}

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;
}
