// variable für engagement -> unesco-biosphärenreservate (es gibt 4 dynamische elemente, die ausgefahren werden)
var fragen_var = 4;
var blogkachel;
var randomKachel = Math.ceil(Math.random()*3);
  
$(document).ready(function(){
  //scrollpane wird initialisiert
  if (!$('#content_left').hasClass('noscroll')){
    $('#scroll-area').jScrollPane({
      showArrows:true,
      scrollbarWidth: 17,
      animateTo:true,
      animateInterval:10,
      animateStep:10
    });
  }
		
  //jede frage unter engagement -> unesco-biosphärenreservate bekommt einen hover-effekt
  $('.engagement_fragen').each(function(){
    $(this).bind('mouseover', function(){
      $(this).css('color','#1BBBEA');
    });
  });

  kachelstart();

  //jede frage unter engagement -> unesco-biosphärenreservate bekommt einen hover-effekt
  $('.engagement_fragen').each(function(){
    $(this).bind('mouseout', function(){
      if (!$(this).next().hasClass('engagement_opened') || $('#bio_karte').hasClass('bio_karte')){
        $(this).css('color','#707173');
      }
    });
  });
		
  //alle fragen unter engagement -> unesco-biosphärenreservate soll initial "eingefahren" sein, damit die scrollbar die größe berechnen kann
  for (var i=1; i <= fragen_var; i++){
    if ($('#fragen'+i).hasClass('engagement_initial')){
      document.getElementById('fragen'+i).className='engagement_closed';
      $('#fragen'+i).css("display","none");
    }
  }
		
  $('a.scroll-to-element').bind('click', function(){
    $this = $(this);
    var destinationSelector = $(this).attr('rel');
    $('#scroll-area')[0].scrollTo(destinationSelector);
    return false;
  });
		
  // presse function (aufruf)
  presse();
  //wenn man im bereich presse ist, soll eine 2. scrollbar initialisiert werden
		
  if (document.getElementById("presse_scroll-area")!=null){
    $('#presse_scroll-area').jScrollPane({
      showArrows:true,
      scrollbarWidth: 17,
      animateTo:true,
      animateInterval:10,
      animateStep:10
    });
  }
		
});

