/*CVS Add-ins*/
/*
$Revision: 1.30 $
$RCSfile: behaviour.js,v $
author: JDE
*/

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/*
    behaviour.js 
    16.06.2008 JDE
*/
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/*Copyright (c) A&B FACE2NET GmbH*/

function check(){ alert("JS eingebunden"); }

var agt = navigator.userAgent.toLowerCase();
var mac_ff  = ( (agt.indexOf("firefox") != -1) && (agt.indexOf("macintosh") != -1) );
var hrefblocker = false;


/**
* preloading background images
*/
var a = new Array( "bg_argument.gif","bg_context.gif","bg_direct.gif","bg_footer.gif","icons_list.gif","icons_links.gif","icons_galerie.gif","bg_greyshadows.gif","bg_header.gif","bg_imageboxSpecial.gif","bg_imageboxSpecial_ie.gif","bg_imageboxSpecial_blue.gif","bg_main_blueborder.gif","bg_main_redborder.gif","bg_mitmachen.gif","bg_mitmachen_active.gif","bg_nav_headline.gif","bg_nav_icons.gif","bg_nav_rightCol_a.gif","bg_nav_rightCol_ah.gif","bg_nav_rightCol_li.gif","bg_presse.gif","bg_quote.gif","bg_redshadows.gif","bg_redshadows_special.gif","bg_tv.gif","icon_nav_headline.gif","icons_contentService.gif","icons_galerie.gif","icons_links.gif","icons_list.gif","logo_facebook_hover.png","logo_flickr_hover.gif","logo_youtube_hover.gif" );
var b = new Array();
var i;
for (i = 0; i < a.length; i++) {
  b[i] = new Image();
  b[i].src = '/_system/css/styleimages/' + a[i];
}


/**
* show or hide value in formelements 
*/
function initiate_formbehaviour(){
  if($("html").attr("lang")=="de") var inputtxt = ' Suchbegriff ';
	else var inputtxt = ' search term ';
	$("#header input.formElement")
		.attr("tabindex", "1")
		.focus(function(){ if(this.value == inputtxt)this.value = ''; })
    .blur(function(){ if(this.value == '')this.value = inputtxt; })  
}

function create_printLink(){
  if($("html").attr("lang") == "de") var printtxt = "drucken";
	else var printtxt = "print";
	$('<li id="contentService_printLink"><a href="javascript:window.print()" title="öffnet den Druckdialog des Browsers">'+printtxt +'</a></li>').prependTo("#contentService .contentService_links ul");

}

function create_printLink2(){
  if($("html").attr("lang") == "de") var printtxt = "drucken";
	else var printtxt = "print";
	$("#contentService .contentService_links").append('<ul><li id="contentService_printLink"><a href="javascript:window.print()" title="öffnet den Druckdialog des Browsers">'+printtxt +'</a></li></ul>');
}

function create_recommendLink(){
  if($("html").attr("lang") == "de") { var recommendtxt = "versenden"; var recommend2txt = "versendet"; }
	else{ var recommendtxt = "send"; var recommend2txt = "sent"; }
	
	if(document.getElementById("recommend") && $("*").index( $('#recommend .error')[0] ) < 0){
		$('<li class="send"><a href="#recommend">'+recommendtxt+'</a></li>').appendTo("#contentService .contentService_links ul");
		$('#recommend').toggleClass("none");
		$("#contentService .contentService_links ul li.send")
			.click(function(){ 
				 toggleBox("#recommend");
				 toggleActive("#contentService .contentService_links ul li.send a");		
		});
	}else if(document.getElementById("newsletter")){
	  $('<li class="send"><strong>'+recommend2txt+'</strong></li>').appendTo("#contentService .contentService_links ul");
	}else if($("*").index( $('#recommend .error')[0] ) > 0){
	  $('<li class="send"><a href="#recommend">'+recommendtxt+'</a></li>').appendTo("#contentService .contentService_links ul");
		$("#contentService .contentService_links ul li.send")
			.click(function(){ 
				 toggleBox("#recommend");
				 toggleActive("#contentService .contentService_links ul li.send a");		
		});
	}
}

function create_tagBoxLink(){
	if(document.getElementById("themes")){
	  $("#content .tagliste div").attr("id", "themenliste");
		$("#content .tagliste h2").append('<span id="mehr_themen"></span>');
	  $("#content .tagliste #themes").wrap('<a class="closed" href="#mehr_themen"></a>');
		$('div#themenliste').toggleClass("none");
                $('div.tagliste').toggleClass("tagfooter");
		$("#content .tagliste h2 strong a.closed")
			.click(function(){ 
				 toggleBox("#themenliste");
                                 $('div.tagliste').toggleClass("tagfooter");
	       toggleLink("#content .tagliste h2 strong");
				 return false;
		  });		
		
	}
}

function toggleBox(content){
	$(content).slideToggle("slow",function(){
				$(content).toggleClass("none");
	});
}

