//-----------------------------------------------
// Beim Laden der Seite Container zentrieren
//-----------------------------------------------
 jQuery.noConflict();
  jQuery(document).ready(function(){
    //setCenter('#wrapper'); 
	if(isHome){
		changeBG();
		setRowsByMaxHeight();
		//rotateTeaserBoxes();
	}
	onHover('.teaser-box', ["css",'background-color','#eee'], ["css",'background-color','#fff']);
	openDialog('.search', '#dialog', 472, 480, false, false, false);
	jQuery("#synonyme ul").collapsorz({
		minimum: 3,
		showText: "mehr...",
		hideText: "",
		linkLocation: "after",
		defaultState: "collapsed"
	});
	jQuery("#synonyme").show();
	jQuery("#collaboration ul").collapsorz({
		minimum: 3,
		showText: "mehr...",
		hideText: "",
		linkLocation: "after",
		defaultState: "collapsed"
	});
	jQuery("#collaboration").show();
	jQuery("#tourdaten table").collapsorz({
		toggle: "tr",
		minimum: 6,
		showText: "mehr...",
		hideText: "zurück",
		linkLocation: "after",
		defaultState: "collapsed"
	});

    if(adbanner==1)
		setInterval("checkWallpaper(false)",250);
});

function rotateTeaserBoxes(){
	var totalCount=10;
	var num = Math.ceil(Math.random() * totalCount);
	if(num%2==0){
		jQuery('#gewinnspiel').show();
		jQuery('#genrelexikon').hide();
	}else{
		jQuery('#gewinnspiel').hide();
		jQuery('#genrelexikon').show();
	}
}

function toggleSubmenu(element) {
	var child = jQuery(element).parent().filter(':first').children('ul');
	if(jQuery(child[0]).is(':visible')) {
		jQuery(child[0]).slideUp();
	} else {
		jQuery(child[0]).slideDown();
		jQuery('li a',child[0]).mouseover(function(){
			jQuery(this).css('color','red');
		}).mouseout(function(){
			jQuery(this).css('color','#5a595e');
		});
	}
	jQuery('.nav > li').each(function(){
			if(jQuery(this).attr('class') != jQuery(element).parent().attr('class'))
				jQuery('ul',this).hide();
	});
}

function expandContainer(id, direction){
	/*if(direction==".more"){
		jQuery(id).animate( { height: '250px' }, 1500 );
		jQuery(id+" "+direction).hide();
		jQuery(id+" .back").show();
	}else if(direction==".back"){
		jQuery(id).animate( { height: '85px' }, 1500 );
		jQuery(id+" "+direction).hide();
		jQuery(id+" .more").show();
	}*/
	jQuery(id).collapsorz({
		minimum: 3,
		showText: "mehr...",
		hideText: "zurück",
		linkLocation: "after",
		defaultState: "collapsed"
	});
}

function closeDialog(selector){
	jQuery(selector).hide();
}

function openDialog(selector){
		
		jQuery('#sub-navi > div').each(function(){
			if(jQuery(this).attr('id') != jQuery(selector).attr('id'))
				jQuery(this).hide();
		});
		jQuery(selector).show();
}

function openSubMenu(selector){
	jQuery(selector+' ul.menu_body li:even').addClass('alt');
	jQuery(selector).click(function(){
		jQuery(selector+' ul.menu_body').slideToggle('medium');
		jQuery('.nav > li').each(function(){
			if(jQuery(this).attr('class') != jQuery(selector).attr('class'))
				jQuery('ul',this).hide();
		});
	});
	jQuery(selector+' ul.menu_body li a').mouseover(function(){
		jQuery(this).css('color','red');
	}).mouseout(function(){
		jQuery(this).css('color','#5a595e');
	});
}

//-----------------------------------------------
// Beim Veraendern der Fenstergroesze Container neu
// zentrieren
//-----------------------------------------------
jQuery(window).bind('resize', function(event) {
    //setCenter('#wrapper');  //Deine ID oder Klasse des Containers
	//if(adbanner==1)
		//checkWallpaper(true);
});
 
 function onHover(selector, add_attr, rm_attr){
	jQuery(selector).hover(
		function(){
			if(add_attr[0]=='class')
				jQuery(this).addClass(add_attr[1]);
			else if(add_attr[0]=='css')
				jQuery(this).css(add_attr[1],add_attr[2]);
		},
		function (){
			if(rm_attr[0]=='class')
				jQuery(this).removeClass(rm_attr[1]);
			else if(rm_attr[0]=='css')
				jQuery(this).css(rm_attr[1],rm_attr[2]);
		}
	);
 }