function kachelstart(){
    
  if(document.getElementById("start-kacheln")!=null){
    /*
      $.ajax({
        url: "/blog/blog-kachel/blog-kachel.php",
        dataType: "html",
        type: "POST",

        beforeSend: function() {
        },
        success: function(data, textStatus) {

          // Inhalt setzen
          if ( data ) {
            $("#menu281").css("width","284px");
            $("#menu281").css("padding-top","7px");
            $("#menu281").html('<div id="img281">'+data+'</div>');
          }
        },
        complete: function(XMLHttpRequest, textStatus) {
        }
      });
    */


$("#menu312").html('<a href="http://www.volvic.de/geniessen-und-gewinnen/?utm_source=volvicstartseite&utm_medium=aquadrinkskachel&utm_campaign=aquadrinkskachel" target="_self"><img  style="height:0px; width:142px;" id="img312" src="fileadmin/templates/_images/kacheln/Aqua_Drinks_Kreativwettbewerb.png" border="0" /></a>');        
    $("#menu311").html('<a href="http://www.volvic.de/1-glas-mehr!/?utm_source=volvicstartseite&utm_medium=einglasmehrkachel&utm_campaign=einglasmehrkachel" target="_blank"><img  style="height:0px; width:142px;" id="img311" src="fileadmin/templates/_images/kacheln/family_kachel.png" border="0" /></a>');    
    $("#menu299").html('<a href="http://www.volvic.de/engagement/" target="_blank"><img  style="height:0px; width:142px;" id="img299" src="fileadmin/templates/_images/kacheln/2010-10-28_engagiert.png" border="0" /></a>');
    //$("#menu308").html('<a href="http://www.volvic.de/trinkrechner/?utm_source=volvicstartseite&utm_medium=trinkrechnerkachel&utm_campaign=trinkrechnerkachel" target="_blank"><img  style="height:0px; width:142px;" id="img308" src="fileadmin/templates/_images/kacheln/15_04_2011_Trinkrechner_Kachel_gelb2.png" border="0" /></a>');    
    
    $("#menu310").css("width","284px");    
    $("#menu310").html('<iframe src="http://www.volvic.de/fileadmin/templates/volvic_facebook_kachel.html" allowtransparency="true" frameborder="0" style="width:290px; height:350px; background:transparent; position:relative; top:0px; left:0px;"></iframe>');        
    
    //$("#menu307").html('<a href="http://www.volvic.de/produkte/volvic-mit-fruchtgeschmack/"><img  style="height:0px; width:142px;" id="img307" src="fileadmin/templates/_images/kacheln/2011-03-22_neue_produkte.png" border="0" /></a>');    
    //$("#menu309").html('<a href="http://www.volvic.de/vulkan/" target="_blank"><img  style="height:0px; width:142px;" id="img309" src="fileadmin/templates/_images/kacheln/25_05_2011_Equity_Microsite_Kachel2.png" border="0" /></a>');
    
    window.setTimeout("showKachel('312')", 0);
    window.setTimeout("showKachel('311')", 500);
    window.setTimeout("showKachel('299')", 1000);    
    //window.setTimeout("showKachel('308')", 1000);    
    window.setTimeout("showKachel('310')", 1500);
  }
	
  /////////////Produkte MENU Konfiguration START

  var idgeschmack = '179';
  //var id1 = '53';
  var id2 = '54';
  var id3 = '55';

  $('#menu'+idgeschmack).parent('div').parent('li').children('strong').children('a').css("cursor","default");

  $('#menu'+idgeschmack).parent('div').parent('li').hover(
    function(){
      $(this).children('.menuContainer').css({
        'height':'auto',
        'width':'auto',
        'font-size':'12px',
        'text-align':'left',
        'top':'0px'
      });
      $(this).children('.menuContainer').html('<div id="produkte_menu"><div class="produkte_div">|&nbsp;&nbsp;&nbsp;'+
          //$('#menu'+id1).parent('div').parent('li').children('strong').html()+'</div><div class="produkte_div">|&nbsp;&nbsp;&nbsp;'+
          $('#menu'+id2).parent('div').parent('li').children('strong').html()+'</div><div class="produkte_div">'
          +'|&nbsp;&nbsp;&nbsp;' + $('#menu'+id3).parent('div').parent('li').children('strong').html()+'</div>'
          + '</div>');
      //$('#menu'+id1).parent('div').parent('li').hide();
      $('#menu'+id2).parent('div').parent('li').hide();
      $('#menu'+id3).parent('div').parent('li').hide();
      $(this).children('b').hide();
    },
    function(){
      //if ( $('#menu'+id1).parent('div').parent('li').hasClass('active') )$('#menu'+id1).parent('div').parent('li').show();
      if ( $('#menu'+id2).parent('div').parent('li').hasClass('active') )$('#menu'+id2).parent('div').parent('li').show();
      if ( $('#menu'+id3).parent('div').parent('li').hasClass('active') )$('#menu'+id3).parent('div').parent('li').show();
	    
      if (
        //$('#menu'+id1).parent('div').parent('li').hasClass('active') || 
        $('#menu'+id2).parent('div').parent('li').hasClass('active') 
        || $('#menu'+id3).parent('div').parent('li').hasClass('active')
        ){
        $(this).children('b').show();
      }
			
      $(this).children('.menuContainer').html('');
    });

  //if ( !$('#menu'+id1).parent('div').parent('li').hasClass('active') )$('#menu'+id1).parent('div').parent('li').hide();
  if ( !$('#menu'+id2).parent('div').parent('li').hasClass('active') )$('#menu'+id2).parent('div').parent('li').hide();
  if ( !$('#menu'+id3).parent('div').parent('li').hasClass('active') )$('#menu'+id3).parent('div').parent('li').hide();
  if (
    //!$('#menu'+id1).parent('div').parent('li').hasClass('active') && 
    !$('#menu'+id2).parent('div').parent('li').hasClass('active') 
    && !$('#menu'+id3).parent('div').parent('li').hasClass('active')
    ){
    $('#menu'+idgeschmack).parent('div').parent('li').children('b').hide();
  } else {
    $(
        //'#menu'+id1+','+
        '#menu'+id2+','
        +'#menu'+id3
    ).parent('div').parent('li').children('b').hide();
  }
	
/////////////Produkte MENU Konfiguration ENDE	
}

//suche ein-ausfahren

function resize(){
  var background = document.getElementById("background");

  if (window.innerHeight < 670){
    background.style.cssText="top:0px";
  } else {
    background.style.cssText="top:10%";
  }
}

