/**
 * Globale Variablen für jq:Colorbox
 */
var g_colorBox = new Object ();
g_colorBox['transisiton'] 	= 'elastic';
g_colorBox['opacity'] 		= 0.4;
g_colorBox['speed'] 		= 650;
g_colorBox['initialWidth'] 	= '250px';
g_colorBox['initialHeight']	= '210px';
g_colorBox['width'] 		= '80%';
g_colorBox['maxWidth'] 		= '500px';
g_colorBox['height']		= '';
g_colorBox['overlayClose']	= true;
g_colorBox['scrolling']		= false;
//g_colorBox['close']		= '<b>Schließen </b>&nbsp;<span style="font-size:9px;">(ESC-Taste)</span></div><div id="cboxPrint"><b>Print</b>';
g_colorBox['close']			= '<b>Schließen </b>';
g_colorBox['print']			= '<b>Einzel-/Druckansicht</b>';


/**
 * 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(document).ready(function() {
	/**
	 * Google Analytics
	 *
	 */
	var strGALabel = ' <label>Ihren Besuch aufzeichnen <a href="/?id=privacy#c278" title="Was bedeutet diese Einstellung">[?]</a></label>';
	var strGADev = ' <lable style="color:red;">Redaktionsmodus: User-Tracking aus!</lable>';

	if (window.location.href.indexOf('webspaceconfig') > 0 || window.location.href.indexOf('typo3server') > 0 || window.location.href.indexOf('p126278') > 0) {
		var fAdminMode = true;	// Tracking: OFF.
	}else{
		var fAdminMode = false;	// Tracking: ON.
	}

	if( fAdminMode == true ){
		// Tracking: OFF!
		var strGACheckbox = '<input type="checkbox" id="gaOptOut" value="true" disabled="disabled" />';
		$jQ('#boxGoogleAnalytics').after(strGACheckbox + strGADev);
	}else{
		// Tracking: ON!
		var strGACheckbox = '<input type="checkbox" id="gaOptOut" value="true" />';
		$jQ('#boxGoogleAnalytics').after(strGACheckbox + strGALabel);
	}

	if( $jQ.cookie('logGoogleAnalytics') == 'false' || fAdminMode == true ){
		// Tracking: OFF!
		$jQ('#gaOptOut').removeAttr('checked');
		$jQ.cookie('logGoogleAnalytics', false, {expires:365});
	}else{
		// Tracking: ON.
		$jQ('#gaOptOut').attr('checked','checked');
		$jQ.cookie('logGoogleAnalytics', true, {expires:365});
		// Plugin "jquery-google-analytics" aktivieren.

		$jQ.trackPage('UA-XXXXXX-1',{
			onload: true
			//status_code: 404
		});

		// Tracking: Kalender
		$jQ("BODY#body_veranstaltungen .tx-cal-controller DL DT A, .calMiniList .tx-cal-controller DL DT A").track({
			category : 'Kalender'
		});
		//$jQ("BODY#body_veranstaltungen .tx-cal-controller DL DT A, .calMiniList .tx-cal-controller DL DT A").track({
		//	category : 'Kalender'
		//});

	}
	$jQ('#gaOptOut').click( function() {
		$jQ.cookie('logGoogleAnalytics', $jQ(this).attr('checked'), {expires:365});
	});
});


$jQ(document).ready(function() {
	$jQ('.csc-menu-7 .article-title').click(function() {
		//alert()
		$jQ(this).toggleClass('isActive');
		$jQ(this).next().toggle();
		$jQ(this).next().toggleClass('isActive');
		return false;
	}).next().hide();

	$jQ('.csc-menu-7 .article-title').mouseover(function() {
		$jQ(this).toggleClass('isOver');
	});
	$jQ('.csc-menu-7 .article-title').mouseout(function() {
		$jQ(this).toggleClass('isOver');
	});

	$jQ("DD.article-teaser A").click(function() {
		var strHref = $jQ(this).attr('href');
		var pressUid = $jQ.getURLParam('press-uid', strHref);
		if (pressUid != null) {
			//alert(pressUid);
			$jQ.cookie('press-uid', pressUid);
		}
		return true;
	});

	var lastPressUid = parseInt($jQ.cookie('press-uid'));
	if( lastPressUid > 0 ){
		var domKeyParent = 'DT#article-title-'  + lastPressUid;
		var domKeyChild  = 'DD#article-teaser-' + lastPressUid;
		//$jQ(domKeyParent).toggleClass('isActive');
		$jQ(domKeyParent).toggleClass('isLast');
		//$jQ(domKeyChild).show();
		//$jQ(domKeyChild).toggleClass('isActive');
	}

});

