
/**
* Switch to the URL of the selected Item in the Dropdown-Menu
*/
function go2url(formEl){
 if (formEl.options[formEl.selectedIndex].value != "none") {
	document.location.href = formEl.options[formEl.selectedIndex].value
 }                       
}

function addBookmark(){

  URL = window.location.href;
  Text = document.title;

  if (window.sidebar)
    {
    // firefox
    window.sidebar.addPanel(Text,URL, "");
    }
  else if(window.opera && window.print)
    {
    // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',URL);
    elem.setAttribute('title',Text);
    elem.setAttribute('rel','sidebar');
    elem.click();
    }
  else if(document.all)
    {
    // ie
    window.external.AddFavorite(URL,Text);
    }
    
   return false;
}


/**
* Dokument fertig geladen => mach so einige Fixes
*/
jQuery(document).ready(function($) {
	/**
	* Setzt den Content unterhalb der Mini-IBE richtig
	*/
	function setContentAfterIBE() {
		var marginTop = 0;
		if($('#mood').height() == 0 && $("#mood").html()!="")  {
			// Peelscript  => etwas h�her setzen
			$(".tx-bnmibe-pi1").css("margin-top", "-60px");
		}
		else if($('#mood').height() > 0 && $("#mood").html()!="") {
			// Moodbild  => noch etwas h�her setzen
			$(".tx-bnmibe-pi1").css("margin-top", "-80px");
		}
			
		
	}
	// $(document).pngFix();
	
	// IBE richtig platzieren
	//setContentAfterIBE();

	// Bilder in Box
	// Wenn kleines Bild bei breiter box => rahmen links, damit text nicht so dicht dran liegt
	$(".frame-content-wrapper").each(function (i) {
    	if($(this).width() > $(this).find(".box-image").width()+5) {
    		$(this).find(".box-image").css("border-left", "5px solid #fff");
    	}
    });
	
	// Boxen-Höhe abgleichen
	$(".subcolumns").each(function(i) {
		var heightLeft = $(this).find(".c50l .frame-content-text").height()+$(this).find(".c50l .frame-content-link").height();
		var heightRight = $(this).find(".c50r .frame-content-text").height()+$(this).find(".c50r .frame-content-link").height();
		var textHeightLeft = $(this).find(".c50l .frame-content-text").height() + 'px';
		var linkHeightLeft = $(this).find(".c50r .frame-content-link").height() + 'px';
		var textHeightRight = $(this).find(".c50r .frame-content-text").height() + 'px';
		var linkHeightRight = $(this).find(".c50r .frame-content-link").height() + 'px';
		if(heightLeft > heightRight) {
			if($.browser.msie && $.browser.version<"8.0") {	
				// ie-hack, da nach setzen einer explitieten Höhe der ie6 das Textfeld anders positioniert
				$(this).find(".c50r .frame-content-text").css("height", $(this).find(".c50l .frame-content-text").height()-$(this).find(".c50r .box-image").height()-5);
				$(this).find(".c50r .frame-content-link").css("height", $(this).find(".c50l .frame-content-link").height());
			}
			else {
				$(this).find(".c50r .frame-content-text").css("height", textHeightLeft);
				$(this).find(".c50r .frame-content-link").css("height", linkHeightLeft);
			}				
		}
		else if(heightLeft < heightRight) {
			if($.browser.msie && $.browser.version<"8.0") {
				// ie-hack, da nach setzen einer explitieten Höhe der ie6 das Textfeld anders positioniert
				$(this).find(".c50l .frame-content-text").css("height", $(this).find(".c50r .frame-content-text").height()-$(this).find(".c50l .box-image").height()-5);
				$(this).find(".c50l .frame-content-link").css("height", $(this).find(".c50r .frame-content-link").height());
			}
			else {
				$(this).find(".c50l .frame-content-text").css("height", textHeightRight);
				$(this).find(".c50l .frame-content-link").css("height", linkHeightLeft);
			}
		}
	});
	
/*****Browserweiche Start ***********/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{
			string: navigator.appName,
			subString: "Opera",
			identity: "Opera"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	]

};

BrowserDetect.init();
var isOldBrowser = false;
var b = BrowserDetect.browser;
var v = parseFloat(BrowserDetect.version);
	if((b == 'Explorer' && v < 8) || (b == 'Firefox' && v <= 3) || (b == 'Chrome' && v < 9) || (b == 'Netscape' && v < 9)|| (b == 'Opera' && v < 9))
		isOldBrowser = true;
if(isOldBrowser == true){
	$('#browserInfoContainer').lightbox_me({
            	closeSelector: '#noUpdate'
	});
}
/*****Browserweiche Ende ***********/
	//empty inputs
	$('.tx-powermail-pi1').find('input:text').each(function(){
      		$(this).val('');
  	});
	
});



/**jquery tooltip**/