//presse function, gilt für den presse bereich und das wasser-wiki
function presse(){
	
  // wenn man im wasser-wiki ist
  if (document.getElementById('wiki-template')!=null){
    var wiki=document.getElementById('wiki-template');
    destinationSelector=wiki.getAttribute('rel');
    if (document.getElementById('dyn_content_templ')!=null){
      $('.'+destinationSelector+' a').addClass("dyn_active");
    } else {
      if (document.getElementById('border-links')!=null){
        $('.'+destinationSelector+' a').css("color","#115992");
      } else {
        $('.'+destinationSelector+' a').css("color","#1BBBEA");
      }
    }
  }

  var presse;
  var sel;

  // wenn man in presse-bilder ist
  if (document.getElementById('presse_bilder')!=null){
    presse = document.getElementById('presse_bilder');
    sel = "bilder";
  }

  // wenn man in presse-pdf ist
  if (document.getElementById('presse_pdf')!=null){
    presse = document.getElementById('presse_pdf');
    sel = "pdf";
  }

  //wenn ein link "leer" ist, soll er dem link "ausgrauen"
  $('#presse_container a').each(function(){
    if ($(this).attr('href')==""){
      $(this).css("color","#e2e2e2");
      $(this).css("cursor","auto");
    }

  });

  if (presse!=null || wiki!=null){
    if (presse!=null){
      destinationSelector=presse.getAttribute('rel');
      year = destinationSelector.substring(0,2);
      $('#presse_20'+year).show();
      $('#scroll-area').jScrollPane();
      $('.'+destinationSelector+' .'+sel).css("color","#1BBBEA");
    }
    
    
    // SCROLLEN (darf nur wenn die scrollbar aktiv ist)
    if ($('#scroll-area').next().hasClass('jScrollPaneTrack')){
      //$('#scroll-area')[0].scrollTo('.'+destinationSelector);
      window.setTimeout("scrollTo('"+destinationSelector+"')",500);
    }
  }
}

function scrollTo(dest){
  $('#scroll-area')[0].scrollTo('.'+dest);
}

function toggleSuche() {
  
  $(document).ready(function(){
    // Blur-Killer
    $('#sucheToggle').blur();
    
    if( $('#suche-feld').hasClass('closed') ){
      $('#suche-feld').animate({
        width: 274+'px'
      }, 500);
    }
    
    if( $('#suche-feld').hasClass('opened') ){
      $('#suche-feld').animate({
        width: 0+'px'
      }, 500);
    }
    
    // Link aktualisieren  
    $('#suche-feld').toggleClass('opened');
    $('#suche-feld').toggleClass('closed');
  });
}

function karte(){
  if ($('#bio_karte').hasClass('bio_karte_no')){
    document.getElementById('bio_karte').className='bio_karte';
    $('#fragen5_click').css("color","#30b0e1");
  } else {
    document.getElementById('bio_karte').className='bio_karte_no';
    $('#fragen5_click').css("color","#797a7b");
  }
	
  for(var i=1; i <= fragen_var;i++){
    $('#fragen'+i+'_click').css("color","#797a7b");
    $('#fragen'+i).slideUp("slow");
    document.getElementById('fragen'+i).className='engagement_closed';
  }
  window.setTimeout("$('#scroll-area')[0].scrollTo('.fragen5_marker')", 1000);
}

function fragen(id) {
  marker = id;

  $(document).ready(function(){
    // Blur-Killer
    $('#'+id).blur();
 
    if( $('#'+id).hasClass('engagement_closed') ){
      for(var i=1; i <= fragen_var;i++){
        if (("fragen"+i)!=id){
          $('#fragen'+i+'_click').css("color","#797a7b");
          $('#fragen'+i).slideUp("slow");
          document.getElementById('fragen'+i).className='engagement_closed';
        }
      }
      document.getElementById('bio_karte').className='bio_karte_no';
      $('#fragen5_click').css("color","#797a7b");
      $('#'+id).slideDown("slow");

      $('#'+id+'_click').css("color","#30b0e1");
    }
    
    if( $('#'+id).hasClass('engagement_opened')){
      $('#'+id+'_click').css("color","#797a7b");
      $('#'+id).slideUp("slow");
    }

    // Link aktualisieren  
    $('#'+id).toggleClass('engagement_opened');
    $('#'+id).toggleClass('engagement_closed');
  });
 
  window.setTimeout("$('#scroll-area')[0].scrollTo('.'+marker+'_marker')", 1000);

}

function showKachel(menuid){	
  var hoehe = 345;

  if ( ($.browser.msie) && (jQuery.browser.version < 7 ) ){
    $('#img'+menuid).css('height','0px');
    $('#img'+menuid).animate({
      height: +hoehe+'px'
      }, 500);
  } else {
    $('#img'+menuid).css('height',hoehe+'px');
    $('#menu'+menuid).animate({
      height: +hoehe+'px'
      }, 500);
  }
}

function hideKachel(menuid){
  if(document.getElementById("start-kacheln")==null){
    $('#'+menuid).stop();

    $('#'+menuid).animate({
      height: 0+'px'
    }, 500);
  }
}
