//--------------------------------------------------------------------------------
// Carousel
//--------------------------------------------------------------------------------
 
if(window.loadFirebugConsole) {
	window.loadFirebugConsole(); 
}

var globalJcarouselObjTEST = "hallo";
var globalJcarouselObj = new Array();
var globalTimer = new Array();
var globalCarouselType = new Array();
var globalItem = new Array();


function displayTimeouts() {
	console.log(globalJcarouselObj);
}


function Ccarousel() {
		
		var obj_id = false;

		this.init = function (obj_id, obj, type){

			globalJcarouselObj[obj_id] = false;

			switch(type){
					case "large":	this.pages = $('#' + obj_id).find('.carouselTeaserList').find('.teaser').length;
												startNumber = Math.floor(Math.random()* this.pages ) + 1;
												this.actualPage = startNumber;
												scrollItems = 1;
												this.pages <= 1 ? animation = 0 : animation = 500;
												this.type = 'large';
												break;
					
					case "small":	this.pages = Math.ceil($('#' + obj_id).find('.carouselTeaserList').find('.teaser').length / 3);
												this.pages <= 1 ? animation = 0 : animation = 500;
												this.actualPage = 1;
												scrollItems = 3;
												this.type = 'large';
												break;
			}
			
			$('#' + obj_id).find('.mycarousel').jcarousel({
					start: this.actualPage,
					scroll: scrollItems,
					pages: this.pages,
					type: this.type,
					animation: animation,
					wrap: 'circular',
					itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
					itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
			}, obj_id);

			globalCarouselType[obj_id] = type;
		
			if(type == 'small')
				addItems(obj_id);

			//Seiten Icons setzen
			icons = '';
			for(var i = 1; i <= this.pages; i++) {
				icons += '<li>&nbsp;</li>'
			}
			
			$('#' + obj_id).find('ul.pageIcons').html(icons);
			
			setActive(this.actualPage, obj_id);
			
			pageCounter = "<span>" + this.actualPage + "/" + this.pages + "</span>";
			$("#" + obj_id).find('.pages').html(pageCounter);

			if(this.pages <= 1){
					$('#' + obj_id).find('.jcarousel-prev').addClass("prev-inactive");
					$('#' + obj_id).find('.jcarousel-next').addClass("next-inactive");
					$('#' + obj_id).find('.pageIcons').css('display', 'none');
			}
		} 

		function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){
				var idx = carousel.index(i, $('#' + carousel.obj_id).find('.carouselTeaserList').find('.teaser').length);
		    carousel.add(i, mycarousel_getItemHTML(idx, carousel.obj_id));
		}
			
		function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){
		    carousel.remove(i);
		}

		function addItems(obj_id) {
			itemCounter = $("#" + obj_id).find(".carouselTeaserList").find(".teaser").length%3; 

			if(this.itemCounter != 0){
				for(i = this.itemCounter; i<3; i++ ){
						  $('#' + obj_id).find(".carouselTeaserList").append("<div class='teaser'>&nbsp;</div>");
				}			
			}
		}
		
		
		function mycarousel_getItemHTML(item, obj_id){
				teaser = $('#' + obj_id).find('.carouselTeaserList').find('.teaser').get(item-1);
				return $(teaser).html();
		}


		function setActive(actualPage, obj_id) {
			$('#' + obj_id).find('ul.pageIcons').find('li').each(function(i){			
				if(actualPage == (i+1)) {  	
					$(this).attr('class', 'active');
				}
				else {
					$(this).attr('class', '');
				}
			});
		} 
}

var toggle = {
	speed: "normal", 
	init: function() {
		$(".toggleItemList").find("h2").click(function () {
			with( $(this).parent() ) {																							
				if ( hasClass("open") ) {
						find(".toggleContent").slideUp(toggle.speed, function () {
						removeClass("open");	
					});
				} else {
						find(".toggleContent").slideDown(toggle.speed, function () {
						addClass("open");	
					});
				}
			}
    });
		var openSection;
		var anchorOpen = false;
		if( openSection = window.location.hash ) {
			openSection = openSection.substring( 1, openSection.length );
			$(".toggleItemList").find("a.moreLess").each(function(i){																						
				if ( this.name == openSection ) {
					$(this).parent().parent().addClass("open");
					anchorOpen = true;
				} 
			});	
		}
		if( !anchorOpen ) {
			$(".toggleItemList > li:first-child").addClass("open");
		}		
	}
}
		  
/*---------------------------------------------------------------------------*/

