// Script by http://wadny.com/news/during/2004/1/29/1707/
function setExternalLinks() {
	if (!document.getElementsByTagName) {
		return null;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i=0;i < anchors.length;i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.className == "neues_fenster")) {
			anchor.setAttribute("target", "blank");
		}
	}
	var maps = document.getElementsByTagName("area");
	for (var i=0;i < maps.length;i++) {
		var map = maps[i];
		if (map.getAttribute("href") && map.className == "external-link-new-window") {
			map.setAttribute("target", "blank");
		}
	}
}

function changePic(picID, action, newfile) {
	if (action == "over") {
		$jQ("#link-"+picID+" img").attr("src", "fileadmin/templates/images/galerie-thumbs-mo/"+picID+"th-mo.jpg");
	}
	if (action == "out") {
		$jQ("#link-"+picID+" img").attr("src", "typo3temp/pics/"+newfile);
	}
}

var $jQ = jQuery.noConflict();
var seconds = new Array(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1);

$jQ(document).ready(function(){
	
	// Init marquee
	// Get the content of the newsticker
	var news = $jQ('div#newsticker p.bodytext').html();

	// Wrap it
	news = '<marquee behavior="scroll" direction="left" scrollamount="1" width="520"><p>'+news+'</p></marquee>';
	// Insert it again
	$jQ('div#newsticker').html(news);
	
	// Add effect
	$jQ('marquee').marquee().mouseover(function () {
			$jQ(this).trigger('stop');
	}).mouseout(function () {
			$jQ(this).trigger('start');
	});
	
	// Init countdown
	$jQ(function () {
    $jQ('#countdown-inner').countdown({since: new Date(2010,4,1,0,0,0), format: 'DHM'});
  });
	
	// Links next to image map
	var freezedMap = '-Allgemein';
	var areasToDisable = new Array();
	var curLang = $jQ('div.tx-tmimagemap-pi1 img').attr("rel");
	areasToDisable[0] = [ 2, 3, 6 ];
	areasToDisable[1] = [ 1, 4 ];
	areasToDisable[2] = [  ];
	areasToDisable[3] = [  ];
	
	if ($jQ('ul.partnerlegende').length > 0) {
		$jQ("ul.partnerlegende li:last").hide();
		
		// Copy all the maps elements
		$jQ("area").clone().appendTo(".tx-tmimagemap-pi1");
		
		// Iterate through the list navigation
		$jQ("ul.partnerlegende li").each(function (i, el) {
			$jQ(this).addClass("li"+i);
			
			/*$jQ(this).click(function () {
				
			});*/
			
			$jQ(this).mouseover(function () {
				/*$jQ("div.tx-tmimagemap-pi1 img").attr({ 
					src: "fileadmin/templates/images/maps/Karte"+i+".jpg"
				});
				*/
				
				// Change map image
				$jQ("div.tx-tmimagemap-pi1 img").attr({ 
					src: "fileadmin/templates/images/maps/"+curLang+"/Karte"+i+".jpg"
				});
				// Reset old activated element
				if ($jQ("ul.partnerlegende li.li"+freezedMap).length > 0) {
					$jQ("ul.partnerlegende li.li"+freezedMap).find("a").css("text-decoration","none");
				}
				// Enable all map areas
				$jQ("map").html("");
				$jQ("div.tx-tmimagemap-pi1 area").not("map area").each(function (i, el) {
					$jQ(this).clone().appendTo("map");
				});
				// Disable all unused areas
				$jQ.each(areasToDisable[i], function() {	
					$jQ("div.tx-tmimagemap-pi1 map area.area"+this).remove();
				});
				$jQ(this).find("a").css("text-decoration","underline");
				// Save old element
				freezedMap = i;
				return false;
			});
			
			/*$jQ(this).mouseout(function () {
				if (freezedMap != i) {
					$jQ("div.tx-tmimagemap-pi1 img").attr({ 
						src: "fileadmin/templates/images/maps/Karte"+freezedMap+".jpg"
					});
					//$jQ(this).css("text-decoration","none");
				}
			});*/
			
			/*$jQ("body").click(function () {
				$jQ("div.tx-tmimagemap-pi1 img").attr({ 
					src: "fileadmin/templates/images/maps/Karte-Allgemein.jpg"
				});
				if ($jQ("ul.partnerlegende li.li"+freezedMap).length > 0) {
					$jQ("ul.partnerlegende li.li"+freezedMap).css("text-decoration","none");
				}
				freezedMap = '-Allgemein';
				return false;
			});*/
			
		});
		
		$jQ(".tx-tmimagemap-pi1").append('<div style="display:none;" id="hiddenmaps"></div>');
		$jQ("#hiddenmaps").html('<img src="fileadmin/templates/images/maps/'+curLang+'/Karte0.jpg"/>');
		$jQ("#hiddenmaps").html('<img src="fileadmin/templates/images/maps/'+curLang+'/Karte1.jpg"/>');
		$jQ("#hiddenmaps").html('<img src="fileadmin/templates/images/maps/'+curLang+'/Karte2.jpg"/>');
	}
	
	// Set links with class="neues_fenster" or rel="external" to open in a new window
	setExternalLinks();
});
