// JavaScript Document

$(document).ready(function(){

	//alle links bluren
	$('a').each(function(){
		$(this).bind( 
			'focus', 
				
				function()
				{
					this.blur();
				}
		)
	}); 

	$('#schwerpunkt_click').each(function(){
		 $(this).bind('click', function(){ dropdown(this); })
	});
	
	
	$('.welcome_boxes .over').hover(function(){													  
		$(this).find('.text').show();
		$(this).find('.text div').fadeIn('slow');
	}, function() {	
		$(this).find('.text').hide();
		$(this).find('.text div').fadeIn('slow');	
	});

	prepareInputFields();
	tooltip('.referenzen_preimg','mouse_tip');

	//if (typeof(lightBox) != "undefined") {
		$('.imagesBox .medium a').lightBox();
		$('.imagesBox .thumbs a').lightBox();
		$('.referenzen_details .image a').lightBox();	
		$('a.organigramm').lightBox();			
	//}
		
	gallerySwitcher();
	
	startSwitcher();

    var contentBox = $("#content")[0];
    var leftContainer = $('#content .left')[0];
    var rightContainer = $('#content .right')[0];
		if (contentBox.offsetHeight > leftContainer.offsetHeight){
			$(leftContainer).css("height", (contentBox.offsetHeight)+"px");
			$(rightContainer).css("height", (contentBox.offsetHeight)+"px");
		}




});

function startSwitcher() {
	var imgTemp;
	var titleTemp;	

	//alle thumbnals...
	$('.welcome_boxes .img_listing img:not(.slide_right, .slide_left)').each(function(){
												
		if ($(this).parent().parent().hasClass('right')) var right = ".right"; else var right = ":not(.right)";
		//... sollen einen hover bekommen
		$(this).hover(
			//onmouseover
							
			function(){
				//das originalbild wird in eine tempvariable geschrieben
				imgTemp = $('.welcome_boxes'+right).css("background-image");
				titleTemp = $('.welcome_boxes'+right+' .img_desc').html();
				//das thumbnail bild wir ausgelesen
				var imageSRC = $(this).attr("src");
				//var imageTitle = $(this).attr("title");				
				imageSRC = imageSRC.replace(/small/,"large");
				//das "neue" bild wird geschrieben
				//$('.welcome_boxes'+right+' .img_desc').html(imageTitle);
				$('.welcome_boxes'+right).css("background-image","url("+imageSRC+")");
			},
			//onmouseout
			function(){
				//das alte bild aus "temp" wird geschrieben
				$('.welcome_boxes'+right+' .img_desc').html(titleTemp);				
				$('.welcome_boxes'+right).css("background-image",imgTemp);			
			});
	});
	
	$('.welcome_boxes .img_listing img:not(.slide_right, .slide_left)').each(function(){
																					  
		if ($(this).parent().parent().hasClass('right')) var right = ".right"; else var right = ":not(.right)";																					  		// alle a-tags sollen ein click event bekommen
		$(this).bind('click',
			function(){
				//das thumbild wird ausgelesen
				var imageSRC = $(this).attr("src");
				//var imageTitle = $(this).attr("title");				
				imageSRC = imageSRC.replace(/small/,"large");			
				imgTemp = imageSRC;
				//titleTemp = imageTitle;
				//das neue bild wird geschrieben
				$('.welcome_boxes'+right+' .img_desc').html(imageTitle);
				$('.welcome_boxes'+right).css("background-image","url("+imageSRC+")");
			});
	});	
	
}