$(document).ready(function(){

	toggle.init();
				   
	var ToBeHidden = /(ecke_|eckeblau_|large_bottom)/;	
	$("img").each(function(i){				   
		if(ToBeHidden.test(this.src)) {
			if(this.parentNode.nodeName !='A') {
				$(this).hide();
			} 
		}
	});
	
	var NoWrap = /(play.gif)/;
	$("img, input").each(function(i){				   
		if(NoWrap.test(this.src)) {
			this.parentNode.style.whiteSpace = 'nowrap'; 
		}
	});	
	

	$(".headingPrimary").each(function(i){				   
		$(this).wrapInner("<span class='gradient'></span>");
	});
	
	$("tr").each(function(i){				   
		$(this).removeAttr("bgColor");
	});
	
	
	
	obj = $('.hoverTable TR');
	
	obj.bind("mouseenter mouseleave", function(e){
        $(this).toggleClass("highLight");
    });	
	

	obj.bind("click", function(e) {
		myLink = $(this).find('a')[0];

		if(myLink.click) {
			myLink.click();
		} else {
			if(myLink.href) {
				if(myLink.target) {
					window[myLink.target] = window.open(myLink.href, myLink.target);
					window[myLink.target].focus();
				} else {
					window.location.href = myLink.href
				}
			}
		}
	
    });
	
	
	$('table.tci td:first-child,table.tci th:first-child').css("padding-left","7px");
	$('table.tci td:last-child,table.tci th:last-child').css("padding-right","7px");
	with($('table.tci')) {
		for(i=0; i<length; i++ ) {
			tableWidth = eq(i).parent().width() - 10;
			colAmount = eq(i).find('tr').eq(0).find('th').length;
			colWidth = 100/colAmount;
			colWidth += "%";
			eq(i).width(tableWidth); 
			eq(i).find('td').width(colWidth);
			eq(i).find('th').width(colWidth);	
		}
	}	

	
});

// ab hier altes Script:

// JavaScript-Library
// Projekt: tc-infonet.de
// (c)2003 denkwerk gmbh

//--------------------------------------------------------------------------------
// Umgebungsvariablen definieren
//--------------------------------------------------------------------------------

var ns = (document.layers)? true : false;
var ie = (document.all)? true : false;
var w3c = ((document.getElementById) && (!document.all))? true : false; // ie5 kennt getElementById auch

//Variablen je nach Browser und Version mit Werten belegen
var version = parseInt(navigator.appVersion);
var agent = navigator.userAgent.toLowerCase();

if ((agent.indexOf("compatible") == -1) && (version >= 5)) {
	//alert("Netscape 6");
	var obj = document.getElementById;
   	var styleObj = ".style";
   	var sichtbar = 'visible';
    var unsichtbar = 'hidden';

	}
if (agent.indexOf("msie") != -1) {
	//alert("IE");
	var obj = document.all;
   	var styleObj = ".style";
    var sichtbar ="visible";
    var unsichtbar = "hidden";

	}
if ((agent.indexOf("compatible") == -1) && (version < 5)) {
	//alert("Netscape 4");
	var obj = document.layers;
    var styleObj = "";
   	var sichtbar = "show";
    var unsichtbar = "hide";

}


//--------------------------------------------------------------------------------
// Öffnet Fenster mit freien Parametern
//--------------------------------------------------------------------------------

function openPopup(theURL, winName, features) {
  a=window.open(theURL,winName,features);
  a.focus();
  return false;
}



//--------------------------------------------------------------------------------
// Öffnet neues Content-Fenster und plaziert dieses in der Bildschirmmitte
//--------------------------------------------------------------------------------

function openTCPopup(url, w, h){

var parameter = 'width='+w+',height='+h+',left='+eval((screen.width-w)/2)+',top=50,scrollbars=1,resizable=no,location=no,menubar=no,toolbar=no';


if (self.window.name != "popupOK" ) {
	self.window.name == "popupOK"
	thomascookwin = window.open(url,'thomascook',parameter);
	window.thomascookwin.focus();
	}
else {
	if (window.thomascookwin.closed == true) {
		thomascookwin = window.open(url,'thomascook',parameter);
		window.thomascookwin.focus();
		}
	else {
		window.thomascookwin.location.href=url;
		window.thomascookwin.resizeTo(w,h);
		window.thomascookwin.focus();
		}
	}
}

function openTCPopupNoScrollbar(url, w, h){

var parameter = 'width='+w+',height='+h+',left='+eval((screen.width-w)/2)+',top=50,scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no';


if (self.window.name != "popupOK" ) {
	self.window.name == "popupOK"
	thomascookwin = window.open(url,'thomascook',parameter);
	window.thomascookwin.focus();
	}
else {
	if (window.thomascookwin.closed == true) {
		thomascookwin = window.open(url,'thomascook',parameter);
		window.thomascookwin.focus();
		}
	else {
		window.thomascookwin.location.href=url;
		window.thomascookwin.resizeTo(w,h);
		window.thomascookwin.focus();
		}
	}
}


//--------------------------------------------------------------------------------
// Druckt aktuelle Seite
//--------------------------------------------------------------------------------

function printText()
{
 if ((!ns) && (!w3c))
 {
  // Focus auf den Frame lenken welcher gedruckt werden soll
  window.focus();
  // BrowserObject ,,Print Box,, anlegen
  var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box
  WebBrowser1.outerHTML = "";
 }
 else
 {
  window.print();
 }
}


//--------------------------------------------------------------------------------
// Layer schieben
//--------------------------------------------------------------------------------