$.fn.tooltip = function(optionen, inhalt){
	optionen = $.extend({
		hintergrund: "#000000",
		schriftfarbe: "#FFFFFF",
		rand: "1px solid #0083AA",
		eckenradius: 10,
		zeit: 300
	}, optionen);
 
	function zeigeTooltip(evt, zeit, id){
		$("<div>", {
			id: "tooltip",
			css: {
				position: "absolute",
				left: evt.pageX + 20,
				top: 400,
				padding: "10px",
				background: optionen.hintergrund,
				color: optionen.schriftfarbe,
				fontFamily: "Tahoma, Helvetica, sans-serif",
				fontSize: "12px",
				border: optionen.rand,
				display: "none",
				"-moz-border-radius": optionen.eckenradius,
				"-webkit-border-radius": optionen.eckenradius
			},
			html: inhalt["inhalt"][0][id]
		})
		.appendTo("body")
		.fadeIn(zeit);
	}
	function zeigeTooltip(evt, zeit, id){
		$("<dl>", {
			id: "tooltip",
			css: {
				position: "absolute",
				left: evt.pageX + 20,
				top: evt.pageY- 200,
				padding: "10px",
				background: optionen.hintergrund,
				color: optionen.schriftfarbe,
				fontFamily: "Tahoma, Helvetica, sans-serif",
				fontSize: "12px",
				border: optionen.rand,
				display: "none",
				"-moz-border-radius": optionen.eckenradius,
				"-webkit-border-radius": optionen.eckenradius
			},
			html: inhalt["inhalt"][0][id]
		})
		.appendTo("body")
		.fadeIn(zeit);
	}
 
	$(this).each(function(){
		var id = $(this).attr("id");
		$(this).attr("title", "");
		$(this).bind({
			mouseenter: function(evt){
				if ($("#tooltip").css("opacity") != 0) {
					$("#tooltip").stop().remove();
				}
 
				zeigeTooltip(evt, optionen.zeit, id);
			},
			mouseleave: function(){
				$("#tooltip").fadeOut(
					optionen.zeit,
					function(){
						$(this).remove();
					}
				);
			},
			mousemove: function(evt){
				$("#tooltip").css({
					left: evt.pageX + 20,
					top: $("#tooltip").css("height")  +50
				});
			}
		});
	});
}

function slideShow(speed) {


	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><a class="slideshow-caption-container" src=""><h3></h3><p></p></a></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0}).addClass('show');
	var theHref = $('ul.slideshow .slideshow-link:first').attr('href');
//	console.log('theHref be with you ' + theHref);
	$('ul.slideshow .slideshow-caption-container:first').attr('href', theHref);
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow li.show').find('.caption-header').text());
	$('#slideshow-caption p').html($('ul.slideshow li.show').find('.caption-text').text());
		
	//Display the caption
	setTimeout(function(){
	$('#slideshow-caption').css({opacity: 0.7, bottom:'-80px'});
	$('#slideshow-caption').animate({bottom:'0'},1000);
	}, 6000);
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	/*
		$('ul.slideshow').bind('mouseenter',function(){
		clearInterval(timer);	
	}).bind('mouseleave', function(){
		timer = setInterval('gallery()',speed);			
	});
	
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);*/
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
	
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {	
	
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
			
		//Get next image caption
		var title = next.find('.caption-header').text();	
		var desc = next.find('.caption-text').text();	
		var theHref = next.find('.slideshow-link').attr('href');
	
		//Set the fade in effect for the next image, show class has higher z-index
		
		//Hide the caption first, and then set and display the caption
		$('#slideshow-caption').slideUp({
			duration:1000,
			easing: 'linear', complete: function () { 
				next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 2000);
				$('#slideshow-caption h3').html(title); 
//				console.log('setting href ' + title);
				$('#slideshow-caption p').html(desc); 
				$('#slideshow-caption .slideshow-caption-container:first').attr('src', theHref);
				setTimeout(function(){$('#slideshow-caption').slideDown(1000, 'linear'); },5000);
			
				current.animate({opacity: 0.0}, 2000).removeClass('show');
			}
		});		
		//Hide the current image
		
	}

}
$(document).ready(function() {
	$(".tooltiptext").each( function(){		
		$(this).hide();
		 $('#tool1').html();
	});	
	
	// Plugin-Aufruf
	
	if( $('.tooltiptext').length >0){
		$(".csc-textpic-image").tooltip({
			hintergrund: "#ffffff",
			schriftfarbe: "#4F4F4F",
			rand: "1px solid #0083AA",
			eckenradius: 0,
			zeit: 400
		}, {
			"inhalt": [{
				//"" + $('.csc-textpic-imagewrap ul li').attr("id")+ "": "test"+ $('.csc-textpic-imagewrap ul li').attr("id")+""
				"id0": $('#tool1').html(),		
				"id1": $('#tool2').html(),
				"id2": $('#tool3').html(),
				"id3": $('#tool4').html(),
				"id4": $('#tool5').html(),
				"id5": $('#tool6').html(),
				"id6": $('#tool7').html(),
				"id7": $('#tool8').html(),
				"id8": $('#tool9').html(),
				"id9": $('#tool10').html(),
				"id10": $('#tool11').html(),
				"id11": $('#tool12').html(),
				"id12": $('#tool13').html()		
			}]
		});
	}
	if($('.slideshow').length > 0) {
		//Execute the slideShow, set 20 seconds for each images
		slideShow(20000);
	}
});

 

