/**************************************/
/* (c) 2009 pro in space GmbH         */
/**************************************/


// Formular Effekte
function clearValue(thefield){
  if (thefield.defaultValue==thefield.value)
  thefield.value = "";
};
function addValue(thefield) {
  if (thefield.value == "")
  thefield.value = thefield.defaultValue;
};

var $j = jQuery.noConflict();

$j(document).ready(function() {

	$j("div.hide").attr("style","display: block");
	
	$j("div.mitarbeiter > div.vita").hide();
	
	$j("div.mid > p").hide();
	
	// Cursor setzen
	$j("div.switch > img").css("cursor","pointer");
	$j("span.teasernav > img").css("cursor","pointer");
	$j("span.listnav > img").css("cursor","pointer");
	$j(".trenner > a").css("cursor","pointer");
	$j("a.prev").css("cursor","pointer");
	$j("a.next").css("cursor","pointer");
	$j("a#copyBtn").css("cursor","pointer");
	
	/////// Teaser Startseite ////////////
	
	// Anzahl schreiben
	$j("div.pict").filter(function(length) {
		var len = $j("li", this).length;
		$j(this).parent().find("span.navlenght").text(len);
	});

	
	// in Teasern blättern
	function pict(p) {
		$j('#pict-'+p).jCarouselLite({
			btnPrev: '#teasernav-'+p+' .prev',
			btnNext: '#teasernav-'+p+' .next',
			circular: false,
			easing: "bounceout",
			speed: 1000,
			start: 0,
			visible: 1,
			mouseWheel: false,
			afterEnd: function(a) {
				$j(this).parent().next().children(".prev").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_la.gif");
				$j(this).parent().next().children(".next").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_ra.gif");
				$j(this).parent().next().children(".prev.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_li.gif");
				$j(this).parent().next().children(".next.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_ri.gif");
				$j(this).parent().next().children(".navindex").html(current+1);
			}
		});
	};

	function list(l) {
		$j('#list-'+l).jCarouselLite({
			btnPrev: '#listnav-'+l+' .prev',
			btnNext: '#listnav-'+l+' .next',
			circular: false,
			visible: 6,
			scroll:1,
			start: 0,
			vertical: true,
			mouseWheel: true,
			afterEnd: function(a) {
				$j(this).parent().next().children(".prev").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ta.gif");
				$j(this).parent().next().children(".next").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ba.gif");
				$j(this).parent().next().children(".prev.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ti.gif");
				$j(this).parent().next().children(".next.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_bi.gif");
			}
		});
	};

	$j('#edition').jCarouselLite({
		btnPrev: '#nav .prev',
		btnNext: '#nav .next',
		circular: false,
		visible: 4,
		scroll:1,
		start: 0,
		easing: "bounceout",
		speed: 1000,
		vertical: false,
		mouseWheel: false,
		afterEnd: function(a) {
			$j(this).parent().next().children(".prev").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_la.gif");
			$j(this).parent().next().children(".next").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_ra.gif");
			$j(this).parent().next().children(".prev.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_li.gif");
			$j(this).parent().next().children(".next.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_ri.gif");
		}
	});
    
	$j('.nt .view').jCarouselLite({
            btnPrev: '#listnav-news .prev',
			btnNext: '#listnav-news .next',
			circular: false,
			visible: 5,
			scroll:1,
			start: 0,
			vertical: true,
			mouseWheel: true,
			afterEnd: function(a) {
				$j(this).parent().next().children(".prev").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ta.gif");
				$j(this).parent().next().children(".next").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ba.gif");
				$j(this).parent().next().children(".prev.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_ti.gif");
				$j(this).parent().next().children(".next.disabled").find("img").attr("src","http://www.odette.senator.de/common/scripts/button/listnav_bi.gif");
			}
		});
	
	// Blätter-Button setzen
	if($j("div.pict > img:hidden")) {
		$j("div.view > span.teasernav").find("img:first").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_li.gif");
	} else {
		$j("div.view > span.teasernav").find("img:first").attr("src","http://www.odette.senator.de/common/scripts/button/teasernav_la.gif");
	};
	
	// Ansicht umschalten
	$j("div.switch > img").click(function() {
		pageTracker._trackPageview('/ajax/'+ window.location.pathname);
		if ($j(this).parent().next().find(".list").css("display") == "none") {
			$j(this).parent().find("img:first").attr("src", "http://www.odette.senator.de/common/scripts/button/view_npict.gif");
			$j(this).parent().find("img:last").attr("src", "http://www.odette.senator.de/common/scripts/button/view_list.gif");
			$j(this).parent().parent().find(".pict").fadeOut(500, function() {
				
				$j(this).parent().parent().find("div.list").fadeIn(500, function() {
				$j(this).parent().parent().find(".listnav").fadeIn(500);
				});
				$j(this).parent().parent().find(".teasernav").hide();
				$j(this).parent().parent().find("div.list").removeClass("hide");
				$j(this).parent().parent().find(".listnav").removeClass("hide");
			});
		} else {
			$j(this).parent().find("img:first").attr("src", "http://www.odette.senator.de/common/scripts/button/view_pict.gif");
			$j(this).parent().find("img:last").attr("src", "http://www.odette.senator.de/common/scripts/button/view_nlist.gif");
			$j(this).parent().parent().find("div.list").fadeOut(500, function() {
				$j(this).parent().parent().find(".pict").fadeIn(500, function() {
				$j(this).parent().parent().find(".teasernav").fadeIn(1000);
				});
				$j(this).parent().parent().find(".listnav").hide();
				$j(this).parent().parent().find(".listnav").addClass("hide");
				$j(this).parent().parent().find("div.list").addClass("hide");
			});
		};
	});
	
	/*	Schiebe-Teaser aufruf	*/
	function disp(divs) {
      var a = [];
      for (var i = 0; i < divs.length; i++) {
        a.push(divs[i].innerHTML);
	//	alert(a[i].toLowerCase().replace(/ /g, '-'));
		pict(''+a[i].toLowerCase().replace(/ /g, '-'));
		list(''+a[i].toLowerCase().replace(/ /g, '-'));
      }
    }
    
    disp( $j(".bt > h2").get() );
	
	
	// Alle Ausblenden
	$j("div.view > .hide").hide();
	
	// Sprachumschaltung
	$j("p.gb").hide();
	
	$j("#lang").find("a").click(function() {
		pageTracker._trackPageview('/ajax/'+ window.location.pathname);
		if ($j("div.zweispalter").find("p.gb").css("display") == "none") {
			$j("div.zweispalter").find("p.de").fadeOut(500,function(){
			$j("div.zweispalter").find("p.gb").fadeIn(500);
			});
		} else {
			$j("div.zweispalter").find("p.gb").fadeOut(500,function(){
			$j("div.zweispalter").find("p.de").fadeIn(500);
			});
		
		}
	});

	// Submenue auf und zufalten
	
	$j("#subnav_main").accordion({ 
	    active: '.activenode', 
	    autoHeight: false, 
	    navigation: true, 
	    event: 'mouseover', 
	    animated: 'easeslide'
	});

	
	// Unternehmensstruktur Zweige aufklappen
	$j("div.mid").hoverIntent(
      function () {
        $j(this).find("p").slideDown('slow');
      }, 
      function () {
        $j(this).find("p").slideUp('slow');
      }
    );

	
	
	// Infoboxen auf-zu-falten

	$j(".trenner").find("a").click(function() {
		pageTracker._trackPageview('/ajax/'+ window.location.pathname);
		
	if ($j(this).parent().prev(".vita").css("display") == "none") {
			$j(".vita").slideUp(500);
			$j(this).parent().prev(".vita").slideDown(500);
			// Icons und Bubbles neusetzen
			$j(this).parent().css("background","none");
			$j(this).parent().css("background","transparent url(http://www.odette.senator.de/common/scripts/css/aufbau/trenner_pfeil_rauf.gif) no-repeat scroll right bottom");
			$j(this).html("schließen");
		} else {
			$j(".vita").slideUp(500);
			// Icons und Bubbles neusetzen
			$j(this).parent().css("background","transparent url(http://www.odette.senator.de/common/scripts/css/aufbau/trenner_pfeil_runter.gif) no-repeat scroll right bottom");
			$j(this).html("mehr");
		}
	});


	// Slider in News-Liste - Startseite
	$j("#list-news a").hover(
      function () {
        $j(this).parent().addClass("act");
        $j(this).parent().siblings().removeClass("act");
      },
      function () {
      }
	);
	
	// Slider in Unternehmensnews-Liste - Startseite
	$j("#unews .list a").hover (
      function () {
				$j(this).parent().addClass("act");
        		$j(this).parent().siblings().removeClass("act");
				
				// ID des Text Feldes
				var theid = $j(this).parent().attr("id");
				
				// Daraus nur die Zahl extrahiert
				var activeno = theid.substr(theid.length - 1, 1);
							
				// Aktiviert das dazugehoerige Bild und deaktviert die anderen
				$j("#unews .pict #unews-img" + activeno).addClass("act");
				$j("#unews .pict #unews-img" + activeno).siblings().removeClass("act");
								
      },
      function () {
				
      }
	);

});
