$(document).ready(function(){
  
  browserDetector();
  
  $('.shop_item_header i').addClass('headline_i');
  
  $('#slider_wrap').cycle({ 
    fx:     'scrollHorz', 
    pager:  '#nav',
    timeout: 10000,
    delay: 0,
    pagerAnchorBuilder: function(idx, slide) { 
    var id = idx + 1;
        return "<li id=\"sldr" + id + "\"></li>";
    }
  });
     

   
  $('#teaser_left').cycle({ 
    fx:     'fade', 
    timeout: 10000,
    delay: 0
  });
  
  $('#jugendmarke_slides_wrap').cycle({ 
    fx:     'fade', 
    pager:  '#nav2',
    timeout: 5000,
    delay: 0,
    pagerAnchorBuilder: function(idx, slide) { 
    var id = idx + 1;
        return "<li id=\"jm" + id + "\"></li>";
    }
  });

  $('#accordion h3 a').click(function(e) { e.preventDefault(); });
  $('#accordion h3').click(function() {
    $('#accordion h3').next().slideUp('slow');
    $(this).next().slideDown('slow');
  }).next().hide();
  
  /*$('#accordion h3').click(function() {
    $(this).next().slideDown('slow');
    $(this).prev().slideUp('slow');
  });*/
  
    
  $('.slider').cycle({ 
    fx:     'scrollHorz', 
    timeout: 0,
    delay: 0,
    prev:    '#prev', 
    next:    '#next'
  });
  
    $('.slides_container').after('<div id="pagination">').cycle({
		fx:     'scrollHorz',
		speed:  'fast',
		timeout: 0,
		pager:  '#pagination'
	});
  
  
  initClick();
  calcNav();
  article_hoehe_neu()
  hoeheNeu();
  


});

function hoeheNeu(){

  var max_height1 = $('#content').height();
  var contentheight = $('#contentwrap').height();
 
  if(max_height1 == null){

    $('#contentwrap').height(contentheight+50); 
    $('#sidebar').height(contentheight+20);
    $('#trenner_vert').height(contentheight);

  }

  
}

function article_hoehe_neu(){
  
$('.article_text').each(function(e) {  
  h = $(this).height();    
  if(typeof(h) != "undefined") {        
       $(this).parent().height(h);
  }  
});  
} 

function calcNav() {
  var content = $("#contentwrap").height();
  content = content * 0.87;
  var trenner = $("#trenner_vert");
  trenner.css({'height': content});
}

function initClick () {
  $('#sldr1').click(function() { 
    $('#slider').cycle(0);  
    $('#teaser_left').cycle(0);  
    return false; 
  }); 
 
  $('#sldr2').click(function() {  
    $('#slider').cycle(1);  
    $('#teaser_left').cycle(1);  
    return false;  
  }); 
  
  $('#sldr3').click(function() {  
    $('#slider').cycle(2);  
    $('#teaser_left').cycle(2);  
    return false;  
  }); 
}


function browserDetector () {
// Checks the browser and adds classes to the body to reflect it.

    var userAgent = navigator.userAgent.toLowerCase();
    $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
    
    // Is this a version of IE?
    if($.browser.msie){
        $('body').addClass('browserIE');
        
        // Add the version number
        $('body').addClass('browserIE' + $.browser.version.substring(0,1));
    }
    
    
    // Is this a version of Chrome?
    if($.browser.chrome){
    
        $('body').addClass('browserChrome');
        
        //Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserChrome' + userAgent);
        
        // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
        $.browser.safari = false;
    }
    
    // Is this a version of Safari?
    if($.browser.safari){
        $('body').addClass('browserSafari');
        
        // Add the version number
        userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
        userAgent = userAgent.substring(0,1);
        $('body').addClass('browserSafari' + userAgent);
    }
    
    // Is this a version of Mozilla?
    if($.browser.mozilla){
        
        //Is it Firefox?
        if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
            $('body').addClass('browserFirefox');
            
            // Add the version number
            userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
            userAgent = userAgent.substring(0,1);
            $('body').addClass('browserFirefox' + userAgent);
        }
        // If not then it must be another Mozilla
        else{
            $('body').addClass('browserMozilla');
        }
    }
    
    // Is this a version of Opera?
    if($.browser.opera){
        $('body').addClass('browserOpera');
    }
   
}
