$(document).ready(function(){
	$("#searchphraseh").focus(function(){
		if(this.value=="Suche"){
			this.value="";
		}
	});
	$("#searchphraseh").blur(function(){
		if(this.value==""){
			this.value="Suche";
		}
	});
	$("#searchphraseb").focus(function(){
		if(this.value=="Suche"){
			this.value="";
		}
	});
	$("#searchphraseb").blur(function(){
		if(this.value==""){
			this.value="Suche";
		}
	});
	$('a[rel="external"]').each(function(){
		$(this).attr("target","_blank");
	});
	function areaFocus(area, event){
		id=($(this).attr("id"));
		$("#img_"+id).css("display","block");
	}
	function areaBlur(area,event){
		id=($(this).attr("id"));
		$("#img_"+id).css("display","none");
	}
	
	$("#kontakt_standorte area").each(function(){
		$(this).focusin(areaFocus);
		$(this).focusout(areaBlur);
		$(this).mouseover(areaFocus);
		$(this).mouseout(areaBlur);
	});
	if(jQuery().prettyPhoto){
		$("a[rel^='video']").each(function(){
			var href=$(this).attr("href");
			var dimensionRegExp = new RegExp(/\s[w|h]([0-9]+)/g);
			var width = 800;
			var height= 600;
			var dimension = dimensionRegExp.exec($(this).attr("rel"));
			if(dimension!=null){
				if(dimension[0].substring(1,2)=="w"){
					width=dimension[1];
				}
				if(dimension[0].substring(1,2)=="h"){
					height=dimension[1];
				}
				dimension = dimensionRegExp.exec($(this).attr("rel"));
				if(dimension[0].substring(1,2)=="w"){
					width=dimension[1];
				}
				if(dimension[0].substring(1,2)=="h"){
					height=dimension[1];
				}
			}else{
				
			}
			href=href.replace(/\/show\//, "/");
			href=href.replace(/\.flv.*/,".flv");
			var videolink = href;
			href="/swf/flvplayer.swf?width="+width+"&height="+height+"&flashvars=file="+href+"&amp;autostart=1";
			//href="/swf/singlevideoplayer.swf?flashvars=flv="+href+"&autoplay=1";
			$(this).attr("href",href);
			//$(this).prettyPhoto();
		});
		
		$("a[rel^='gallery']").each(function(){
			var srcRegExp = new RegExp(/\s(\/.*)$/g);
			var src = srcRegExp.exec($(this).attr("rel"));
			$(this).attr("href",src[1]);
			$(this).attr("rel","gallery[aa]");
		});
		
		$("a[rel^='video'],a[rel^='gallery']").prettyPhoto({theme: 'facebook'});
	}
});
var custom = function(){
  return {
      createDoubleClickFrame : function(basePath){
		var axel = Math.random() + "";
		var a = axel * 10000000000000;
		var newFrame=document.createElement('iframe');
		newFrame.src=basePath+"" + a + "?";
		newFrame.width="1";
		newFrame.frameBorder="0";
		newFrame.height="1";
        $("body").append(newFrame);
		return newFrame;
      },
	  
	  /*trackDownload : function(obj,basePath){
		var axel = Math.random() + "";
		var a = axel * 10000000000000;
		var location = basePath+"" + a + "?";
		$.ajax({
			url: location,
			context:obj,
			complete:function(xhr,textStatus){
				document.location.href=this.href;
			}
		});
		return false;
	  },*/
	  trackDownload : function(obj, basePath){
		newFrame = custom.createDoubleClickFrame(basePath);
		newFrame.id = "dblclk"+Math.floor(Math.random()*1000000)+ (new Date().getTime())+'';
		var redirectURL = obj.href;
		// Get iframe callback.do the redirect. 
		$('#'+newFrame.id).load(function() 
		{
			document.location.href=redirectURL;
		});
		return false;
	  }
	  
    };
}();
