﻿/* jQuery extension to get url params */
jQuery.extend({
  getUrlVars: function(){
    var vars = [], hash;
	var url = unescape(window.location.href);
    var hashes = url.slice(window.location.href.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(name){
    return jQuery.getUrlVars()[name];
  }
});

jQuery.fn.centerSL=function(a){var b=jQuery(window),c=b.scrollTop();return this.each(function(){var f=jQuery(this),e=jQuery.extend({against:"window",top:false,topPercentage:0.5},a),d=function(){var h,g,i;if(e.against==="window"){h=b;}else{if(e.against==="parent"){h=f.parent();c=0;}else{h=f.parents(against);c=0;}}g=((h.width())-(f.outerWidth()))*0.5;i=((h.height())-(f.outerHeight()))*e.topPercentage+c;if(e.top){i=e.top+c;}f.css({left:g,top:i});};d();b.resize(d);});};


	var weburl = /http:\/\/www.bastian-schweinsteiger.de/;
	//var weburl = /http:\/\/bs.dev.afm-koeln.de/;
	
	var domain = 'http://www.bastian-schweinsteiger.de/';
	//var domain = 'http://bs.dev.afm-koeln.de/';

	var isInIFrame = false;

	n=navigator;
	nua=n.userAgent;
	saf=(nua.indexOf('Safari')!=-1 && nua.indexOf('Chrome')==-1);
	  

/*------------------------------------------
          ROUNDABOUT SCRIPTS
-------------------------------------------*/
	var currentttnewspage = 0;
	var islastnewspage = 0;
	
	var currentChild = 0;
	
	TopUp.enableFastMode(true);
	/* 
	var topupOptions = {
		width: 600,
	   height: 500,
	   type: "iframe",
	   layout: "dashboard",
	   shaded: 1,
	   resizable: 0,
	   effect: 'show',
	   x: 225,
	   y: 90
	}; */
	var topupOptions = {
		width: 600,
	   height: 530,
	   type: "iframe",
	   layout: "dashboard",
	   shaded: 1,
	   resizable: 0,
	   effect: 'show',
	   x: 225,
	   y: 90
	};

	function inithtml5() {
        sc_elements = new Array( );
        jQuery('.ring .news-list-item').each(function(index) {
          sc_elements.push( jQuery(this).attr('id') );
        });
        RING_RADIUS = ((sc_elements.length * 250 ) / 3.14156298 ) /2;
        jQuery('.ring').roundabout({
          minOpacity: 0, // invisible!
          minScale: 0, // tiny!
		  tilt: 4.2,
          clickToFocus: false,
		  reflect: false,
		  debug: false
          //childSelector: 'table'
        });
    }
  
	   TopUp.addPresets({
         ".ring .poster a[target!=_blank]": topupOptions
       });
	   TopUp.addPresets({
         "#teasernewshome ul li a[target!=_blank]": topupOptions
       });
	   TopUp.addPresets({
         "#footer .footersponsor a": topupOptions
       });
	   TopUp.addPresets({
         "#footer .footerinfomenu a": topupOptions
       });
	   
	   /* main menu sub popup*/
		TopUp.addPresets({
			"#nav ul li ul.ueber li a[target!=_self]": topupOptions
		});

		
		
	 cnt = 1;
	 
	 
	 function fillupttnews() {
		/* fill tt_news elements with dummy items when not enough */
		if ( jQuery('.ring li').length <= 10 ) {
			var missingitems = 11 - jQuery('.ring li').length;
			//alert(missingitems);
			
			for (i=1; i<=missingitems; i++) {
				jQuery('.ring li:last').after('<li id="emptycard_'+i+'" class="emptycard"></li>');
			}
		}
	 }
	 
	 function changettnewsMoreLinkText() {
		jQuery('.ring li').each(function(index) {
			morelinktext = jQuery(this).children('.footer').children('a').text();
			
			morelinkurl = jQuery(this).children('.footer').children('a').attr('href');
			
			newlinktext = '';
			//alert(jQuery(this).children('p.footer a').text());
			if ( jQuery(this).children('p.footer').children('a').attr('target') == '_blank' ) {
				//alert('aaaa');
				if ( morelinkurl.search(/facebook+/i) != -1 ) {
					//alert('bbbb');
					newlinktext = 'ZU FACEBOOK';
					//jQuery(this).children('p.footer').children('a').text('ZU FACEBOOK');
				} else {
					newlinktext = 'ZU DEN NEWS';
					//alert('ccc');
					//jQuery(this).children('p.footer').children('a').text('ZU DEN NEWS');
				}
			} else {
				newlinktext = morelinktext;
			}
			
			
			if ( jQuery(this).hasClass('cat_STYLE') ) {
				jQuery(this).children('p.footer').children('a').before('<img src="/fileadmin/template/images/home/feed_button_rechts_style.gif" style="width:1.55em; float:left; padding-top: 0.6em;" />');
				//newlinktext = '<img src="/fileadmin/template/images/home/feed_button_rechts_style.gif" />' + newlinktext;
				//alert('testsetset');
			} else if ( jQuery(this).hasClass('cat_SPORT') ) {
				jQuery(this).children('p.footer').children('a').before('<img src="/fileadmin/template/images/home/feed_button_rechts_sport.gif" style="width:1.55em; float:left; padding-top: 0.6em;" />');
			} else {
				jQuery(this).children('p.footer').children('a').before('<img src="/fileadmin/template/images/home/feed_button_rechts_privat.gif" style="width:1.55em; float:left; padding-top: 0.6em;" />');
			}
			jQuery(this).children('p.footer').children('a').text(newlinktext);
			
		});
		
		
		//jQuery(this).hasClass('cat_STYLE').children('p.footer').children('a').before('<img src="/fileadmin/template/images/home/feed_button_rechts_style.gif" />');

		
		
	 }
	 
  
     jQuery(document).ready(function() {
		//alert('ttest');
		
		fillupttnews();
		changettnewsMoreLinkText();
	 
	 
       //sc_elements = new Array( jQuery('#ring-1 .post').length );
       sc_elements = new Array( );
       jQuery('.ring li').each(function(index) {
         sc_elements.push( jQuery(this).attr('id') );
         
       });
       //alert(sc_elements.length);
       //const RING_RADIUS = ((sc_elements.length * 250 ) / 3.14156298 ) /2;
       RING_RADIUS = ((sc_elements.length * 250 ) / 3.14156298 ) /2;
    
	if(saf){
	   /* jQuery('#slider').slider({
         min: -190,
         max: 155,
         value: 146
       }); */
	   
	   jQuery('#slider').slider({
        // min: RING_RADIUS * -1,
         min: -360,
         max: -33,
         value: -33,
		 step: 1
       });
	   
	} else {
    /* 
       jQuery('#slider').slider({
         min: -340,
         max: 10,
         value: 0
       }); */
       jQuery('#slider').slider({
         min: -330,
         max: 0,
         value: 0,
		 step: 1
       });
	   
	}
	   
	    var ua = jQuery.browser;
		if (ua.msie && ( ua.version.slice(0,1) == '8' || ua.version.slice(0,1) == '7' )) {
			jQuery('ul#news-listteaser li').cornerz({
				radius: 18,
				corners: "tl tr",
				background: "transparent"
			});
			jQuery('#rotate .ring li').cornerz({
				radius: 18,
				corners: "tr bl br",
				background: "transparent"
			});
			jQuery('.jspDrag').cornerz({
				radius: 10,
				corners: "tl tr bl br",
				background: "transparent"
			});
			/* jQuery('.ui-corner-all').cornerz({
				radius: 10,
				corners: "tl tr bl br",
				background: "transparent"
			}); */
		}
		
		
		
		/*######################################
			Parse Time for nextgame-view
		#######################################*/
		var nextgametime = jQuery('#nextgame .red').text();
		var nextgametimesplit = nextgametime.split('#');
		
		var nextgamenewtext = 'noch ';
		
		var nextgametimedifference = (nextgametimesplit[0] * -1);
		nextgamenewtext += nextgametimedifference;
		var showplaybackground = 0;
		
		switch (nextgametimesplit[1]) {
			case "m":
				if (nextgametimedifference <= 1) {
					nextgamenewtext += ' Minute';
				} else {
					nextgamenewtext += ' Minuten';
				}
				showplaybackground = 1;
                break;
			case "h":
				if (nextgametimedifference <= 1) {
					nextgamenewtext += ' Stunde';
				} else {
					nextgamenewtext += ' Stunden';
				}
				showplaybackground = 1;
                break;
			case "d":
				if (nextgametimedifference <= 1) {
					nextgamenewtext += ' Tag';
				} else {
					nextgamenewtext += ' Tage';
				}
				showplaybackground = 2;
                break;
			case "j":
				if (nextgametimedifference <= 1) {
					nextgamenewtext += ' Jahr';
				} else {
					nextgamenewtext += ' Jahre';
				}
                break;
				   
			default:
				nextgamenewtext = 'Unbekannt';
				break;
		}
		jQuery('#nextgame .red').text(nextgamenewtext);
		
		if (nextgametimedifference <= 0) {
			jQuery('#nextgame').remove();
		}
		
		/*---------change Background------------*/
		
		var ua = jQuery.browser;
		if (ua.msie && ( ua.version.slice(0,1) == '8' || ua.version.slice(0,1) == '7' )) {
			if (showplaybackground == 1) {
				jQuery('body #iebg').not('body.popuppage #iebg').before('<img src="/fileadmin/template/images/bg_spiel.jpg" style="position:fixed; bottom:0; right:0; height:100%; z-index:0;" />');
			} else if (showplaybackground == 2 && ( nextgametimedifference <= 3 && nextgametimedifference >= 0 ) ) {
				jQuery('body #iebg').not('body.popuppage #iebg').before('<img src="/fileadmin/template/images/bg_training.jpg" style="position:fixed; bottom:0; right:0; height:100%; z-index:0;" />');
			} else {
				jQuery('body #iebg').not('body.popuppage #iebg').before('<img src="/fileadmin/template/images/bg_privat.jpg" style="position:fixed; bottom:0; right:0; height:100%; z-index:0;" />');
			}
		} else {
			if (showplaybackground == 1) {
				jQuery('body').not('body.popuppage').css('background-image', 'url("/fileadmin/template/images/bg_spiel.jpg")');
			} else if (showplaybackground == 2 && ( nextgametimedifference <= 3 && nextgametimedifference >= 0 ) ) {
				jQuery('body').not('body.popuppage').css('background-image', 'url("/fileadmin/template/images/bg_training.jpg")');
			} else {
				jQuery('body').not('body.popuppage').css('background-image', 'url("/fileadmin/template/images/bg_privat.jpg")');
			}
		}
		
		
		
		jQuery('#slider-bg').bind('mouseover', function() {
			jQuery('#slider-bg').addClass('slide-hover');
		});
		jQuery('#slider-bg').bind('mouseout', function() {
			jQuery('#slider-bg').removeClass('slide-hover');
		});
    
     });
	 
	function changeTtnewsBrowserPos() {
		
		jQuery('.news-list-browse').not('ul.ring .news-list-browse').remove();
		jQuery('#stage').after( jQuery('ul.ring .news-list-browse') );
		jQuery('ul.ring .news-list-browse').remove();
	
		jQuery(".news-list-browse span strong").hide();
		
		jQuery(".news-list-browse span:last a").text(' ');
		jQuery(".news-list-browse span:first a").text(' ');
		                               
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('position', 'absolute');
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('z-index', '5');
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('top', '305px');
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('display', 'block');
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('width', '20px');
		jQuery(".news-list-browse span:last a, .news-list-browse span:first a").css('height', '25px');
		jQuery(".news-list-browse span:last a").css('left', '290px');
		
		jQuery(".news-list-browse span:first a").css('left', '770px');
		
		
		jQuery('.news-list-browse span a').bind('mouseover', function() {
			jQuery('#slider-bg').addClass('slide-hover');
		});
		
		if ( jQuery(".news-list-browse span:last a").length == 1 && jQuery(".news-list-browse span:first a").length == 1 ) {
			jQuery('#slider-bg').addClass('slide-both');
			jQuery('#slider-bg').removeClass('slide-right');
			jQuery('#slider-bg').removeClass('slide-left');
			//jQuery('#slider-bg').css('background-image', 'url(/fileadmin/template/images/home/feed_slider_both.png)');
		} else if ( jQuery(".news-list-browse span:first a").length == 1 ) {
			jQuery('#slider-bg').addClass('slide-right');
			jQuery('#slider-bg').removeClass('slide-left');
			jQuery('#slider-bg').removeClass('slide-both');
			//jQuery('#slider-bg').css('background-image', 'url(/fileadmin/template/images/home/feed_slider_right.png)');
		} else if ( jQuery(".news-list-browse span:last a").length == 1 ) {
			jQuery('#slider-bg').addClass('slide-left');
			jQuery('#slider-bg').removeClass('slide-right');
			jQuery('#slider-bg').removeClass('slide-both');
			//jQuery('#slider-bg').css('background-image', 'url(/fileadmin/template/images/home/feed_slider_left.png)');
		}
		
	}
	 
	function sl_changettnewsPage(pageurl) {
		newsContainer = jQuery(".news-list-ajax");
		newsContainer.fadeTo("slow", 0.33);
		
		pageurl = pageurl.replace(weburl, '');
		
		currenturl = window.location.href;
		//currenturl = currenturl.replace(weburl, 'http://bs:style2010@bs.dev.afm-koeln.de');
		//alert(currenturl);
		
		//alert(pageurl);
		jQuery.ajax({
			type: "POST",
			url: currenturl,
			dataType: "html",
			data: ({
				eID: 'ttnews_ajaxpagebrowser_ajaxHandler',
				todo: 'pagebrowser',
				href: escape(pageurl),
				part: newsContainer.attr("id")
			}),
			success: function(data){
				//alert('xxxxxxx');
			
			
				newsContainer.html(data);
				newsContainer.fadeTo("slow", 1.0);
				// scroll to top
				//window.location.hash = '#' + newsContainer.attr("id");
				
				
				fillupttnews();
				changettnewsMoreLinkText();
				
				if ( jQuery('.news-list-browse span:last a').size() == 0 ) {
					islastnewspage = 1;
				} else {
					islastnewspage = 0;
				}
				
				if (saf) { //wieso funktioniert das nur fuer safari???
					jQuery( "#slider" ).slider( "option", "value", 0 ); // reset slider
				}
				//alert('XXXXXXXX');
				currentChild = 0;
				
				//sl_updateZeitstrahl();
				inithtml5();
				
				
				//changeTtnewsBrowserPos();
			
				//alert('YYYYYYY');
			
			},
			cache: false,
			async: false
		});
		return false;
	}
  

      function sc_buildRotator(k, v){

        var posterAngle = 360 / sc_elements.length;

        var transform = 'rotateY(' + (posterAngle * cnt) + 'deg) translateZ(' + RING_RADIUS + 'px)';
        document.getElementById(k).style.webkitTransform = transform;

        cnt += 1;
         
      }
	  
		function sl_updateZeitstrahl() {
			
			jQuery("#zeitstrahl .dateblock .newerdate").text( jQuery("#rotate ul.ring li:first .date").text() );
			jQuery("#zeitstrahl .dateblock .olderdate").text( jQuery("#rotate ul.ring li:last .date").text() );
			
		}


	  function init (){
        sc_elements.forEach(sc_buildRotator);
      }
	  
	  function hideTooSmallEntries() {
		jQuery('.ring li').each(function(index) {
			if (jQuery(this).width() <= 85) {
				jQuery(this).css('opacity', '0');
			}
		});
	  }
	  
	  function fixIE78() {
		var ua = jQuery.browser;
		if (ua.msie && ( ua.version.slice(0,1) == '8' || ua.version.slice(0,1) == '7' )) {
			jQuery('.ring li').each(function(index) {
				jQuery(this).children('h2').css('width', jQuery(this).width()-9 ); //entferne weißen rand (-9 px wegen 10px padding und 1px weißem rand)
				jQuery(this).children('h5').css('width', jQuery(this).width() );
				jQuery(this).children('a').children('img').css('width', jQuery(this).width()+1 );
			});
		}
	  }


      if(saf){

        jQuery(document).ready(function() {

          //jQuery(".ring").css("-webkit-animation-duration","150s");
          //jQuery(".ring").css("animation-duration","150s");

          init();
		  //jQuery('.ring').css('width', '500px');
		  jQuery('.ring').css('width', '530px');
		  //jQuery('#stage').css('width', '500px');
		  jQuery('#rotate').css('width', '500px');
		  
		  jQuery('#stage').css('position', 'relative');
		  jQuery('#stage').css('top', '-20px');
		  
		  jQuery('#stage').css('-webkit-perspective', '2000');
		  
		  //jQuery('#rotate').css('-webkit-transform', 'rotateX(8.55deg) ');
		  
		  //jQuery('#rotate').css('-webkit-transform', 'rotateX(5.1deg) ');
		  jQuery('#rotate').css('-webkit-transform', 'rotateX(4.2deg) ');
		  
		  jQuery('#stage').css('-webkit-transform', 'scale(0.8)');
          
          //doSlider();
		  /* jQuery( "#slider" ).slider( "option", "value", 145 ); // reset slider
		  
		  jQuery( "#slider" ).slider( "option", "min", -190 ); // reset slider
		  jQuery( "#slider" ).slider( "option", "max", 155 ); // reset slider */
		  
		  var delta = parseFloat(jQuery('#slider').slider('value'));
		  
		  jQuery('.ring').css('-webkit-transform', 'rotateY('+(delta)+'deg)');
		  
		  jQuery('#slider').bind( "slide", function(event, ui) {
				var delta = parseFloat(jQuery('#slider').slider('value'));
				//jQuery('.ring').roundabout_setBearing(delta.toFixed(1) * -1);
				jQuery('.ring').css('-webkit-transform', 'rotateY('+(delta)+'deg)');
				//jQuery('.ring').roundabout_setBearing(delta * -1);

				//window.status =delta;
			});
			
			jQuery( "#slider" ).bind( "slidechange", function(event, ui) {
				var delta = jQuery('#slider').slider('value');
				jQuery('.ring').css('-webkit-transform', 'rotateY('+(delta)+'deg)');
				hideAllElements();
				
				//alert(delta);
			});
			
			
        });

//        window.status ="karamba";

      }else{
        function doSlider() {
			hideTooSmallEntries();
				
			jQuery('#slider').bind( "slide", function(event, ui) {
				var delta = parseFloat(jQuery('#slider').slider('value'));
				//jQuery('.ring').roundabout_setBearing(delta.toFixed(1) * -1);
				jQuery('.ring').roundabout_setBearing(delta * -1);
				//alert("grdthgtd");
				/* if ( jQuery('.ring li').css('height') ) {
					
				} */
				
				hideTooSmallEntries();
				
				fixIE78();
				
			});
			jQuery( "#slider" ).bind( "slidechange", function(event, ui) {
				var delta = parseFloat(jQuery('#slider').slider('value'));
				jQuery('.ring').roundabout_setBearing(delta * -1);
				
				//var delta = jQuery('#slider').slider('value');
				//alert(delta);
				/*if (delta >= 5 && delta <= 10 && currentttnewspage != 0) {
					currentttnewspage = currentttnewspage - 1;
					//var byName = $.getUrlVar('name');
					//alert('XXXXXXX');
					//newpageurl = 'index.php?id='+$.getUrlVar('id')+'&tx_ttnews[pointer]='+currentttnewspage;
					//newpageurl = 'index.php?id=7&tx_ttnews[pointer]='+currentttnewspage+'&no_cache=1';
					newpageurl = 'index.php?id='+jQuery.getUrlVar('id')+'&tx_ttnews[pointer]='+currentttnewspage+'&no_cache=1';
					sl_changettnewsPage( newpageurl );
					//jQuery( "#slider" ).slider( "option", "values", [0] );
				}
				if (delta <= -335 && delta >= -340 && islastnewspage != 1) {
					currentttnewspage = currentttnewspage + 1;
					//alert('http://bs.dev.afm-koeln.de/index.php?id='+$.getUrlVar('id')+'tx_ttnews[pointer]='+currentttnewspage);
					//alert('XXXXXXX');
					//var byName = $.getUrlVar('name');
					//newpageurl = 'index.php?id='+jQuery.getUrlVar('id')+'&tx_ttnews[pointer]='+currentttnewspage;
					//newpageurl = 'index.php?id=7&tx_ttnews[pointer]='+currentttnewspage+'&no_cache=1';
					newpageurl = 'index.php?id='+jQuery.getUrlVar('id')+'&tx_ttnews[pointer]='+currentttnewspage+'&no_cache=1';
					
					sl_changettnewsPage( newpageurl );
				}*/
				/* jQuery('#slider').slider({
					min: -180,
					max: 180,
					value: 0
				}); */
				hideAllElements(jQuery(this));
				
				jQuery('.ring li').each(function(index) {
					if ( jQuery(this).width() > 250 ) {
						currentChild = index;
					}
				});
				//alert(currentChild);
			});
		}
        jQuery(document).ready(function() {
          jQuery("#stage").css("width","950");
          //jQuery("#stage").css("width","1000");
          jQuery("#rotate").css("width","1000");
          jQuery(".ring").css("width","1000");
          /*jQuery('ul.ring').roundabout({
             minOpacity: 1, // invisible!
             minScale: 0, // tiny!
             clickToFocus: false
             //childSelector: '.ring div.news-list-item'
          });*/
          inithtml5();
		  
			if ( jQuery('.news-list-browse span:last a').size() == 0 ) {
				islastnewspage = 1;
			} else {
				islastnewspage = 0;
			}
		  
		  sl_updateZeitstrahl();
          
          doSlider();
		  
		  hideTooSmallEntries();
		  
		  fixIE78();
        });
      }


/*------------------------------------------
         TT_News AJAX pagebrowser
-------------------------------------------*/



jQuery(document).ready(function(){
	
	// ajax pagebrowser
	jQuery(".news-list-browse a,.tx-ttnews-browsebox a").live("click", function(){
	
		url = jQuery(this).attr("href");
		/*url.replace(/http:\/\/bs.dev.afm-koeln.de/, ''); */
		sl_changettnewsPage( url );
		
		//alert( url );
		//alert( weburl );
		
		//fillupttnews();
		//alert('XXXXXX');
		changeTtnewsBrowserPos();
		
		if(saf){
			sc_elements = new Array( );
			jQuery('.ring li').each(function(index) {
				sc_elements.push( jQuery(this).attr('id') );
			});
			//alert(sc_elements.length);
			//const RING_RADIUS = ((sc_elements.length * 250 ) / 3.14156298 ) /2;
			RING_RADIUS = ((sc_elements.length * 250 ) / 3.14156298 ) /2;
			cnt = 1;
			init();
		} else {
			hideTooSmallEntries();
		}
		
		var ua = jQuery.browser;
		if (ua.msie && ( ua.version.slice(0,1) == '8' || ua.version.slice(0,1) == '7' )) {
			/*jQuery('ul#news-listteaser li').cornerz({
				radius: 18,
				corners: "tl tr",
				background: "transparent"
			});*/
			jQuery('#rotate .ring li').cornerz({
				radius: 18,
				corners: "tr bl br",
				background: "transparent"
			});
		}
		
		//changeTtnewsBrowserPos();
		/*newsContainer = jQuery(this).closest(".news-list-ajax");
		newsContainer.fadeTo("slow", 0.33);
		jQuery.ajax({
			type: "POST",
			dataType: "html",
			data: ({
				eID: 'ttnews_ajaxpagebrowser_ajaxHandler',
				todo: 'pagebrowser',
				href: escape(jQuery(this).attr("href")),
				part: newsContainer.attr("id")
			}),
			success: function(data){
				newsContainer.html(data);
				newsContainer.fadeTo("slow", 1.0);
				// scroll to top
				window.location.hash = '#' + newsContainer.attr("id");
				
				inithtml5();
		  
			}
		});*/
		return false;
	});

	
	changeTtnewsBrowserPos();
	
	// handle urls like "news.html#browse:2 to load initial page
	/*if(window.location.hash) {
		hash = window.location.hash.split(":");
		if(hash[0] == 'browse' && hash[1]) {
			//TODO
		}
	}*/
	
	
	
});


/*------------------------------------------
         TT_News AJAX newsteaser
-------------------------------------------*/
function hideAllElements(clickedElement) {
	jQuery('#socials div.facebook').not(clickedElement).stop();
	jQuery('#socials div.facebook').not(clickedElement).animate({
		height: '34'
	}, 500, function() {
		// Animation complete.
	});
	
	jQuery('#teasernewshome ul li').not(clickedElement).stop();
	jQuery('#teasernewshome ul li').not(clickedElement).animate({
		height: '62'
	}, 500, function() {
		jQuery(this).children('a, p.footer').not('.upbutton, #teasernewshome ul li p.footer a').hide();
		jQuery(this).children('.upbutton').show();
		// Animation complete.
	});

	jQuery('#nav ul li ul.ueber').not(clickedElement).stop();
	jQuery('#nav ul li ul.ueber').not(clickedElement).animate({
		height: '0'
	}, 500, function() {
		// Animation complete.
	});
}

jQuery(document).ready(function(){
	jQuery('#teasernewshome ul li').bind('click', function() {
		if (jQuery(this).height() < 130) {
			//alert(jQuery(this).text());
			jQuery(this).animate({
				height: '130'
			}, 500, function() {
				jQuery(this).children('a, p.footer').not('.upbutton, #teasernewshome ul li p.footer a').show();
				jQuery(this).children('.upbutton').hide();
				
				jQuery(this).children('.upbutton')
				ET_Event.click('Teaser: '+jQuery(this).children('h2').text(), 'Teaser');
				// Animation complete.
			});
		} else {
			jQuery(this).animate({
				height: '62'
			}, 500, function() {
				jQuery(this).children('a, p.footer').not('.upbutton, #teasernewshome ul li p.footer a').hide();
				jQuery(this).children('.upbutton').show();
				// Animation complete.
			});
		}
	});
	
	var ua = jQuery.browser;
	if ( !ua.msie && !saf ) {
		jQuery('body').not('.popuppage').bind('mousewheel', function(event, delta) {
			//alert('test');
			var dir = delta > 0 ? 'up' : 'down';
			vel = Math.abs(delta);
			//jQuery(this).text(dir + ' at a velocity of ' + vel);
			
			if (dir == 'up') {
				if ( currentChild < jQuery('.ring li').length - 1 ) {
					currentChild = currentChild + 1;
					jQuery('.ring').roundabout_animateToChild(currentChild);
				}
				//jQuery('.ring').roundabout_setBearing(delta * -1);
			} else {
				if ( currentChild > 0 ) {
					currentChild = currentChild - 1;
					jQuery('.ring').roundabout_animateToChild(currentChild);
				}
			}
			//alert( jQuery('.ring').data('roundabout' ).bearing );
			//jQuery('#slider').slider("value",  );
			
			var timer = setInterval( mousewheelSlider, 100);
			counter = 0;
			function mousewheelSlider() {
				if (counter <= 6) {
					counter++;
					jQuery( "#slider" ).slider( "option", "value", jQuery('.ring').data('roundabout' ).bearing * -1 ); // reset slider
					hideTooSmallEntries();
					fixIE78();
				} else {
					clearInterval(timer);
				}
			}
			
			return false;
		});
		/*jQuery(document).everyTime(1000, function() {
			jQuery( "#slider" ).slider( "option", "value", jQuery('.ring').data('roundabout' ).bearing * -1 ); // reset slider
			fixIE78();
		}, 0);*/
	}
	jQuery('.ring').bind('focus', function(event) {
		jQuery( "#slider" ).slider( "option", "value", jQuery('.ring').data('roundabout' ).bearing * -1 ); // reset slider
		hideTooSmallEntries();
		fixIE78();
		//alert('xxxxxxxxxx');
	});
	
	//jQuery('#teasernewshome ul li, ul.ring li a, #socials div.facebook, #nav ul li a.ueber, #nav ul li ul.ueber li a[target!=_self]').bind('mouseover', function() {
	/* jQuery('#teasernewshome ul li, ul.ring li a, #socials div.facebook').bind('mouseover', function() {
		hideAllElements(jQuery(this));
	}); */
	jQuery('.ui-slider-handle, #teasernewshome ul li, ul.ring li a, #socials div.facebook').bind('click', function() {
		hideAllElements(jQuery(this));
	});
	
	/* social teaser tabs */
	jQuery('#socials div.facebook').bind('click', function() {
		if (jQuery(this).height() < 350) {
			//alert(jQuery(this).text());
			//var ua = jQuery.browser;
			//if (ua.msie) {
			//	facebookheight = '360';
			//} else {
				facebookheight = '412';
			//}
			jQuery(this).animate({
				height: facebookheight
			}, 500, function() {
				FB.init({xfbml : true});
				
				ET_Event.click('Facebook', '');
				// Animation complete.
			});
		} else {
			jQuery(this).animate({
				height: '34'
			}, 500, function() {
				// Animation complete.
			});
		}
	});
	
	/* main menu */
	jQuery('#nav ul li ul.ueber li a[target!=_self]').bind('click', function() {
			jQuery('#nav ul li ul.ueber').animate({
				height: '0'
			}, 500, function() {
				// Animation complete.
			});
		//return false;
	});
	//jQuery('#nav ul li a.ueber').bind('mouseover', function() {
	jQuery('#nav ul li ul.ueber').bind('mouseout', function() {
		//jQuery('#nav ul li ul.ueber').css('height',50);
		/* jQuery('#nav ul li ul.ueber').animate({
				height: '0'
			}, 500, function() {
				// Animation complete.
			}); */
	});
	jQuery('#nav ul li.uebermich').bind('mouseenter', function() {
		jQuery('#nav ul li ul.ueber').stop();
		if (jQuery('#nav ul li ul.ueber').height() < 45) {
			//alert(jQuery(this).text());
			jQuery('#nav ul li ul.ueber').animate({
				height: '50'
			}, 500, function() {
				// Animation complete.
			});
		} else {
			/*jQuery('#nav ul li ul.ueber').animate({
				height: '0'
			}, 500, function() {
				// Animation complete.
			});*/
		}
		return false;
	});
	jQuery('#nav ul li.uebermich').bind('mouseleave', function() {
		jQuery('#nav ul li ul.ueber').stop();
		jQuery('#nav ul li ul.ueber').animate({
			height: '0'
		}, 500, function() {
			// Animation complete.
		});
	});
	jQuery('#nav ul li.uebermich a.ueber').bind('click', function() {
		return false;
	});
	
	
	jQuery('#teasernewshome ul li a, #teasernewshome ul li p.footer').not('#teasernewshome ul li p.footer a').hide();
	jQuery('#teasernewshome ul li p.footer').after('<img src="/fileadmin/template/images/home/teaser_button_up.gif" class="upbutton" />');
	//jQuery('#teasernewshome ul li').content( jQuery('#teasernewshome ul li').content()+'' );
	var teaserposition = 0;
	var teaserpositionoffset = 18;
	jQuery('#teasernewshome ul li').each(function(index) {
		var teaserwidth = jQuery(this).width();
		jQuery(this).css('left', teaserposition * teaserwidth + teaserpositionoffset);
		teaserpositionoffset = teaserpositionoffset + 1;
		
		
		
		teaserposition = teaserposition + 1;
	});
	
	iscontentpage = 0;
	/* popupwindow for content pages */
	if ( jQuery('#col1_content .news-single-item').length < 1 && jQuery('body.popuppage').length > 0 ) {
		jQuery('.outer-scrollbox').before( '<div class="news_single_date">&nbsp;</div><h1>'+jQuery('body.popuppage h1').text()+'</h1>' );
		/* jQuery('.inner-scrollbox #col1_content .csc-header-n1').remove(); */
		jQuery('body.popuppage .inner-scrollbox #col1_content h1').remove();
		
		iscontentpage = 1;
	}
	
	/*news popupwindow youtube videos*/
	if ( jQuery('body.popuppage .inner-scrollbox embed').length >= 1 ) {
		jQuery('.shareliketweet #tweet').after('<div id="youtubelink"><a href="http://www.youtube.com/user/BastianSchw1984" onclick="ET_Event.link(\'Youtube\', \'\')" target="_blank"><img src="/fileadmin/template/images/home/youtube-kanal.jpg" /></a></div>');
	}
	
	
	/* popupwindow fussballtabelle special style */
	if ( jQuery('body.popuppage .fussballtabelle').length >= 1 ) {
		jQuery('body.popuppage .inner-scrollbox').css('padding', '0 6px 0 0');
		jQuery('body.popuppage .shareliketweet').css('padding-left', '12px');
	}
	
	
	/*news popupwindow gallery*/
	var imagecount = jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow').length;
	var contentcount = jQuery('body.popuppage .inner-scrollbox .csc-default').length;
	var imagevisible = 0;
	
	//imagegallerymaxH = 370;
	imagegallerymaxH = 365;
	//imagegallerymaxW = 490;
	imagegallerymaxW = 518;
	
	if ( imagecount > 1 && ( contentcount <= 1 || iscontentpage == 0) ) { // if the image content element has more then 1 image and only 1 content element is present or it is a news page.
		jQuery('body.popuppage').addClass('imagegalerie');
	
		jQuery('.csc-textpic-equalheight .csc-textpic-imagerow').css('margin-bottom',0); // fix jumping images in galery
		
		
		//jQuery('body.popuppage .page_margins').css('background-color', '#505050');
	
		jQuery('body.popuppage .inner-scrollbox').before('<style type="text/css">body.popuppage .news_single_date{background-color:#000; background-image:url(/fileadmin/template/images/popupgalerie_close.png);} body.popuppage h1{background-color:#000;} body.popuppage .inner-scrollbox .csc-textpic-imagewrap{margin-left: 0 !important;} #prev{float:left; height:100%; background-color:#000;}#next{float:right; height:100%; background-color:#000;}</style><a href="#prev" id="prev"><img src="/fileadmin/template/images/galerie_left.png"  alt="Bild zurück" /></a>');
		jQuery('body.popuppage .inner-scrollbox').after('<a href="#next" id="next"><img src="/fileadmin/template/images/galerie_right.png" alt="Bild weiter" /></a>');
		
		//jQuery('body.popuppage .inner-scrollbox .csc-textpic-imagewrap').css('margin-left','0');
		jQuery('body.popuppage .inner-scrollbox').css('float','left');
		jQuery('body.popuppage .inner-scrollbox').css('width',imagegallerymaxW+'px');
		jQuery('body.popuppage .inner-scrollbox').css('height',imagegallerymaxH+'px');
		
		jQuery('body.popuppage .outer-scrollbox').css('overflow','inherit');
	
		jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow ').not(':eq('+imagevisible+')').hide();
		jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:eq('+imagevisible+')').show();
		
		
		jQuery('body.popuppage .news_single_date').text('BILD '+(imagevisible+1)+' VON '+imagecount);
		
		// center too small images
		jQuery('body.popuppage .inner-scrollbox .csc-textpic-imagerow').each(function(index) {
			//alert( jQuery(this).children('ul').children('li').width() );
			currentimagewidth = jQuery(this).children('ul').children('li').children('img').attr('width');
			if ( currentimagewidth < imagegallerymaxW ) {
				imagegallerymargin = ( imagegallerymaxW / 2 ) - ( currentimagewidth / 2 );
				jQuery(this).css('margin-left', imagegallerymargin);
			}
		});
		
		// Bilduntertitel
		//jQuery('body.popuppage .inner-scrollbox p.bodytext').css('position','absolute');
		//jQuery('body.popuppage .inner-scrollbox p.bodytext').css('bottom','0');
		jQuery('body.popuppage .inner-scrollbox p.bodytext').css('line-height','1.1em');
		jQuery('body.popuppage .inner-scrollbox p.bodytext').css('margin-top','5px');
		/* jQuery('body.popuppage .inner-scrollbox p.bodytext').css('margin-bottom','3px'); */
		jQuery('body.popuppage .inner-scrollbox p.bodytext').css('margin-bottom','6px');
		jQuery('body.popuppage .inner-scrollbox p.bodytext').css('width','500px');
		jQuery('body.popuppage .inner-scrollbox p.bodytext').css('color','#AAAAAA');
		jQuery('body.popuppage .inner-scrollbox li.csc-textpic-image').css('height','355px');
		
		
		// remove comment and shareliketweet block
		jQuery('body.popuppage .inner-scrollbox .shareliketweet').remove();
		jQuery('body.popuppage .inner-scrollbox .kommentare').remove();
		
		jQuery('body.popuppage #prev').bind('click', function() {
			if (imagevisible > 0) {
				imagevisible = imagevisible - 1;
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow ').not(':eq('+imagevisible+')').hide();
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:eq('+imagevisible+')').show();
				//jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:visible').centerSL({top:0});
				jQuery('body.popuppage .news_single_date').text('BILD '+(imagevisible+1)+' VON '+imagecount);
			} else {
				imagevisible = imagecount-1;
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow ').not(':eq('+imagevisible+')').hide();
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:eq('+imagevisible+')').show();
				jQuery('body.popuppage .news_single_date').text('BILD '+(imagevisible+1)+' VON '+imagecount);
			}
			return false;
		});
		jQuery('body.popuppage #next').bind('click', function() {
			if (imagevisible < imagecount-1) {
				imagevisible = imagevisible + 1;
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow ').not(':eq('+imagevisible+')').hide();
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:eq('+imagevisible+')').show();
				//jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:visible').centerSL({top:0});
				jQuery('body.popuppage .news_single_date').text('BILD '+(imagevisible+1)+' VON '+imagecount);
			} else {
				imagevisible = 0;
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow ').not(':eq('+imagevisible+')').hide();
				jQuery('body.popuppage .inner-scrollbox .csc-textpic .csc-textpic-imagerow:eq('+imagevisible+')').show();
				jQuery('body.popuppage .news_single_date').text('BILD '+(imagevisible+1)+' VON '+imagecount);
			}
			return false;
		});
	}
	
	/* popupwindow image resizer */
	jQuery('body.popuppage a.lightbox').bind('click', function() {
		var bigimage = jQuery(this).attr('href');
		
		//var smallimage = jQuery(this).children('img').attr('src');
		/* alert(smallimage);
		alert(bigimage); */
		if ( jQuery(this).children('img').attr('src') != bigimage) {
			smallimage = jQuery(this).children('img').attr('src');
			jQuery(this).children('img').css('width','560px').css('height','auto');
			jQuery(this).children('img').attr('src',bigimage);
		} else {
			jQuery(this).children('img').css('width','auto').css('height','auto');
			jQuery(this).children('img').attr('src',smallimage);
		}
		return false;
	});
	
	
	/* put comments block to the correct place */
	if ( jQuery('body.popuppage').length > 0 && jQuery('body.popuppage .kommentare').length > 0 ) {
	
		jQuery('body.popuppage .inner-scrollbox').children(':last').after( jQuery('body.popuppage .kommentare').not('body.popuppage .inner-scrollbox .kommentare') );
		jQuery('body.popuppage .kommentare').not('body.popuppage .inner-scrollbox .kommentare').remove();
		
		// remove empty commentbox when no comments and comments are deactivated
		if ( jQuery('body.popuppage .kommentare .eingabe').length <= 0 && jQuery('body.popuppage .kommentare .ausgabe .entry').length <= 0 ) {
			jQuery('body.popuppage .kommentare').remove();
		} else {
			//alert('test');
			//putCommentFB();
		}
		
		
		
		//jQuery('body.popuppage #fb-root').innerHTML = '<fb:comments href="###ACTION_URL###" num_posts="4" width="555"></fb:comments>';
		//document.getElementById('fb-root').innerHTML = '<fb:comments href="###ACTION_URL###" num_posts="4" width="555"></fb:comments>';
		
	}
	
	/* all popup pages except gallerys */
	if ( jQuery('body.popuppage').length > 0 && imagecount <= 1 ) {
		if ( jQuery('body.popuppage h1').height() > 50 ) {
			jQuery('body.popuppage .outer-scrollbox').css('height', 360);
		}
		
		jQuery('.outer-scrollbox').jScrollPane({autoReinitialise: true});
		
	}
	
	/* all popup pages !!! */
	if ( jQuery('body.popuppage').length > 0 ) {
		isInIFrame = (window.location != window.parent.location) ? true : false;
		
		if ( !isInIFrame ) {
			pageid = jQuery.getUrlVar('id');
			newsid = jQuery.getUrlVar('tx_ttnews[tt_news]');
			window.location = domain+'index.php?id=7&box='+pageid+'&news='+newsid;
		}
	}
	
	
	// Open Lightbox window from parameters
	if ( typeof jQuery.getUrlVar('box') != 'undefined' ) {
		//TopUp.display('http://bs.dev.afm-koeln.de/index.php?id=286&no_cache=1&tx_ttnews[tt_news]=89', topupOptions);
		box = jQuery.getUrlVar('box');
		newsid = jQuery.getUrlVar('news');
		TopUp.display(domain+'index.php?id='+box+'&no_cache=1&tx_ttnews[tt_news]='+newsid+'', topupOptions);
	}
	//&box=286&news=89
	
	
});



