$(document).ready(function(){
	$(".hidden").hide();
	var target;
	//	toggle
	$("a.toggler").toggle(
		function(){
			target=this.href.match(/#(\w.+)/)[1];
			$('#'+target).show();
		},
		function(){
			target=this.href.match(/#(\w.+)/)[1];
			$('#'+target).hide();
		}
	);

	//	delvalue
	$(".delvalue").focus(
		function(){
			this.value='';
		}
	);
	//	defaultfocus
	$(".defaultfocus").each(function(){
		this.focus();
		});
	//	popup
	$(".popup").click(
		function(){
			var newwindow=window.open(this.href,'popup','height=400,width=450,scrollbars=yes,resizable=yes');
			return false;
		}
	);
	// 	tabs
	if($.fn.tabs)$(".tabs").tabs();
	
	// datePicker
	if($.fn.calendar){
		$('input.date-picker').calendar({dateFormat: 'DMY.'});
	}
	// fillin
	$(".fillin").click(
		function(){
			target=this.rel;
			document.getElementById(target).value+=this.firstChild.nodeValue+" ";
			return false;
		}
	);
	// validation
	if($.fn.validate){
			
		$(".required").blur(function() {
          $(this).validate.required(this);
		});
		$(".minlength").blur(function() {
          $(this).validate.minlength(this);
		});
		$(".email").blur(function() {
          $(this).validate.email(this);
		});
		$(".alphanumeric").blur(function() {
          $(this).validate.alphanumeric(this);
		});
	}
	//	ticker
	if($.fn.newsTicker){
		$("#medialist", "#rightcol").css({"margin-bottom":"0"});
		$("#medialist").newsTicker();
	}
	
	
	// 	plugin
	if($.fn.jmedia)  {
		$(".jmedia").jmedia({mode:"onclick",
			version:"6",
			elemType:"div",
			errTxt:"<div class=\"jm_onfailure\"><p>OOOPS - Ihrem Browser scheint ein aktuelles <a title=\"Real Plugin downloaden\" href=\"http://www.real.com/freeplayer/?rppr=rnwk\">Real-Player-Plugin</a> zu fehlen.</p><p>Alternativ k&ouml;nnen Sie versuchen, das Video <a href=\"#link\">in einem externen Player abzuspielen</a>.</p></div>",
			elemClass:"jm_real"},
			{autostart:true,
			width:350,
			controls:"ImageWindow,ControlPanel",
			maintainaspect:true});
		
		
		
	}
	
	$(".jmedia_flv").click(function(){
		var _el=$('<div class="jm_real"><div id="flv"></div></div>');
		$(".jm_closebtn").remove();
		var _closecon=$("<span></span>");;
		$(_closecon).addClass("jm_closebtn");
		$(_closecon).css({width:350});
		var _closebtn=$('<a href="#">close&nbsp;</a>');
		$(_closecon).append($(_closebtn));
		$(_closebtn).click(function(){$(_el).remove();return false;});
		$("body").append($(_el));
		$(_el).show();
		$(_el).prepend($(_closecon));
		var _elHref = $(this).attr("href");
		var flashvars = {
			repeat:"true",
			autostart:"true",
			screencolor:"0xFFCC00",
			backcolor:"0xFFCC00",
			frontcolor:"0x434C5F",
			lightcolor:"0x000000",
			file:_elHref,
			width:"350",
			height:"300"
		};
		var params = {
			allowfullscreen: "false"
		};
		var attributes = {};
		swfobject.embedSWF("http://www.wuestefilm.de/mov/flvplayer.swf", "flv", "350", "300", "8.0.0","http://www.wuestefilm.de/mov/expressInstall.swf", flashvars, params, attributes);
		return false;
	});
	
	$(".searchtoggler").click(function(){
		$("#searchform").toggle();
		if($("#searchform").css("display")=='block'){
			$("#header").css({"padding-top":"4em"});
			$(this).addClass("active");
		}
		else if($("#searchform").css("display")=='none'){
			$("#header").css({"padding-top":"0"});
			$(this).removeClass("active");
		}
		return false;
	});
	
	var _html=$(".imgkompass").html();
	$("#kompass").hover(
		function(){
			$(".imgkompass").jmedia({mode:"replace",version:"6",elemClass:"imgkompass"},{src:baseURL+"img/background/kompass_animation.swf",width:"63",height:"63",wmode:"transparent"});
			if ($(".imgkompass").children("object").size()!=0 || $(".imgkompass").children("embed").size()!=0) $(".imgkompass").css({"margin-top":"-1px", "margin-left":"-3px"});
		},
		function(){
			$(".imgkompass").html(_html);
			$(".imgkompass").css({"margin-top":"0", "margin-left":"0"});
		}
	);
	$(".jexp").each(function(k) {
		txtarea=this;
		// getting textarea id
		if(!txtarea.getAttribute("id")){
			txtarea.setAttribute("id","exp_"+k)
		}
		var tid=txtarea.getAttribute("id");
		
		var br=document.createElement('br');
		document.getElementById(tid).parentNode.appendChild(br,document.getElementById(tid));
		var w_link=document.createElement('a');
		w_link.setAttribute("href","#"+tid);
		w_link.setAttribute("class","sbutton");
		var w_linktext=document.createTextNode(' + ');
		w_link.appendChild(w_linktext);
		document.getElementById(tid).parentNode.appendChild(w_link,document.getElementById(tid));
		w_link.onclick=function(){
			var _i=this.href.split('#');
			document.getElementById(_i[1]).style.height='350px';
			return false;
		}
		
		var bspc=document.createTextNode(' ');
		document.getElementById(tid).parentNode.appendChild(bspc,document.getElementById(tid));
		
		var w_link2=document.createElement('a');
		w_link2.setAttribute("href","#"+tid);
		w_link2.setAttribute("class","sbutton");
		var w_linktext2=document.createTextNode(' - ');
		w_link2.appendChild(w_linktext2);
		document.getElementById(tid).parentNode.appendChild(w_link2,document.getElementById(tid));
		w_link2.onclick=function(){
			var _i=this.href.split('#');
			document.getElementById(_i[1]).style.height='50px';
			return false;
		}
		var bspc=document.createTextNode(' ');
		document.getElementById(tid).parentNode.appendChild(bspc,document.getElementById(tid));
		
		
		});
});