function toggleActive(content){
	$(content).toggleClass("active");	
}

function toggleLink(content){
	$(content+" a.closed").remove();
	$(content).prepend('<span id="themes">Mehr Themen</span>');	
}

/*editierte Contentlinks*/

function get_target(t_url){
  var args = 'width=597,height=440,resizable,scrollbars'; 
  ok = window.open(t_url,'',args);
  if (ok) return false;
  else return true;
}

function get_target2(t_url, t_width, t_height){
  var args = 'width='+t_width+',height='+t_height+',resizable,scrollbars'; 
  ok = window.open(t_url,'',args);
  if (ok) return false;
  else return true;
}



/* argumentebox */
function toggle_arguments(){
	if(document.getElementById("argumenteList")){
		$("#argumenteList li:not(:first)").toggleClass("hide");
		$("#argumenteList li:first").toggleClass("show");
		$("#argumenteList li.hide").each(function () {
				var currentID = "'"+$(this).attr("id")+"'";
				$(this).children("h3").wrapInner('<a href="javascript: argument_anzeigen('+currentID+')"></a>');
		});
	}
}

function argument_anzeigen(nextID){
	var currentID = "'"+$("#argumenteList li.show").attr("id")+"'";
	$("#argumenteList li.show").toggleClass("hide");
	$("#argumenteList li.show h3").wrapInner('<a href="javascript: argument_anzeigen('+currentID+')"></a>');
	$("#argumenteList li").removeClass("show").removeClass("last");
	$("#argumenteList li#"+nextID).removeClass("hide").toggleClass("show");
	$("#argumenteList li:last#"+nextID).toggleClass("last");
	$("#argumenteList li#"+nextID+" h3 a").replaceWith($("#argumenteList li#"+nextID+" h3 a").text());

}

function map_behaviour(){
  if(document.getElementById("gmap")){

    if(document.getElementById('header')) {
      var t_url= 'map.html';
      var t_height = 940;
      var t_width = 834;
      if(screen.height < 1000) t_height = screen.height - 100;
      if(screen.width < 850) t_width = screen.width - 20;
      var suffix = '';
      suffix = $('#content .summertour').attr('id');
      if(0 < suffix.length){ t_url = t_url.concat('?tour='+suffix); }
      $('.special .maximumContent .summertour .open_gmap')
        .attr('id', 'open_gmap')
        .append('<a target="_blank" title="öffnet in neuem Fenster" href="'+t_url+'" onclick="karte_vergroessern(\''+t_width+'px\',\''+t_height+'px\',\''+t_url+'\'); return hrefblocker;">vergrößern</a>');
    }else{
      if(null != window.opener) $('#google_popup #content').prepend('<span class="close" ><a href="javascript:window.close();">Fenster schließen</a></span>')
    }
  }
}

function karte_vergroessern(t_width, t_height, t_url){
  hrefblocker = get_target2(t_url, t_width, t_height);
}


/* ***** click tracker functions start ***** */

/* etracker code start*/

var toSleep = true; function stopTimer(){toSleep=false;}
function clickTracker(link,LinkName){var secureID="TysP23";
//var redirectUrl="http://www.etracker.de/skin/de.def/img/1px.gif";
var redirectUrl=link;
etrackerSink=new Image(1,1);toSleep=true;
etrackerSink.src="http://www.etracker.de/lnkcnt.php?et="+secureID+"&url="+
redirectUrl+"&lnkname="+LinkName;etrackerSink.onload=stopTimer;if(toSleep==true)
{maxDelay(500);}return true;}function maxDelay(gap){var then,now;then=new
Date().getTime();now=then; while( toSleep==true&&(now-then)<gap){now=new Date().
getTime();}}

/* etracker code end */


function searchTracker(linkname) {
 var redirectUrl = "http://www.etracker.de/skin/de.def/img/1px.gif";
 clickTracker(redirectUrl,linkname); 
}

function writeEtrackerLink() {
   if( isLive() ) {
	$("#content a.externerlink").each(function() {
		//var atext = $(this).text();
		var ahref = $(this).attr("href");
		var eturl = 'http://www.etracker.de/lnkcnt.php?et=TysP23&url=';
		eturl    += ahref;
		eturl    += '&title=&lnkname=';
		eturl    += 'content--'+ahref;
		$(this).attr('href', eturl);                
	});
   }
}

/* ***** click tracker functions end ***** */

function isLive() {
  if( window.location.hostname.slice(0,3)=='cms' )
     return false;
  return true;
}


//addLoadEvent(create_printLink);
addLoadEvent(create_printLink2);
addLoadEvent(create_recommendLink);
addLoadEvent(create_tagBoxLink);
addLoadEvent(initiate_formbehaviour);
addLoadEvent(toggle_arguments);
addLoadEvent(map_behaviour);
//addLoadEvent(writeEtrackerLink);