$jQ(function() {
	/* Events in ColorBox.
	 * - miniCalList
	 * - Default List
	 */

	var key = '';
	key += 'BODY#body_veranstaltungen .tx-cal-controller DL DT A, ';
	key += 'BODY#body_veranstaltungen-akt-semester .tx-cal-controller DL DT A, ';
	key += 'BODY#body_veranstaltungen-naechst-semester .tx-cal-controller DL DT A, ';
	key += '.calMiniList .tx-cal-controller DL DT A';

	$jQ(key).click(function() {
	var strHref = $jQ(this).attr('href');
	var fIsColorbox = strHref.indexOf("tx_cal_controller[view]=event");

	if (fIsColorbox > -1) {
		/**
		 * EXT:an_search hängt ein "#ID" an das Ende der Fundstellen.
		 * Dies erzeugt einen Fehler beim Auswerten des AJAX-Parameters.
		 * Der Href wird bei einem (möglichen) "#" gesplittet, manipuliert
		 * und wieder zusammengesetzt.
		 */
		var strHref = $jQ(this).attr('href');
		var arrHref = strHref.split("#");
		var ajaxHref = arrHref.join("#");
		ajaxHref = strHref + " div#singleEvent";	// Url für Ajax mit zu filterndem Container.
		var printHref = $jQ(this).attr('href');		// Original Url.

		$jQ.colorbox({
			href: 			ajaxHref,
			transition: 	g_colorBox['transisiton'],
			opacity: 		g_colorBox['opacity'],
			speed: 			g_colorBox['speed'],
			initialWidth: 	g_colorBox['initialWidth'],
			initialHeight: 	g_colorBox['initialHeight'],
			maxWidth: 		g_colorBox['maxWidth'],
			width: 			g_colorBox['width'],
			scrolling: 		g_colorBox['scrolling'],
			overlayClose: 	g_colorBox['overlayClose'],
			close: 			g_colorBox['close'],
			print: 			g_colorBox['print'],
			printHref:		printHref
		});
		return false;
	}else{
		return true;
	}
	});
});

$jQ(document).ready(function(){
	/*
	 * Addresses in ColorBox
	 */
	$jQ(".example5, .searchlink A").click(function () {
		var strHref = $jQ(this).attr('href');
		var fIsColorbox = strHref.indexOf("colorbox=1");
		if( fIsColorbox > -1 ){
			/**
				* EXT:an_search hängt ein "#ID" an das Ende der Fundstellen.
				* Dies erzeugt einen Fehler beim Auswerten des AJAX-Parameters.
				* Der Href wird bei einem (möglichen) "#" gesplittet, manipuliert
				* und wieder zusammengesetzt.
				*/
			var strHref = $jQ(this).attr('href');
			var arrHref = strHref.split("#");
			//arrHref[0] = arrHref[0] + "&mode=ajax";
			var ajaxHref = arrHref.join("#");
			ajaxHref = strHref + " div#address-details";// Url für Ajax mit zu filterndem Container.
			var printHref = $jQ(this).attr('href');		// Original Url.

			$jQ(this).colorbox({
				href:			ajaxHref,
				transition: 	g_colorBox['transisiton'],
				opacity: 		g_colorBox['opacity'],
				speed: 			g_colorBox['speed'],
				initialWidth: 	g_colorBox['initialWidth'],
				initialHeight:	g_colorBox['initialHeight'],
				maxWidth: 		g_colorBox['maxWidth'],
				width: 			g_colorBox['width'],
				scrolling: 		g_colorBox['scrolling'],
				overlayClose: 	g_colorBox['overlayClose'],
				close: 			g_colorBox['close'],
				print: 			g_colorBox['print'],
				printHref:		printHref
			});
		}
	});
});



/**
 * fontScaler (Schrift größer/ kleiner machen)
 * Cookie-Lifetime in minutes: 60(minutes)*24(hours)*7(days) = 1 week from now!
 */
