heightCorrection = false;

/*
 * Prevent conflicts with MooTools
 */
jQuery.noConflict();

/*
 * NAVI
 */
function show(element) {
	element.className += "hover";
}

function hide(element) {
	element.className = element.className = "";
}

/*
 * BESCHREIBUNG
 */
function showToggleDesc() {

	genDesc = jQuery(".as_beschreibung_generated").html();
	apiDesc = jQuery(".as_beschreibung").html();
	
	if (genDesc != '' && apiDesc != '') {
	
		jQuery(".as_beschreibung_generated").html(apiDesc);
		jQuery(".as_beschreibung").html(genDesc);
	
		jQuery(".as_beschreibung_generated").toggle();
	
		// Height correction
		pageHeight = jQuery("#page").height();
		untenHeight = jQuery("#unten").height();
	
		if (heightCorrection) {
			if (!jQuery(".as_beschreibung_generated").is(":hidden")) {
				jQuery("#page").height(pageHeight + 450);
				jQuery("#unten").height(untenHeight + 450);
			} else {
				jQuery("#page").height(pageHeight - 450);
				jQuery("#unten").height(untenHeight - 450);
			}
		}
	}
}

jQuery(document).ready(function($){
	$('#as_beschreibung_generated').hide();
	$('.bg-kleine-bilder img').css({'visibility' : 'hidden'});

	$('#content_news_kat #teaser .ts_txt_headline').detach().prependTo('#content_news_kat');

//	$("#text_link").click(showToggleDesc);
	
	$("#text_link").click(function(){
		$('#as_beschreibung_generated').toggle('slideDown');
	});
	
	// Height correction
	subnaviHeight = $("#subnavi").height();
	pageHeight = $("#unten").height();
	
	if (subnaviHeight > pageHeight) {
		$("#page").height(subnaviHeight + 160);
		$("#unten").height(subnaviHeight + 10);
		heightCorrection = true;
	}
	
	$('.artikelseite .image_container img').wrap('<a href="' + $('.call_to_action a').attr('href') + '" rel="nofollow" target="_blank" />');
	
/*	$('.startseite .news-list-container a img').each(function(i,e){
		$(e).closest('a').attr('href', $(e).attr('title'));
	}); */
	
	$('.bg-kleine-bilder a').fadeTo(0, 0.75);
	
	$('.bg-kleine-bilder a').hover(function(){ $(this).stop(true).fadeTo(300, 1); }, function(){ $(this).stop(true).fadeTo(300, 0.75); });
	
	$('.bg-kleine-bilder img').animate({'opacity' : '0'}, 0);

	$('.bg-kleine-bilder img').load(function(){
		if ($(this).width() > $(this).height()) {
			$(this).css({'width' : '100%', 'height' : 'auto', 'position' : 'relative'});
			todoheight = $(this).closest('a').height();
			$(this).css('top', parseInt((todoheight - $(this).height()) / 2, 10) + 'px');
			$(this).css('left', '0px');
		}
		else
		{
			$(this).css({'width' : 'auto', 'height' : '100%', 'position' : 'relative'});
			todowidth = $(this).closest('a').width();
			$(this).css('left', parseInt((todowidth - $(this).width()) / 2, 10) + 'px');
			$(this).css('top', '0px');
		}
	});

	$('.galerie-links img').load(function(){
		if ($(this).width() > $(this).height()) {
			$(this).css({'width' : '100%', 'height' : 'auto', 'position' : 'relative'});
			todoheight = $(this).closest('a').height();
			$(this).css('top', parseInt((todoheight - $(this).height()) / 2, 10) + 'px');
		}
		else
		{
			$(this).css({'width' : 'auto', 'height' : '100%', 'position' : 'relative'});
			todowidth = $(this).closest('a').width();
			$(this).css('left', parseInt((todowidth - $(this).width()) / 2, 10) + 'px');
		}
	});

	$('.startseite .news-list-container .news-list-item').css('width', '150px');
	
	setInterval('check_for_size()', 500);
		
/*	$('.news-list-item:not(".haslike")').each(function(i,e){
		likebutton = $('<div class="fb-button" />');
		$(likebutton).html('<fb:like layout="button_count" show_faces="false" width="108" font="arial" href="http://shopping-papst.de/' + $(e).find('.ls_title').children('a').attr('href') + '"></fb:like>');
		$(e).append(likebutton);
	});
	
	var fbscript = document.createElement( 'script' );
	fbscript.type = 'text/javascript';
	fbscript.src = "http://connect.facebook.net/de_DE/all.js#xfbml=1";
	document.body.appendChild(fbscript); */
});


function check_for_size() {
	$ = jQuery;
	$('.bg-kleine-bilder img:not(".checked_for_size")').each(function(i,e){
		if ($(e).width() > $(e).height()) {
			$(e).css({'width' : '100%', 'height' : 'auto', 'position' : 'relative'});
			todoheight = $(e).closest('a').height();
			$(e).css('top', parseInt((todoheight - $(e).height()) / 2, 10) + 'px');
			$(e).css('left', '0px');
		}
		else
		{
			$(e).css({'width' : 'auto', 'height' : '100%', 'position' : 'relative'});
			todowidth = $(e).closest('a').width();
			$(e).css('left', parseInt((todowidth - $(e).width()) / 2, 10) + 'px');
			$(e).css('top', '0px');
		}
		if ($(e).hasClass('pre_checked_for_size'))
		{
			$(e).addClass('checked_for_size').removeClass('pre_checked_for_size');
		}
		else
		{
			$(e).addClass('pre_checked_for_size');
		}
		$(e).css('visibility', 'visible');
		$(e).animate({'opacity' : '1'}, 600);
	});
}


function show(element){

           element.className += "drop_oben";

   }

function hide(element){

           element.idName = element.className = "";

     }
	 
function showText(){

		alert('BUH!');
//         document.getElementById("as_beschreibung_generated").className = "anzeigen";
		jQuery('#as_beschreibung_generated').toggle();

   }

function hideText(element){
		alert('BUH!');
//           element.idName = element.className = "";

     }


