// JavaScript Document

//var open_obj = "";

var act_pane = 0;
var pane;
var opac;
var infobox_interval;
var infobox_count = 5; //Anzahl der Infoboxen auf der Seite

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title" style="text-align: left">' + (title && title.length ? '<b class="db">' + title + '</b></div><div id="tip7-title" style="text-align: right">' : '' ) + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
}



$(document).ready(function() {
	// put all your jQuery goodness in here.
	if($(".gallery_pics_link").length >=1)
	{
		
		
		$(".gallery_pics_link").fancybox({
  		 'overlayShow': true,
  		 'overlayOpacity': 0.75,
  		 'cyclic':true,
  		 'titlePosition' : 'inside',
	         'titleFormat': formatTitle

  		 });
  		 $(".product_gallery:gt(0)").css('display', 'none');
  		 
  	} 
	if($(".gallery_extra_image").length >=1)
	{
		$(".gallery_extra_image").parent().fancybox({
  		 'overlayShow': true,
  		 'overlayOpacity': 0.75
  		 });
  		 $(".gallery_extra_image").each(function(){
  		 	if (typeof $(this).attr('longdesc') == 'string') {
  		 		$(this).after('<span>'+$(this).attr('longdesc')+'</span>');
  		 	
  		 		$(this).parent().css({'float': $(this).css('float'), 'margin': $(this).css('margin-top')+' '+ $(this).css('margin-right')+' '+ $(this).css('margin-bottom')+' '+ $(this).css('margin-left') });
  		 	
  		 		$(this).css({'float':'none', 'margin': '0 0 5px 0', 'padding': '0', 'display':'block'});
  		 	}
  		 });
  	} 
	
	initHeight(); 
	leere_tooltips();
	
	if ($('.to_change').length > 0){ 
	$('.to_change h2:first').css('font-size','16px');
	var html = $('.to_change').html();
	$('.to_change').html(html.replace(/Category: (.+)/, ""));
	$('#news-1 h2').eq(1).hide();
	$('#hottest-news-1 h2').eq(1).hide();
	$('#news-1 .news-single-timedata').show().addClass('float_r').after('<br class="clearall" />').css('margin-bottom', '15px');
	var text = $('#news-1 .news-single-timedata').text();
	text = text.substr(0,10);
	$('#news-1 .news-single-timedata').html(text);
	}
	
	$('#footer li:last a').click(function(){
		window.print();
		return false;
	});
	
	
		                         
	

$('#main_navi').superfish({ 
            delay:       100,                            // one second delay on mouseout 
            animation:   {opacity:'show'},  // fade-in and slide-down animation 
            speed:       '220',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        }); 
  
  $('#main_navi .main_level2')
  .bgiframe()
  .hover(
      function(){
      $(this).prev().addClass('hover');
      },
      function(){
      $(this).prev().removeClass('hover');
      }
  )
  ;
  
      if($("#infobox_outer").length >=1) {
  	// --- Flashersatz ---
  	//prüfen wieviele Panes es gibt?
  	for(i=0;i<5;i++){
  		if(!isPaneEmpty(i)){
  			$("#l"+i).parent().css("visibility", "visible");
  		} else {
  			infobox_count = i;
  			break;
  		}
  	}
  	
  	//switch panes automatically
	infobox_interval = setInterval("box_rotate()", 10000);
	
	//switch panes manually
	$("#l0, #l1, #l2, #l3, #l4").click(function(){
        var pane = parseInt($(this).attr("id").substr(1,1));
        window.clearInterval(infobox_interval);
        infobox_interval = "inactive";
		$(".go-btn").css("background-position", "-97px -100px");
        if (pane != act_pane) {
			switchoff(pane);
			act_pane = pane;
        }
        return false;
	});
	
	//start animation
	$("#start_ani").click(function(){
		if (infobox_interval == "inactive") {
			box_rotate();
			$(".go-btn").css("background-position", "-97px -100px");
			infobox_interval = window.setInterval("box_rotate()", 10000);
		} else {
            window.clearInterval(infobox_interval);
			infobox_interval = "inactive";
			$(".go-btn").css("background-position", "-97px -50px");
		}
		return false;
	});
      }
  

});



function initHeight(){
	
	var hoehe = 0;	
	$('#content img').each (function(i){
  		 hoehe += $(this).height();
		 });
	
	if ($('#navigation_inner').height() < $('#marginal').height()){
		$('#navigation_inner').css('height', $('#marginal').height()-34);		
	}
}





function change_bigImg (path,title){	
	ge('karte').style.display = 'block';
	ge('large_img').src = path;
	ge('bigImgTitle').innerHTML = title;
}