function setRowsByMaxHeight(){
//alert( parseInt(jQuery('.firstrow.fifth .content-box').height()));
		
    var max_first = Math.max(parseInt(jQuery('.firstrow.first .content-box').height()), parseInt(jQuery('.firstrow.second .content-box').height()), parseInt(jQuery('.firstrow.third .content-box').height()), parseInt(jQuery('.firstrow.fourth .content-box').height()), parseInt(jQuery('.firstrow.fifth .content-box').height()));
	var max_second = Math.max(parseInt(jQuery('.secondrow.first .content-box').height()), parseInt(jQuery('.secondrow.second .content-box').height()), parseInt(jQuery('.secondrow.third .content-box').height()), parseInt(jQuery('.secondrow.fourth .content-box').height()), parseInt(jQuery('.secondrow.fifth .content-box').height()));
	var max_third = Math.max(parseInt(jQuery('.thirdrow.first .content-box').height()), parseInt(jQuery('.thirdrow.second .content-box').height()), parseInt(jQuery('.thirdrow.third .content-box').height()), parseInt(jQuery('.thirdrow.fourth .content-box').height()), parseInt(jQuery('.thirdrow.fifth .content-box').height()));
	//alert( parseInt(jQuery('.firstrow.fifth .content-box').height()));
	//alert(max_first);
    jQuery('.firstrow.first .content-box').css('height', max_first+'px');
    jQuery('.firstrow.second .content-box').css('height', max_first+'px');
    jQuery('.firstrow.third .content-box').css('height', max_first+'px');
	jQuery('.firstrow.fourth .content-box').css('height', max_first+'px');
	//alert(max_first);
	jQuery('.firstrow.fifth .content-box').css('height', max_first+'px');
	jQuery('.secondrow.first .content-box').css('height', max_second+'px');
    jQuery('.secondrow.second .content-box').css('height', max_second+'px');
    jQuery('.secondrow.third .content-box').css('height', max_second+'px');
	jQuery('.secondrow.fourth .content-box').css('height', max_second+'px');
	jQuery('.secondrow.fifth .content-box').css('height', max_second+'px');
	jQuery('.thirdrow.first .content-box').css('height', max_third+'px');
    jQuery('.thirdrow.second .content-box').css('height', max_third+'px');
    jQuery('.thirdrow.third .content-box').css('height', max_third+'px');
	jQuery('.thirdrow.fourth .content-box').css('height', max_third+'px');
	jQuery('.thirdrow.fifth .content-box').css('height', max_third+'px');
	
}
 
//-----------------------------------------------
// Container vertikal zentrieren
//-----------------------------------------------
/*function VerticalCenter(elem) {
    var top=(jQuery(window).height() - jQuery(elem).height()) / 2;
    jQuery(elem).css('margin-top',top);
}*/
 
//-----------------------------------------------
// Container horizontal zentrieren
// (Alternativ ueber CSS -> margin: auto;)
//-----------------------------------------------
function HorizontalCenter(elem) {
    var left=(jQuery(window).width() - jQuery(elem).width()) / 2;
    jQuery(elem).css('left',left);
}
 
//------------------------------------------------
// Beides zentrieren
//------------------------------------------------
function setCenter(elem) {
    //VerticalCenter(elem);
    //HorizontalCenter(elem);
}

function changeBG(){
	jQuery('#top').delay(100).animate({
		'opacity': 1
	}, 2000, "swing", function(){
		jQuery(this).css('filter','');
	});
	jQuery('#middle').delay(100).animate({
		'opacity': 1
	}, 2000, "swing", function(){
		jQuery(this).css('filter','');
	});
	jQuery('#bottom').delay(100).animate({
		'opacity': 1
	}, 2000, "swing", function(){
		jQuery(this).css('filter','');
	});
}

function changeSearchArea(obj){
	document.search.searchwhere.value=obj.value;
	document.search.submit();
}