$jQ(document).ready(function() {
	var strFontSizerHml = '';
	strFontSizerHml += '<h6 title="Durch Anklicken der [A]-Symbole wird die Schriftgröße geändert.">';
	strFontSizerHml += 'Schriftgröße<span class="inv">:</span>';
	strFontSizerHml += '</h6>';
	strFontSizerHml += '<div id="fontSizer"></div>';

	$jQ("#header .page_margins .page #boxFontSizer").html(strFontSizerHml);

	$jQ("#header .page_margins .page #fontSizer").fontScaler({
		target: '#boxSubHeader #breadcrumbs, #col1_content,#col2_content,#col3_content, #footer .page',
		containerclass: 'fontScaler',
		store: true,
		storetime: 60*24*7,
		fx: 'smooth',
		fxspeed: 50,
		fixed:{
			size1: '95',
			id1: 'fs_small',
			title1: 'Schriftgröße klein',
			size2: '100',
			id2: 'fs_normal',
			title2: 'Schriftgröße normal',
			size3: '125',
			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");
		}
		this.blur();
	});
});





/**
 * Anstatt normale Popups hier die unobstruive jQuery-Variante.
 */
$jQ(document).ready( function() {
		$jQ('A[rel="external Window"]').click( function() {
				window.open( $jQ(this).attr('href') );
				return false;
		});
});