function tool_tip(title,text){
	if (title !='')	{
	 var title =	'<h2>' + title + '</h2>';
	}
	var tooltip = '<div class=\'tooltip\'><div style="padding:10px 10px 20px 10px;">'+ title +  text + ' </div></div><div class=\'tooltip_footer\'></div>';
	//return overlib(tooltip , LEFT,10 , ABOVE, 0, FULLHTML);
}

function leere_tooltips () {
	var alle =document.getElementsByTagName("acronym");
	for (var i=0;i<alle.length;i++){
		alle[i].title='';
	}
	var ules = document.getElementsByTagName("ul");
	for (var j=0;j<ules.length;j++){
		if (ules[j].className == 'sitemap_L_3'){
			ules[j].style.display = 'none';
		}
	}
}


function toggleBox(elementId) {
	if (ge(elementId) ) {
		if (ge(elementId).style.display == 'none')  {
			ge(elementId).style.display = 'block';
			ge(elementId+'_img').src="static/img/icon_minus.gif";
			ge(elementId+'_link').removeAttribute("class");
			ge(elementId+'_link').setAttribute("class", "bold" );
		} else {
			ge(elementId).style.display = 'none';
			ge(elementId + '_img').src="static/img/icon_plus.gif";
			ge(elementId+'_link').removeAttribute("class");
			ge(elementId+'_link').setAttribute("class", "" );
		}
	}
}

function handleForm(){
        if (document.getElementById('name').value.length<2){
                document.getElementById('submitter').disabled = true;
                return false;
        }
        // Email null ?
        email = document.getElementById('email');
        if (email.value.length<2 || email.value.indexOf('@')==-1 || email.value.indexOf('.')==-1){
                document.getElementById('submitter').disabled = true;
                return false;
        }
        // Anliegen null ?
        if (document.getElementById('text').value.length<10){
                document.getElementById('submitter').disabled = true;
                return false;
        }
        document.getElementById('submitter').disabled = false;
        return true;
}
function sendForm(){
    document.forms['formulario'].action = "contact.php";        
}
function reduceAttributes(){
	var aFirst = new Array("focussing","collimating","KB-mirrors","Bragg-Brentano","Cu","Co","Cr","Mo","Fe","Ag","Ti");
	var aSecond = new Array("High Flux","focussing","collimating","low divergence","Cu","Co","Cr","Mo","Fe","Ag","Ti");
	var aThird =  new Array("Analyzer Crystal","Monochromator");
	var aFourth = new Array("Multi Stripes","Long Length");
	var ret = "";
	value = $('#anwendung').val();
	ret = $('#anwendung option:selected').attr("class");
	if(ret=="diff" || ret=="hrd" ||ret=="reflect" ||ret=="screening" ){
		ge('eigenschaft').innerHTML = buildOptions(aFirst);
	}
	else if(ret=="scd" || ret=="pc" ||ret=="sac" ||ret=="smo" ||ret=="fsd" ||ret=="lps" ||ret=="trd" ||ret=="cc" || ret=="pi" ||ret=="scr" ){
		ge('eigenschaft').innerHTML = buildOptions(aSecond);
	}
	else if(ret=="wdx" ||ret=="ba" ||ret=="ca" || ret=="le" || ret=="txr" ){
		ge('eigenschaft').innerHTML = buildOptions(aThird);
	}
	else if(ret=="mo" || ret=="tro" || ret=="cam" || ret=="mm"){
		ge('eigenschaft').innerHTML = buildOptions(aFourth);
	}
	else{
		ge('eigenschaft').innerHTML = buildOptions("");
	}
}

function buildOptions(arr){
	top = arr.length;
	ret = "";
	for(i=0;i<top;i++){
		ret+='<option value="'+arr[i]+'">'+arr[i]+'</option>';
	}
	return ret;
}


/* Flashersatz fuer Startseite */
function box_rotate() {
	act_pane = (act_pane+1) % infobox_count;
	switchoff(act_pane);
}
function switchoff(elem) {
	if ($.browser.msie == true && $.browser.version == "6.0") {
		$(".infobox:visible").stop().css("display", "none");
		show_pane(elem);
	} else {
		$(".infobox:visible").stop().animate({
			opacity: 0}, 1000, function(){
				$(this).css("display", "none");
				$(this).css("opacity", "1");
				show_pane(elem);
			}
		);
	}
}
function show_pane(elem){
	$("#infobox_"+elem).fadeIn("slow");
}
/* checken ob ein Pane leer ist (kein Bild & Text) */
function isPaneEmpty(pane){
	if(($("#infobox_img_"+pane).html().length) == 0){
		return true;
	} else {
		return false;
	}
}