/*
 * 
 */

function flash_detection(required) 
{
	max = 9;
  	var required_version = required;
  	var max_version = max;
  	var available_version = 0;
 
  	if (typeof (navigator.plugins["Shockwave Flash"]) == "object") 
	{
    	var description = navigator.plugins["Shockwave Flash"].description;
    	available_version = description.substr(16, (description.indexOf(".", 16) - 16));
  	}
  	else  
  	{
  		if (typeof (ActiveXObject) == "function") 
	  	{
    		for(var i = 2; i < (max_version + 1); i ++) 
      			try {
        			if(typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i)) == "object")
          				available_version = i;
      			}
      		catch(error) {}
	  	}
  	}
 
  	if(available_version == 0)
    	return 0;  // no flash
    	
  	if(available_version < required)
    	return 1;  // version zu alt

	return 2;  // ok
} // end function flash_detection(required) 

$(function(){
	ProductMenu.init();
	Flash.init();
	Cufon.replace('h1, h2');
	var sendafriedOn = false;
	
	var sendafriend_url = document.location.href;
	sendafriend_url = sendafriend_url.replace('&module[sendafriend]=send');
	$('#field-sendafriend-url').attr("value", sendafriend_url);
	
/* sendafriend-div auf und zu klappen */
	if($('#sendafriend').css('display') == 'block') {
		sendafriedOn = true;
	}
	$('#sendafriend-close').click(function(event){
		$('#sendafriend').fadeOut(300);
		event.preventDefault();
		sendafriedOn = false;	
	});
	$('.sed-to-friend a').click(function(event){
		//console.log( $('#sendafriend').css('display') );
		if(sendafriedOn == false) {
			$('#sendafriend').fadeIn(300);
			$('html').animate({scrollTop: ($('html').outerHeight()+650)});
			event.preventDefault();
			sendafriedOn = true;
		}
		else {
			$('#sendafriend').fadeOut(300);
			event.preventDefault();
			sendafriedOn = false;
		}
	});
	/*
	 * wenn weiterempfehlen abgeschickt
	 */
	if($('#if_send').val() == 'send')
	{
		$('#sendafriend').show(0);
		$('html').animate({scrollTop: ($('html').outerHeight()+650)});
	}


/* land-auswahl bei katalog-bestellung */	
	$('#katalog-country-select').change(function () {
    	var str = "";
        $("select option:selected").each(function () {
        	str = $(this).val();
		});
		
		if(str == "other") {
			$("#field-country_txt").show();
		} else {
			$("#field-country_txt").val("");
			$("#field-country_txt").hide();
		}
			
	}).change();

/*Media Galerie und Lightbox */
	$('.media-galerie').jcarousel();
	$('.media-galerie a').lightBox( { fixedNavigation:true } );
	
/*Accordion f�r Pressemeldungen */
//$(".year-news").accordion({header: 'h2'});
$('.year-news').each(function(i){
	$('.year-news:eq(0) dl').show(0);	
});

$('.year-news h2').click(function(){
		Effects.accordion("year-news", this);	   
});

/* Accordion fuer Messekalender */
/*
 * Show first content 
 */
$('span.exhibitionimg').hide(); // 
$('.exhibition.first p, .quality-details p:eq(0)').show(0);
var firstImage = $('.exhibition.first').find('span.exhibitionimg').text();

if(firstImage != '0')
{
	$('.exhibition.first').prepend('<img src="'+firstImage+'" class="exhibitionimg" />');
}
//
$('.exhibition h2').click(function(){
		Effects.accordion("exhibition", this);
});





/* Accordion fuer Qualitaet im Detail */
$('.quality-details h2').click(function(){
	Effects.accordion("quality-details", this);	   
});

/* Accordion fuer Qualitaet im Detail */
$('.acc-details h2').click(function(){
	Effects.accordion("acc-details", this);	   
});





/*Product Menu*/



$(".product-menu a").bind("click", function(){
	
	ProductMenu.open();
	return false;	
});


//$(".main-navigation li:not(li.product-menu)").bind("mouseover", function(){	
/*$(".main-navigation li a:not(li.product-menu a)").bind("mouseover", function(){
	ProductMenu.close();


});*/
	

/*
 * 
 */

if(flash_detection(9) == 0) 
{
	
	var imgfile = $('#flash_content').css("background-image");
	imgfile = imgfile.replace('url(','');
	imgfile = imgfile.replace(')','');
	//alert( imgfile );
	
	var tmp_img = '<div id="header_clip"><img src="'+imgfile+'" id="img_noflash" alt="" /></div>';
	

	$('#flash_content').html(tmp_img);
	$('#img_noflash').css({
		'width':'100%'	
	});
	
	$('#header_clip').css({
		'width': '100%',
		'position':'absolute',
		'clip':'rect(0 auto 559px 0)',
		'height':'440px'
	});
}


	// alert($('.product_preview_img').attr('rel'));

	$('img.reflect').reflect({height: 0.3, opacity: 0.5});
	
	//alert( $('#header-swf').height() );
	
	
	if ($.browser.msie == true) {
		$('#sendafriend .form_border').css ({
			'border':'0px solid #ff0000',
			'margin-top': '-31px'
		});
	}
	
	
});
//window.onload = Cufon.replace('h1, h2');


function newContentStyle() {

	if($.browser.msie == false || ($.browser.msie == true && $.browser.version != '6.0')) {
		
		$(".top-menue-teaser").wrap('<div id="navi_border"></div>');
		// $("#page").wrapAll('<div id="page_inner"></div>');
		// $(".footer ul").wrapAll('<div id="footer_border"></div>');
		
		var pWidth 		= $(window).width();
		var pageWidth 	= $('#page').width();
		var left 		= ( ( pWidth - pageWidth ) / 2) ;
		var footerPosi  = $("#footer_border").position();
		
		//console.log(footerPosi.top);
		
		/*$('.footer').css ({
			'position':'relative',
			'width': pWidth+'px',
			'margin-left': '-'+left+'px',
			'background-repeat':'repeat-x'
		});
		
		$('.form_border').css({
			'margin-left': left+'px',
			'width': $("#footer_border").width()+'px'
		});*/
	
	}
		
	
	
}
/* Funktion um Header und Footer auf 100% Breite zu skalieren*/
/* 
$(function() {
	newContentStyle();
	$(window).resize(function(){
		newContentStyle();
	});
});
*/

/**
 * Zeichen begrenzen
 * 
 */
function productDownloadTeaserText (length)
{
	
	var l = (length != '' && length > 0) ? length : 25;

	$(".docs li a").each(function(i){
		var text = $(this).text();
		var text_length = text.length;
		var new_text = (text_length > l) ? text.substr(0, l)+' ...': text; 
		$(this).text(new_text);
		
	});
}
$(function() {
	productDownloadTeaserText (25);
});