$jQ.extend({
	getUrlVars: function(strHref){
		var vars = [], hash;
		var hashes = strHref.slice(strHref.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	getUrlVar: function(strName, strHref){
		return $jQ.getUrlVars(strHref)[strName];
	}
});


/**
 * 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"]').removeAttr('onclick');
	$jQ('A[rel="magnifier"]').removeAttr('onclick');

	//$jQ('A[rel="magnifier"]').click( function() {
	$jQ('A[rel="magnifier"]').each( function() {
		var strHref = unescape($jQ.getUrlVar('file', $jQ(this).attr('href') ));
		$jQ(this).attr('href', strHref);

		if( $jQ(this).attr('title') == '' ){

			if ($jQ(this).find('IMG').attr('alt')) {
				strTitle = $jQ(this).find('IMG').attr('alt');
			}else{
				strTitle = "Kein Titel";
			}

			$jQ(this).attr('title', strTitle);
		}
		//return false;
	});
	$jQ('.csc-textpic-image dt a[rel="magnifier"]').attr('rel', 'colorbox');


	$jQ('.jcarousel-list A:first').colorbox({
			//href:			$jQ(this).attr('href'),
			transition:		g_colorBox['transisiton'],
			opacity:		g_colorBox['opacity'],
			speed:			g_colorBox['speed'],
			initialWidth:	g_colorBox['initialWidth'],
			initialHeight:	g_colorBox['initialHeight'],
			scalePhotos:	true,
			open: 			true,
			overlayClose:	g_colorBox['overlayClose'],
			title:			$jQ(this).attr('title'),
			close:			g_colorBox['close'],
			print: 			g_colorBox['print'],
			printHref:		$jQ(this).attr('href'),
			previous:		true,
			next:			true
	});

	$jQ('.csc-textpic-image DT A[rel="colorbox"]').click( function() {
		//alert( $jQ(this).attr('title') );
		$jQ.fn.colorbox({
			href:			$jQ(this).attr('href'),
			transition:		g_colorBox['transisiton'],
			opacity:		g_colorBox['opacity'],
			speed:			g_colorBox['speed'],
			initialWidth:	g_colorBox['initialWidth'],
			initialHeight:	g_colorBox['initialHeight'],
			scalePhotos:	true,
			open: 			true,
			overlayClose:	g_colorBox['overlayClose'],
			title:			$jQ(this).attr('title'),
			close:			g_colorBox['close'],
			print: 			g_colorBox['print'],
			printHref:		$jQ(this).attr('href'),
			previous:		false,
			next:			false
		});
		return false;
	});



	$jQ('.csc-textpic-image dt a[rel="colorbox"]').append('<img src="fileadmin/breitensport-deutschland.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?

			//alert(unescape(link.href));

			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:		g_colorBox['transisiton'],
		opacity:		g_colorBox['opacity'],
		speed:			g_colorBox['speed'],
		initialWidth:	g_colorBox['initialWidth'],
		initialHeight:	g_colorBox['initialHeight'],
		//innerWidth: '640px',
		//innerHeight: '480px',
		scalePhotos:	true,
		//maxWidth:		g_colorBox['maxWidth'],
		open: 			true,
		overlayClose:	g_colorBox['overlayClose'],
		title:			imageLinkTitle,
		close:			g_colorBox['close'],
		print: 			'',
		printHref:		'',
		previous:		true,
		next:			true
	});
}
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('.tx-imagecarousel-pi1 LI A[rel="magnifier"]').colorbox({
		transition:		g_colorBox['transisiton'],
		opacity: 		g_colorBox['opacity'],
		speed: 			g_colorBox['speed'],
		initialWidth:	g_colorBox['initialWidth'],
		initialHeight:	g_colorBox['initialHeight'],
		//width: '65%',
		//height: '95%',
		//maxWidth: 	g_colorBox['maxWidth'],
		scrolling: 		g_colorBox['scrolling'],
		overlayClose: 	g_colorBox['overlayClose'],
		preloading:		true,
		previous: 		'<b>&lt; Zurück</b>',
		next: 			'<b>Weiter &gt;</b>',
		close: 			g_colorBox['close'],
		current: 		'Bild {current} / {total}'
	});
	return false;
});


$jQ(document).ready( function() {

	var strImgAjaxIndicatorBar = '<img src="fileadmin/breitensport-deutschland.de/system/medias/icons/ajax-loader-hor.gif" width="128" height="15" border="0" class="cal-category-menu-action-msg" />';
	var strImgAjaxIndicatorCirc = '<img src="fileadmin/breitensport-deutschland.de/system/medias/icons/ajax-loader-circ.gif" width="16" height="16" border="0" class="cal-category-menu-action-msg" />';
	var strImgAjaxIndicatorArrow = '<img src="fileadmin/breitensport-deutschland.de/system/medias/icons/ajax-loader-arrow.gif" width="16" height="16" border="0" class="cal-category-menu-action-msg" />';

	$jQ('#cal-category-menu-page-12-tt_content-116 #cal-category').change( function() {
		$jQ(this).after('&nbsp;&nbsp;' + strImgAjaxIndicatorArrow);
		setTimeout("$jQ('#cal-category-menu-page-12-tt_content-116').submit()",1000);
		});


	$jQ('#cal-category-menu-page-169-tt_content-273 #cal-category').change( function() {
		$jQ(this).after('&nbsp;&nbsp;' + strImgAjaxIndicatorArrow);
		setTimeout("$jQ('#cal-category-menu-page-169-tt_content-273').submit()",1000);
		});



	/**
	 * Einfügen eines Symbols für externe Links.
	 */
	$jQ("body").link_external_icon({
		icon_path:"fileadmin/breitensport-deutschland.de/system/medias/icons/link-external.png"
	});

	/**
	 * Anstatt normale Popups hier die unobstruive jQuery-Variante.
	 */
		$jQ('A[rel="external Window"], A[target="_blank"]').click( function() {
		window.open( $jQ(this).attr('href') );
				return false;
		});

	/**
	 * Vorbelegen und Handling des Suchfeldes.
	 */
	var strSearchDummie = 'Suchwort';
	var strSearchForm 	= '#tx_ansearchit_form, #boxDefaultSearchAllPages #mailform';
	var strSearchField	= '#tx_ansearchit_form, #boxDefaultSearchAllPages #mailformsword';

	$jQ(strSearchField).val(strSearchDummie);
	$jQ(strSearchField).focus( function() {
		if( $jQ(this).val() == strSearchDummie ){
			$jQ(this).val('');
		}
	});
	$jQ(strSearchField).blur( function() {
		if( $jQ(this).val() == '' ){
			$jQ(this).val(strSearchDummie);
		}
	});
	$jQ('#tx_ansearchit_form, #boxDefaultSearchAllPages #mailform').submit( function() {
		if( $jQ(strSearchField).val() == strSearchDummie || $jQ(strSearchField).val() == '' ){
			return false;
		}
	});


	/**
	 * Farbige Kennzeichnung von Suchergebnissen.
	 */
	var strSearchKey = 'sword_list[]';
	var strHitsRemove = '<div class="hitsRemove"><a href="javascript:void($jQ(\'#col3_content\').removeHighlight());">Keine Fundstellen-<span class="highlight">Markierung</span></a>.</div>';
	if( window.location.href.indexOf(strSearchKey) > 0 ){
		var strSearchTerm = unescape($jQ.getUrlVar(strSearchKey, window.location.href));
		$jQ('#col3_content').highlight(strSearchTerm);
		$jQ('#col1 #col1_content #boxDefaultSearchAllPages #mailform').after(strHitsRemove);
	}
	//if( strSearchTerm != 'undefined' ){ alert(strSearchTerm);}


});