function checkWallpaper(resize)
{		
    
    if(jQuery(window).width()>925)
    {
    	jQuery('#wrapper').css("position","absolute");
		var wrapperleft = Math.round((jQuery(window).width() - (jQuery('#wrapper').width()+40)) / 2);
		jQuery('#wrapper').offset({left:wrapperleft});
	}else{
		jQuery('#wrapper').offset({left:0});
	}

	if (typeof(adtype) != 'undefined')
	{
		if (adtype == 'wallpaper')
		{
			// Schiebe Skyscraper rechtsbuendig an Leaderboard
			var wrapperwidth = jQuery('#wrapper').width();
			var superbannerwidth = jQuery('#superbanner-top').width();
			jQuery('#wrapper').offset({top:jQuery('#superbanner-top').height()});
			if(jQuery(window).width()>910){
				var superbannerleft = Math.round(((jQuery(window).width() - wrapperwidth) / 2) + (wrapperwidth-superbannerwidth));
				jQuery('#superbanner-top').offset({top:0,left:Math.round(((jQuery(window).width() - wrapperwidth) / 2)) + (wrapperwidth-superbannerwidth)});
				jQuery('#skyscraper').offset({ top: 0, left : (jQuery('#superbanner-top').width()+jQuery('#superbanner-top').offset().left)});
			}else{
				if(!resize){
					jQuery('#superbanner-top').offset({top:0,left:((wrapperwidth+20)-superbannerwidth)});
					jQuery('#skyscraper').offset({ top: 0, left : (jQuery('#superbanner-top').width()+jQuery('#superbanner-top').offset().left)});
				}
			}
		}
		if (adtype == 'expwallpaper')
		{
			// Schiebe Sky rechts unter das Leaderboard
			var wrapperwidth = jQuery('#wrapper').width();
			var superbannerwidth = jQuery('#superbanner-top').width();
			if(jQuery(window).width()>925)
				var superbannerleft = Math.round(((jQuery(window).width() - wrapperwidth) / 2)) + (wrapperwidth-(superbannerwidth-jQuery('#skyscraper').width()));
			else
				var superbannerleft = ((wrapperwidth+20)-(superbannerwidth-jQuery('#skyscraper').width()));
			jQuery('#wrapper').offset({top:jQuery('#superbanner-top').height()});
			jQuery('#superbanner-top').offset({top:0,left:superbannerleft});
			jQuery('#skyscraper').offset({ top: jQuery('#superbanner-top').height(), left : ((jQuery('#superbanner-top').width()+jQuery('#superbanner-top').offset().left)-jQuery('#skyscraper').width())});
		}
		if (adtype == 'expushape')
		{
			if(jQuery(window).width()>1125){
				var superdimensionsLeft = Math.round((jQuery(window).width() - jQuery('#superbanner-top').width()) / 2);
			}else{
				var superdimensionsLeft = 0;
				jQuery('#wrapper').offset({left:Math.round(((jQuery('#superbanner-top').width()- jQuery('#wrapper').width()-40)/2))});
			}
			var skyscraperleftwidth = jQuery('#skyscraperleft').width();
			var skyscraperleftoffsetleft = (skyscraperleftwidth+superdimensionsLeft);
			jQuery('#wrapper').offset({top:jQuery('#superbanner-top').height()});
			jQuery('#ushapefill').offset({top:jQuery('#superbanner-top').height, left:skyscraperleftoffsetleft});
			jQuery('#ushapefill').show();
			jQuery('#ushapefill').height((jQuery('#main').height()+102));
			
			jQuery('#superbanner-top').offset({top: 0,left:superdimensionsLeft});
			jQuery('#skyscraperleft').offset({ top:jQuery('#superbanner-top').height(), left:jQuery('#superbanner-top').offset().left});

			var skyscraperoffsetleft = ((jQuery('#superbanner-top').width()+jQuery('#superbanner-top').offset().left)-skyscraperleftwidth);
			jQuery('#skyscraper').offset({ top: jQuery('#superbanner-top').height(), left : skyscraperoffsetleft});
		}
	}else{
		var wrapperwidth = jQuery('#wrapper').width();
		var superbannerwidth = jQuery('img','#superbanner-top').width();
		var superbannerheight = jQuery('#superbanner-top').height();
		var superbannerLeft =Math.round((jQuery(window).width() - jQuery('#superbanner-top').width()) / 2);
		jQuery('#wrapper').offset({top:superbannerheight});
		jQuery('#superbanner-top').offset({top:0,left:(jQuery('#wrapper').offset().left+20)});
		jQuery('#skyscraper').offset({ top: superbannerheight, left : (jQuery('#wrapper').offset().left+jQuery('#wrapper').width()+20)});
	}
	if (typeof(bgcolor) != 'undefined' && bgcolor != null)
	{
		// Faerbe moegliche Bereiche ein
		jQuery('#mlbody').css("background-color",bgcolor);
		
		if (typeof(bgimage) != 'undefined' && bgimage != null)
		{
			// Setze Hintergrund Bild
			jQuery('#mlbody').css("background-image",bgimage);
		}
	}
	if (typeof(adclick) != 'undefined' && adclick != null)
	{
		// Verlinke bei Klick auf Hintergrund auf adclick
		jQuery('#bgclick-bg').show();
		jQuery('#bgclick-bg').css("width",jQuery(window).width());
		jQuery('#bgclick-bg').css("height",jQuery(window).height());
	}

	if(!visiblebanners){
		jQuery('#superbanner-top').css("visibility","visible");
		jQuery('#skyscraper').css("visibility","visible");
		jQuery('#skyscraperleft').css("visibility","visible");
	}
	var visiblebanners = true;

}

function changeIcon(obj, tag, state, icon){
	if(tag=='bg'){
		jQuery(obj).css('background-image',"url(/bilder/2012/"+state+"/"+icon+".png)");
	}else{
		jQuery(obj).attr('src',"/bilder/2012/"+state+"/"+icon+".png");
	}
}

function openVerlosung(Frage, identifier)
{
	link = document.getElementById("verlosung-link");
	return hs.htmlExpand(link, {
					objectType: 'iframe',
					width: 480,
					height: 431,
					src: '/de/verlosung?frage='+escape(Frage)+'&identifier='+identifier
					} );
}
function bannermp3playeropen(url)
{
	banner_fla_player_open = window.open(url,"Player","toolbar=yes,resizable=yes,directories=no,status=no,menubar=no,location=yes,locationbar=yes,scrollbars=yes");
	banner_fla_player_open.focus();
}
function getAndNullHREF(element)
{
	_this = element;
	url = _this.href;
	//_this.href = "";
	return url;
}