function gallerySwitcher() {
	var imgTemp;				

	//links sollen gecleart werden, damit beim klicken auf den link nicht der href ausgefuehrt wird
	//$('.imagesBox .thumbs a').attr("href","javascript:void(0);");
	
	//alle thumbnals...
	$('.imagesBox .thumbs a').each(function(){
												
		//... sollen einen hover bekommen
		$(this).hover(
			//onmouseover
			function(){
				//das originalbild wird in eine tempvariable geschrieben
				imgTemp = $('.imagesBox .medium a img').attr("src");
				//das thumbnail bild wir ausgelesen
				var imageSRC = $(this).children('img').attr("src");
				imageSRC = imageSRC.replace(/small/,"medium");
				//das "neue" bild wird geschrieben
				$('.imagesBox .medium a img').attr("src",imageSRC);
			},
			//onmouseout
			function(){
				//das alte bild aus "temp" wird geschrieben
				$('.imagesBox .medium a img').attr("src",imgTemp);				
			});
	});
	
	$('.imagesBox .thumbs a').each(function(){
		// alle a-tags sollen ein click event bekommen
		$(this).bind('click',
			function(){
				//das thumbild wird ausgelesen
				var imageSRC = $(this).children('img').attr("src");
				var title = $(this).attr("title");				
				//und umgeformt
				imageSRC = imageSRC.replace(/small/,"medium");				
				aImageSRC = imageSRC.replace(/medium/,"large");								
				// die temp variable wird geleert, damit er beim mouseout nicht das ursprungsbild wiederherstellt
				imgTemp = imageSRC;
				//das neue bild wird geschrieben
				$('.imagesBox .medium a').attr("title",title);
				$('.imagesBox .medium a').attr("href",aImageSRC);
				$('.imagesBox .medium a img').attr("src",imageSRC);
			});
	});	
	
}



function prepareInputFields() {
 $('input[type=text]:not(.no-auto-clear)').each(function(){
	var startText = $(this).val();
	 $(this).bind('focus', function(){
	 startText = $(this).val();
	 $(this).val('');
 });
	 });
}

function dropdown(element){
 if ($(element).next().css("display") == "block"){
 	$(element).next().slideUp(100);
 } else {
 	$(element).next().slideDown(100);
 }
}

/* --- Tooltip fuer Mouseover Referenzen --- */
function tooltip(target_items, mouse_tip){	
	$(target_items).each(function(i){
	 $("body").append("<div class='"+mouse_tip+"' id='"+mouse_tip+i+"'><p>"+$(this).find("."+mouse_tip).html()+"</p></div>");
	  var tooltip = $("#"+mouse_tip+i);
	  
	$(this).hover(function(kmouse){						   
			tooltip.css({left:kmouse.pageX+10, top:kmouse.pageY+5});
			tooltip.show();
		},function(){
			tooltip.hide();
		});
	});
}
	
function tm_tracker() {
 var pageTitle = document.title;
 var pageUrl = document.URL;

 var page="http"+(document.URL.indexOf('https:')==0?'s':'')+'://www.trafficmaxx.de/controlcenter/thx.php?sid='+tm_sid+"\x26java=y";
 var tm_ref = escape(parent==self?document.referrer:top.document.referrer);
 tm_ref = (typeof(top.document)=="object")?top.document.referrer:tm_ref;
 var tm_lang = navigator.userLanguage?navigator.userLanguage:navigator.language;

 if (typeof(tm_pageCategory)=="undefined") tm_pageCategory = "";
 if (typeof(tm_conversionName)=="undefined") tm_conversionName = "";
 if (typeof(tm_campaignName)=="undefined")  tm_campaignName = "";

 tm="\x26swidth="+swidth;
 tm+="\x26sheight="+sheight;
 tm+="\x26scolor="+scolor;
 tm+="\x26la="+escape(tm_lang.toLowerCase());
 tm+="\x26pageTitle="+escape(pageTitle);
 tm+="\x26pageUrl="+escape(pageUrl.toLowerCase());
 tm+="\x26pageCategory="+escape(tm_pageCategory);
 tm+="\x26campaignName="+escape(tm_campaignName);
 tm+="\x26ref="+escape(tm_ref.toLowerCase());
 tm+="\x26conversionName="+escape(tm_conversionName);
 pq = new Image();
 pq.src = page+tm;
}

