
/**
 * jQuery in den Kompatibiltätsmodus versetzen.
 * Wichtig, da sonst Konflikte mit anderen JS-Libs
 * wie z.B. Prototype für die EXT:powermail.
 *
 * Die Variable muß vor jede jQery-Anweisung gesetzt werden.
 * Anstatt $(... ist $jQ(... zu notieren.
 * Quelle: http://www.typo3forum.net/forum/powermail/30411-jquery-powermail-rgslideshow-vertragen.html
 */
var $jQ = jQuery.noConflict();

$jQ(function () {
    // basic version is: $('div.demo marquee').marquee() - but we're doing some sexy extras

    $jQ('MARQUEE.homeNewsticker').marquee('pointer').mouseover(function () {
        $jQ(this).trigger('stop');
    }).mouseout(function () {
        $jQ(this).trigger('start');
    }).mousemove(function (event) {
        if ($jQ(this).data('drag') == true) {
            this.scrollLeft = $jQ(this).data('scrollX') + ($jQ(this).data('x') - event.clientX);
        }
    }).mousedown(function (event) {
        $jQ(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $jQ(this).data('drag', false);
    });
});


$jQ(document).ready(function() {
	$jQ(".boxCarouselLite .jCarouselLite").jCarouselLite({
	    btnNext: ".boxCarouselLite .carouselNext",
	    btnPrev: ".boxCarouselLite .carouselPrev",
		visible: 5,
		scroll: 5,
		mouseWheel: true,
		speed: 500,
   		easing: "easeinout"
	});
});

/**
 * Ein Lupen-Icon NUR an die Bilder anfügen, die per Click vergrößert werden können.
 * Zur Identifikation wird die REL-Eigenschaft 'magnifier' verwendet,
 * die in der 'user_parseFunc.php' als Erweiterung des Strings
 * 'onclick="openPicExt' -> 'rel="magnifier" onclick="openPicExt' verwendet wird.
 */
$jQ(document).ready(function() {
	$jQ('.csc-textpic-image dt a[rel="magnifier"]').append('<img src="fileadmin/sco-berlin.de/system/medias/icons/icon-magnifier.png" border="0" class="iconIndicateZoom" />');
	$jQ('.csc-textpic-image dt a .iconIndicateZoom').css('opacity', 0.4);
	$jQ('.csc-textpic-image dt a').hover(
		function () {
	  		$jQ('.csc-textpic-image dt a .iconIndicateZoom').css("opacity", "1");
		},
		function () {
			$jQ('.csc-textpic-image dt a .iconIndicateZoom').css("opacity", 0.4);
		}
    );
});


// Replacement for the openPic-Function:
function openPicExt(url, winName, winParams){
	/**
	 * Den PopUp-Url in seine einzelnen GET-Parameter zerlegen.
	 */
	HTTP_GET_VARS = new Array();
	strGET = url;
	if (strGET != '') {
		gArr = strGET.split('&');
		for (i = 0; i < gArr.length; ++i) {
			v = '';
			vArr = gArr[i].split('=');
			if (vArr.length > 1) {
				v = vArr[1];
			}
			HTTP_GET_VARS[unescape(vArr[0])] = unescape(v);
		}
	}
	/**
	 * Auslesen des Image-Titles.
	 * Da der PopUp-Url NICHT den Title per GET enthält, alle Links der
	 * Seite duchsuchen. Der Link, der den gleichen Href enthält,
	 * enthält auch den gesuchten Image-Title.
	 */
	imageLinkTitle = '';
	for (var linkNum = 0; linkNum < document.links.length; linkNum++) {	// Alle Links durchlaufen.
		var link = document.links[linkNum];								// Href holen.
		if( link.href.indexOf(url) > -1 ){								// Ist der url in dem Href enthalten?
			if (link.title) { 											// Title vorhanden?
				var imageLinkTitle = link.title; 						// Ja: Dann holen de Title des Links.
				linkNum = document.links.length; 						// Schleife abbrechen.
			}
		}
	}
	/**
	 * Bildbox aufrufen.
	 */
	var imgSrc = GET(HTTP_GET_VARS,"file");								// Image-Src aus PopUp-Url holen.
	$jQ.fn.colorbox({
		href:imgSrc,
		transition: 'elastic',
		opacity: 0.5,
		speed: 700,
		initialWidth: '184px',
		initialHeight: '117px',
		//width: '650px',
		height: '95%',
		open: true,
		overlayClose: true,
		title: imageLinkTitle,
		close: '<b>Schließen </b>&nbsp;<span style="font-size:9px;">(ESC-Taste)</span>'
	});
}
function GET(HTTP_GET_VARS,v){
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}

/**
 * Öffnet Dia als Pop-Layer.
 */
$jQ(document).ready( function() {
	$jQ('A[rel="makzgallery"]').colorbox({
		transition: 'elastic',
		opacity: 0.5,
		speed: 700,
		initialWidth: '184px',
		initialHeight: '117px',
		width: '65%',
		height: '95%',
		scrolling: false,
		overlayClose: true,
		preloading:	true,
		previous: '<b>Zurück</b>',
		next: '<b>Weiter</b>&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size:9px;">(Links-/Rechts-Pfeiltasten)</span>',
		close: '<b>Schließen </b>&nbsp;<span style="font-size:9px;">(ESC-Taste)</span>',
		current: 'Bild {current} von {total}'
	});
});

/**
 * Öffnet Erklärungen als Pop-Layer.
 */
$jQ(document).ready( function() {
	$jQ(".tx-contagged-definition A, .tx-contagged-abbrevation A").colorbox({
		href:function(){return $jQ(this).attr('href')+'&mode=ajax'},
		transition: 'elastic',
		opacity: 0.5,
		speed: 700,
		initialWidth: '184px',
		initialHeight: '117px',
		width: '650px',
		height: '480px',
		scrolling: false,
		overlayClose: true,
		close: '<b>Schließen </b>&nbsp;<span style="font-size:9px;">(ESC-Taste)</span>'
	});
});

/**
 * Anstatt normale Popups hier die unobstruive jQuery-Variante.
 */
$jQ(document).ready( function() {
    $jQ('A[rel="external Window"], #sideBoxSponsors .adBanner A, #homepageforecast A, #navigationService .itemLast A').click( function() {
        window.open( $jQ(this).attr('href') );
        return false;
    });
});

/**
 * Pfeil-Effekt im Hauptmenue.
 */
$jQ(document).ready( function() {
	$jQ("#navigationMain,").lavaLamp({
		fx: "backout",
		speed: 700
	})
});

/**
 * Sanftes Scrollen zum oberen Rand bei Link "zum Seitenanfang".
 */
$jQ(document).ready(function() {
	$jQ('a[href*=#page_top]').bind("click", function(event) {
		event.preventDefault();
		var ziel = $jQ(this).attr("href");

		if ($jQ.browser.opera) {
			var target = 'html';
		}else{
			var target = 'html,body';
		}
		$jQ(target).animate({
			scrollTop: $jQ(ziel).offset().top
		}, 1000 , function (){location.hash = ziel;});
	});
	return false;
});

/**
 * Steuerung des Kopfbanners.
 */
var fPageBannerShow = true;
var sPageBannerHeightFull = 265 + "px";
var sPageBannerHeightMin  =  15 + "px";
var sPageBannerCmdOpacity = 0.55;

if ($jQ.cookie("scoPageBannerShow") == "false") {
	// Bild einfach klein machen:
	document.writeln("<style>#boxBanner{height:" + sPageBannerHeightMin + ";}</style>");
}else{
	document.writeln("<style>#boxBanner{height:" + sPageBannerHeightFull + ";}</style>");
}

$jQ(document).ready( function() {
	$jQ("#cmdPageBannerToggle").show();	//Button nur bei JS einblenden.

	// Zustand aus Cookie erfragen.
	if($jQ.cookie("scoPageBannerShow") == "false" ) {
		// Bild einfach klein machen:
		$jQ("#boxBanner").css("height", sPageBannerHeightMin);
		$jQ("#cmdPageBannerToggle").css("background-position", "-45px 0");
		$jQ("#cmdPageBannerToggle").css("opacity", 1); 	// Cross-Browser!

		fPageBannerShow = false;
		document.getElementById("cmdPageBannerToggle").title = "Verkleiner das Kopfbild";
	}else{
		$jQ("#cmdPageBannerToggle").css("opacity", sPageBannerCmdOpacity); 	// Cross-Browser!
	}

	$jQ("#cmdPageBannerToggle").hover(
      function () {
	  	$jQ(this).css("opacity", "1");
        if( fPageBannerShow == true ){
			$jQ(this).css("background-position", "0 -13px");
		}else{
			$jQ(this).css("background-position", "-45px -13px");
		}
      },
      function () {
		if( fPageBannerShow == true ){
			$jQ(this).css("background-position", "0 0");
			$jQ(this).css("opacity", sPageBannerCmdOpacity);
		}else{
			$jQ(this).css("background-position", "-45px 0");
			$jQ(this).css("opacity", 1);
		}
      }
    );

	$jQ("#cmdPageBannerToggle").click(function () {
		if(fPageBannerShow == true) {
			// Bild animier klein machen:
			$jQ("#boxBanner").animate({height: sPageBannerHeightMin},1000);
			this.blur();
			fPageBannerShow = false;
			document.getElementById("cmdPageBannerToggle").title = "Vergrößert das Kopfbild";

		}else{
			// Bild animiert groß mache:
			$jQ("#boxBanner").animate({height: sPageBannerHeightFull},1000);
			this.blur();
			fPageBannerShow = true;
			document.getElementById("cmdPageBannerToggle").title = "Verkleinert das Kopfbild";
		}
		$jQ.cookie('scoPageBannerShow', fPageBannerShow, {expires: 7, path: "/" });
	});
});

/**
 * fontScaler (Schrift größer/ kleiner machen)
 * Cookie-Lifetime in minutes: 60(minutes)*24(hours)*7(days) = 1 week from now!
 */
$jQ(document).ready(function() {
	$jQ(".fontSizer").fontScaler({
		target: '#boxContentContainer',
		containerclass: 'fontScaler',
		store: true,
		storetime: 60*24*7,
		fx: 'smooth',
		fxspeed: 50,
		fixed:{
			size1: '90',
			id1: 'fs_small',
			title1: 'Schriftgröße klein',
			size2: '100',
			id2: 'fs_normal',
			title2: 'Schriftgröße normal',
			size3: '120',
			id3: 'fs_large',
			title3: 'Schriftgröße groß'
		}
	});
	// Zustand beim Laden.
	if( $jQ.cookie("fontScalerFixed") == 1 ){
		$jQ("#fs_small").addClass("fs_selected");
		$jQ("#fs_normal").removeClass("fs_selected");
		$jQ("#fs_large").removeClass("fs_selected");
	}else if( $jQ.cookie("fontScalerFixed") == 3 ){
		$jQ("#fs_small").removeClass("fs_selected");
		$jQ("#fs_normal").removeClass("fs_selected");
		$jQ("#fs_large").addClass("fs_selected");
	}else{
		$jQ("#fs_small").removeClass("fs_selected");
		$jQ("#fs_normal").addClass("fs_selected");
		$jQ("#fs_large").removeClass("fs_selected");
	}
	// Zustand nach dem Anklicken.
	$jQ("#fs_small,#fs_normal,#fs_large").click(function () {
		if( $jQ.cookie("fontScalerFixed") == 1 ){
			$jQ("#fs_small").addClass("fs_selected");
			$jQ("#fs_normal").removeClass("fs_selected");
			$jQ("#fs_large").removeClass("fs_selected");
		}else if( $jQ.cookie("fontScalerFixed") == 2 ){
			$jQ("#fs_small").removeClass("fs_selected");
			$jQ("#fs_normal").addClass("fs_selected");
			$jQ("#fs_large").removeClass("fs_selected");
		}else if( $jQ.cookie("fontScalerFixed") == 3 ){
			$jQ("#fs_small").removeClass("fs_selected");
			$jQ("#fs_normal").removeClass("fs_selected");
			$jQ("#fs_large").addClass("fs_selected");
		}
	});
});

/**
 * Client OS for Font-Names
 * Es wird angenommen, daß Windows-Systeme den Font Georgia haben.
 */
if ($jQ.client.os == "Windows") {
	// Font Georgia nehmen und Größe anpassen:
	document.writeln("<style>.pageMainTitle{font-family:Georgia,\"Times New Roman\",Times,serif;font-size:1.55em;}</style>");
}else{
	document.writeln("<style>.pageMainTitle{font-family:\"Times New Roman\",Times,serif;font-size:1.6em!important;}</style>");
}

/**
 * Input-Feld bei Focus mit Hintergrundfarbe versehen; Reset bei Blur.
 */
$jQ(document).ready(function() {
    $jQ('input[type="text"], textarea').addClass("idleField");
	$jQ('input[type="text"], textarea').focus(function() {
		$jQ(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $jQ('input[type="text"], textarea').blur(function() {
    	$jQ(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value == '')){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
});



/*
 * Tooltip script
 * powered by jQuery (http://www.jquery.com)
 *
 * written by Alen Grakalic (http://cssglobe.com)
 *
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */



this.tooltip = function(){
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$jQ("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$jQ("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$jQ("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$jQ("#tooltip").remove();
    });
	$jQ("a.tooltip").mousemove(function(e){
		$jQ("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};



// starting the script on page load
$jQ(document).ready(function(){
	tooltip();
});








