$(document).ready(function() {
  $('#slideshow .csc-textpic-imagerow').show();
  $('#slideshow').slideshow({
    timeout: 8000,
    fadetime: 2500
  });
  
  if($('li.artikel a:contains("Anmelden")').length > 0) {
	$('li.artikel a').attr('class', 'referenzBlock loginbutton');
	$('li.bilder').remove();
	$('li.artikel').width('220');	
};
  

  /*Presselounge box fix*/
  $('div.referenzen_wrapper:eq(2)').after('<br class="clear" />');
  
  
  $(".csc-textpic-image dt a[href$='.pdf']").attr('target','_blank');

  /*Presselouge*/
  /*$("div.left a.referenzBlock").click(function (event){
    var url = $("div.left a.referenzBlock").attr("href");
    var windowName = "popUp";//$(this).attr("name");
    window.open(url, windowName, 'height=900,width=850');
    event.preventDefault();
  });*/
  

  /*Ende*/
  
  
  $('#suchform').submit(function() {
    if($('.suchfeld',this).val()=='') {
      alert('Bitte geben Sie einen Suchbegriff ein.');
      return false;
    } else {
      return true;
    }
  });
  
  if($('.hauptnavigation li:last').hasClass('trenner')) {
    $('.hauptnavigation li:last').remove();
  }
  
  $('#suchform .suchfeld').focus(function() {
    $(this).addClass('active');
  });
  $('#suchform .suchfeld').blur(function() {
    $(this).removeClass('active');
  });

  if($('body.page_418').length) {
    $('.header .suche').html('<form method="post" enctype="multipart/form-data" action="index.php?id=418&amp;no_cache=1"><input type="submit" class="suchbutton" value="SUCHEN" name="submit"> <input type="text" class="suchfeld" value="" size="20" name="sword"></form>');
    $('.header .suche input.suchfeld').attr('value',$('#suchform .suchfeld').val());
    $('.header .suche form').submit(function(){
      var $tmp_value = $('.suchfeld',this).val();
      if($('.suchfeld',this).val()=='') {
        alert('Bitte geben Sie einen Suchbegriff ein.');
      } else {
        $('#suchform .suchfeld').attr('value',$tmp_value);
        $('#suchform .suchbutton').trigger('click');
      }

      return false;
    });
    $('.header .suche .suchfeld').live('focus',function() {
      $(this).addClass('active');
    });
    $('.header .suche .suchfeld').live('blur',function() {
      $(this).removeClass('active');
    });
  }

  if($('body.page_571').length) {
    $('.header .suche').html('<form method="post" enctype="multipart/form-data" action="index.php?id=571&amp;no_cache=1"><input type="submit" class="suchbutton" value="SUCHEN" name="submit"> <input type="text" class="suchfeld" value="" size="20" name="sword"></form>');
    $('.header .suche input.suchfeld').attr('value',$('#suchform .suchfeld').val());
    $('.header .suche form').submit(function(){
      var $tmp_value = $('.suchfeld',this).val();
      if($('.suchfeld',this).val()=='') {
        alert('Bitte geben Sie einen Suchbegriff ein.');
      } else {
        $('#suchform .suchfeld').attr('value',$tmp_value);
        $('#suchform .suchbutton').trigger('click');
      }

      return false;
    });
    $('.header .suche .suchfeld').live('focus',function() {
      $(this).addClass('active');
    });
    $('.header .suche .suchfeld').live('blur',function() {
      $(this).removeClass('active');
    });
  }
  
  $('div.news-single-img a img[src*="uploads"]').unwrap();
  
  if($('body.page_449').length) {
    $('.col1-long > .newsBlock:lt(8)').hide();
    $('ul.third > li:lt(8)').hide();
  }
  
  $('a[href=$".pdf"] img').css('border','none');
  
  //Achema Landingpage
  if($('body.achema').length) {
    $('.header #slideshow img:first').addClass('change');
    
    $('div.content div.top_content ul:first').addClass('jcarousel').addClass('jcarousel-skin-tango').attr('id','mycarousel');
    $('div.content div.top_content ul:first li a').each(function(){
      var img_full = $(this).attr('href').split('/');
      var thumb = 'thumb_'+img_full.pop();
      
      $(this).html('<img src="'+img_full.join('/')+'/'+thumb+'"/>');
    });
    $('div.content div.top_content ul:first li:eq(4)').addClass('active');
    
    $('#mycarousel').jcarousel({
      vertical: false,
      scroll: 1,
      start: 3,
      wrap: 'circular',
      // mouseWheel:true
                
      size: $('#mycarousel li').length
    });
    $('#mycarousel a').click(function() {
      // 1. aktiv markieren
      $('#mycarousel li').removeClass('active');
      $(this).parent('li').addClass('active');//.siblings().removeClass('active');
      
      // 2. auslesen Pfad
      var $img_url = $(this).attr('href');
      
      // 3. Bild tauschen
      $('.header img.change').attr('src',$img_url);
      
      
      var $index = $('ul#mycarousel li').index($(this).parent()) + 1;
        $('p.ref_navigation span.index').text($index);
        
      
      return false;
    });

  }
         // Zum durchklicken der Bilder
        $('p.ref_navigation a.prev').click(function(){
          var $active = parseInt($('p.ref_navigation span.index').text());
          if($active>1) {
            $active = $active - 2;
            
            $('ul#mycarousel li:eq('+$active+') a').trigger('click');
          }
        });
        $('p.ref_navigation a.next').click(function(){
          var $active = parseInt($('p.ref_navigation span.index').text());
          if($active<$('ul#mycarousel li').length) {
            $active = $active;
            
            $('ul#mycarousel li:eq('+$active+') a').trigger('click');
          }
        });
        
        
          
          
        
        $('p.ref_navigation span.total').text('/'+$('ul#mycarousel li').length);
  
  
  /*Kontaktformular*/
  if($('body.page_419, body.page_570, body.page_223, body.page_259, body.page_518').length) {
    var $value = $('select').val();
      if($value == 'Sonstiges'){
          $("label[for='mailformSonstiges']").show();
          $("textarea#mailformSonstiges").show();
      }
      else{
        $("label[for='mailformSonstiges']").hide();
        $("textarea#mailformSonstiges").hide();
      }
    //$(".page_575 label[for='mailformSonstiges']").hide();
    //$(".page_575 textarea#mailformSonstiges").hide();
    
    $('select').change(function () {
      var $value = $(this).val();
        if($value == 'Sonstiges'){
            $("label[for='mailformSonstiges']").show();
            $("textarea#mailformSonstiges").show();
        }
        else{
          $("label[for='mailformSonstiges']").hide();
          $("textarea#mailformSonstiges").hide();
        }
    
    });
  }
  
  /*Ende*/

  /*BROWSER FILTER*/
  if ($.browser.safari) {
    $('body').addClass('safari');
  }
    if ($.browser.opera) {
    $('body').addClass('opera');
  }
  
  // Presseloung - Lightbox-Integration
  if($('body.page_552').length) {
    
    $('div.referenzBlock > a,div.artikel-download li > a').each(function(){
      if( (
        
          $(this).attr('href')=='http://www.isinger-merz.de/index.php?id=556')
          || ($(this).attr('href')=='index.php?id=556')
          || ($(this).attr('href')=='http://www.isinger-merz.de/headernavigation/news-trends/presselounge/anmelden-um-inhalte-anzusehen.html')
          || ($(this).attr('href')=='headernavigation/news-trends/presselounge/anmelden-um-inhalte-anzusehen.html')
        //  || $(this).attr('href')=='http://www.isinger-merz.de/index.php?id=585')
        //  || ($(this).attr('href')=='index.php?id=585')
      ) {
        $(this).removeAttr('href').attr('href','http://www.isinger-merz.de/index.php?id=585').addClass('fbox_powered').addClass('referenzBlock');
      }
    });
    
    $('.newsBlock h4').each(function(){
      var $tmp_link = $(this).closest('.presse_wrapper').find('div.referenzBlock > a');
      $(this).html('<a href="'+$tmp_link.attr('href')+'" class="'+$tmp_link.attr('class')+'">'+$(this).text()+'</a>');
    });
  
  
  /*Presse Bilder Lightbox*/
  $('div.presse_wrapper div.hidden_lightbox_images a').addClass('referenzBlock').addClass('lightbox_powered');
  
  $("div.hidden_lightbox_images").each(function(i) {
                $(this).find('a').attr('rel','group'+i);
  });

  
  $("div.artikel-download li.bilder a").click(function() {
  
    //var $tmp_wrapper = $(this).closest("div.artikel-download").children("div");
    var $tmp_wrapper = $(this).closest("div.artikel-download");
    $tmp_wrapper.find("div.hidden_lightbox_images a:first").trigger("click");
  
  });
  $('a.referenzBlock.lightbox_powered,div.presse_wrapper div.hidden_lightbox_images .lightbox_powered').lightbox({});
	  $('a.referenzBlock.fbox_powered').fancybox({
		width: 400,
		height: 500,
		autoDimensions: false
	  });
  }

  // ENDE Presselounge
  
});