function thisClient(){
	this.ns = (document.layers)? true : false;
	this.w3c = (document.getElementById) ? true : false;
	this.ms = (document.all)&& (!this.w3c) ? true : false;
}

var nav = new thisClient(); // initialize browser object




/* constructor function for cross-browser layer (ns4,6, msie > 4) */
function myDiv(id,top,left,zI,isNested){
	this.id = id;
	this.isNested = isNested;

	/* get the browser pointer*/
	if (nav.ns){
		if (this.isNested) {
			this.css = document.layers['container'].document.layers[id];
			this.doc = document.layers['container'].document.layers[id].document;
		} else {
			this.css = document.layers[id];
			this.doc = document.layers[id].document;
		}
	}

	else if (nav.ms) this.css = document.all[id].style;
	else if (nav.w3c) this.css = document.getElementById(id).style;

	if (nav.ms) this.doc = document.all[id];
	if (nav.w3c) this.doc = document.getElementById(id);

	this.contentHeight;
	this.isActive = false;
	this.ActiveIndex = 0;

		/* have the browser point to the right attributes */

		this.css.top = top;
		this.css.left = left;
		this.css.zIndex = zI;
		if (nav.ns || nav.w3c){ this.x = this.css.left; this.y = this.css.top; }
		else if (nav.ms){   this.x = this.css.pixelLeft; this.y = this.css.pixelTop; }

		this.getContentHeight = getContentHeight;
		this.swapVis = swapVis;
		this.moveTo = moveTo;
		this.moveBy = moveBy;
		this.getX = getX;
		this.getY = getY;
		this.getVisibility = getVisibility;
		this.getName = getName;
}

/** verschiebt den Layer im koordinatensystem zur Position x/y*/
function moveTo(x,y){
	this.x = x;
	this.y = y;
	this.css.left = x;
	this.css.top = y;
}

/** verschiebt den Layer im koordinatensystem  um x/y px */
function moveBy(x,y){
	this.x = x;
	this.y = y;

	if (nav.ns){
		this.css.top += this.y;
		this.css.left += this.x;
	} else {
		this.css.top = parseInt(this.css.top) + this.y +'px';
		this.css.left = parseInt(this.css.left) + this.x +'px';
	}
}

/** ändert die Sichtbarkeit */
function swapVis(bol){
	if (nav.ns) visibility = (bol)? "show" : "hide";
	else visibility = (bol)? "visible" : "hidden";
	this.css.visibility = visibility;
}

/** errechnet die Höhe des Layers */
function getContentHeight(){
		if (nav.ns)	return this.contentHeight = this.css.clip.height;
		else if (nav.w3c) return this.contentHeight = document.getElementsByTagName('div')[this.id].offsetHeight;
		else if (nav.ms) return this.contentHeight = document.all[this.id].scrollHeight;//offsetHeight;
}

/** holt die Position auf der x-Achse */
function getX(){
 	if (arguments.length > 0) return parseInt(this.css.left) + arguments[0];
	else return parseInt(this.css.left);

 }
/** holt die Position auf der y-Achse */
function getY(){
	if (arguments.length > 0) return parseInt(this.css.top) + arguments[0];
	else return parseInt(this.css.top);
}

/** erfragt die Sichtbarkeit */
function getVisibility(){
	return this.css.visibility;
}

/** erfragt den Namen/Id */
function getName(){
	return this.id;
}



//--------------------------------------------------------------------------------
// Flash-Detection
//--------------------------------------------------------------------------------

var opSystem = navigator.platform;
var isIE = false;
var theBrowserString = (document.all && navigator.userAgent.indexOf("MSIE") > -1)? "isLoaded=false&" : "isLoaded=false&";

function checkFlash(inRequiredVersion){
  theVersionFlag = false;

  if(navigator.plugins != null && navigator.plugins.length > 0) {
    var thePlugin = navigator.plugins['Shockwave Flash'];

    if(typeof thePlugin == 'object') {
      var theVersion = thePlugin.description.split(' ')[2];

      theVersionFlag = theVersion >= inRequiredVersion;
    }
  }
  else if(navigator.userAgent
    && navigator.userAgent.indexOf("MSIE") > -1
    && navigator.userAgent.indexOf("Windows") > -1
    && navigator.userAgent.indexOf("Windows 3") < 0
    && document.all
    && !window.opera) {
      isIE = true;
	document.write('<scr'+'ipt language=VBScript>\n ');
	document.write('intCurVersion = 10\nwhichVersion = ' + inRequiredVersion + '\n');
	document.write('Do\nOn Error Resume Next\n');
	document.write('theVersionFlag = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & intCurVersion)))\n');
	document.write('If theVersionFlag = true Then Exit Do\n');
	document.write('intCurVersion = intCurVersion - 1\n');
	document.write('Loop While intCurVersion >= whichVersion\n');
	document.write('</scr'+'ipt>');
  }
  if (opSystem.substring(0,5) == "Linux") theVersionFlag = false;
  return theVersionFlag;
}
