// JavaScript Document

function checkForm() {
  if(document.getElementById('feedback_email').value=="")
  {
    alert('Bitte geben Sie Ihre E-Mail-Adresse an!');
    document.getElementById('feedback_email').focus();
    return false;
  }
  
  if(document.getElementById('feedback_text2').value=="")
  {
    alert('Bitte geben Sie einen Text ein!');
    document.getElementById('feedback_text2').focus();
    return false;
  }
  document.mailform.submit();
}

var sliderup=false;
var sliderdown=false;
var upReady=true;
var downReady=true;
var count=0;
var aktPos=0;
var maxPos=0;

var upHandler=function() {
  sliderdown=true;
  sliderup=false;
  if(upReady){
    slideGalDown();
    }
}


var counter=4;
var img_index;
jQuery.fx.interval = 100;

$(document).ready(function(){

jQuery(".menu_left_top").click(function (){
  if(jQuery(this).next().css('display') == 'block') {
    jQuery(this).next().hide();
    jQuery('.keyvisual_more').css('margin-top','475px');   
  }else{
    jQuery(this).next().show(); 
    jQuery('.keyvisual_more').css('margin-top','211px'); 
  }
});

//jQuery(".menu_left").mouseleave(function(){
//  if(jQuery(".menu_left_hide").css('display') == 'block') {
//    jQuery(".menu_left_hide").hide();  
//  }
//});

jQuery(".www_img_hover").hover(function (){
  jQuery(this).css('background-position','0px -86px');
},function (){
  jQuery(this).css('background-position','0px 0px');
});
jQuery(".partner_hover").hover(function (){
  jQuery(this).css('background-position','0px -51px');
},function (){
  jQuery(this).css('background-position','0px 0px');
});

jQuery(".various3").fancybox({
				'width'				: 410,
				'height'			: 300,
				'autoScale'			: true,
				'scrolling'      : 'auto',
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe'
			});

maxPos=$(".bigimg").size();
$("#various1").fancybox();
$("#various2").fancybox();

if($(".gallery_slide_wrap").css('left')=='0px'){
  $(".gallery_slide_left").hide();
}



$(".alle").click(function () {
  if($(this).text() == "alle ausblenden" ) {
    $(this).parent().children('.half_box').find(':checkbox').attr('checked', false);
    $(this).parent().next().next().find(':checkbox').attr('checked', false);
    $(this).text("alle einblenden");
    $(this).parent().children(":nth-child(1)").attr('value', 'alle einblenden');
    $("#filter").submit();
  }else {
    $(this).parent().children('.half_box').find(':checkbox').attr('checked', true);
    $(this).parent().next().next().find(':checkbox').attr('checked', true);
    $(this).text("alle ausblenden");   
    $(this).parent().children(":nth-child(1)").attr('value', 'alle ausblenden');
    $("#filter").submit();
  }
});

   




$(".themen").hover(function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".topnavi").css("background-position","0 -49px");
    }
}, function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".topnavi").css("background-position","0 0");
    }  
});

$(".region").hover(function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".topnavi").css("background-position","0 -147px");
    }
}, function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".topnavi").css("background-position","0 -98px");
    }  
});

$(".themen").click(function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".region").removeClass('act');
      $(".topnavi").css("background-position","0 -98px");
      $(".regionmenu").css("display","none");
      $(".themenmenu").css("display","block");
      $(this).addClass('act');
    }
});

$(".region").click(function () {
    if(this.className.indexOf('act') == -1 ) {
      $(".themen").removeClass('act');
      $(".topnavi").css("background-position","0 0");
      $(".themenmenu").css("display","none"); 
      $(".regionmenu").css("display","block");     
      $(this).addClass('act');
    }
});

$(".play_btn_click").click(function () {
      $(".image").fadeOut(10, function () { 
            $(".video_box").fadeIn("slow");
    });
});


$(".mid").click(function () {
 
if($(".hidden2").text() == "yes" && this.className.indexOf('act') == -1) {
  
  $(".hidden2").text("no");
  var aktive = $(".hidden").text();
  var test = $(this).attr("class");
  var clicked = test.substring(test.indexOf('_')+1,test.length);
  var off = aktive.substring(aktive.indexOf('.')+1,aktive.indexOf('_'));
  var off_btn = ".bundesland_"+off;
  var geklicked = "."+clicked+"_wrap";
  
  var actImg=$(this).children().attr('src');
  actImg=actImg.split('.');

  var offImg=$(".act").children().attr('src');
  offImg=offImg.replace('_act','');
  
  $(".act").children().attr('src',offImg);
  $(".act").next().css("margin-left","0");
  $(".act").css("margin-left","0");
  $(".act").css("z-index","0");
  $(".act").removeClass("act");

  $(off_btn).css("color","#000");
  //$(off_btn).css("padding","7px 10px 0");
  $(off_btn).css("height","42px");  
  $(off_btn).prev().css("background-position","0 0");
  $(off_btn).css("background-position","0 0");
  $(off_btn).next().css("background-position","0 0");

  $(this).css("color","#fff");
  //$(this).css("padding","17px 10px 0");
  $(this).css("height","41px");    
  $(this).addClass("act");
  if(!$(this).hasClass("bundesland_video")){
    $(this).css("margin-left","-4px");
    }
  if($(this).hasClass("bundesland_feeds")||$(this).hasClass("bundesland_links")){
    $(this).css("margin-left","-5px");
  }  
  $(this).css("position","relative");
  $(this).css("z-index","100");
  $(this).next().css("margin-left","-5px");
  
  $(this).children().attr('src',actImg[0]+'_act.png');
  
  //$(this).prev().css("background-position","0 -49px");
  //$(this).css("background-position","0 -49px");
  $(this).next().css("background-position","0 -98px");
  if(aktive != geklicked) {
    if(aktive == ".video_wrap") {
      $(".content_bg").fadeIn("slow");
      $(".keyvisual_more").fadeOut("slow");  
    }
    if(geklicked == ".video_wrap") {
      $(".content_bg").fadeOut("slow"); 
      $(".keyvisual_more").fadeIn("slow");  
    }    
    
    $(aktive).fadeOut(500, function () {
            $(".hidden").text(geklicked); 
            $(geklicked).fadeIn("slow", function () {$(".hidden2").text("yes");} );
    });
  }
}
});

$(".slide_btn").click(function() {
  $(this).parent().prev().prev().slideToggle("slow");
  $(this).parent().css("display","none");
});

$(".offer_top").click(function() {
  if(this.className.indexOf('act') == -1 ) {
    $(".box_offer_mid_slide").slideToggle("slow");
    $(".slide_btn").css("display","none");
    $(this).addClass('act');
    $(this).css('cursor','auto');
  }
});

$("#lslider_but").click(function() {
  if($(this).prev().css('display')=='block') {
    $(this).prev().animate({width:'hide'},'fast');
  }else{
    $(this).prev().animate({width:'show'},'slow');
  }
});
$("#tslider_but").click(function() {
  if($(this).prev().css('display')=='block') {
    $(this).prev().animate({height:'hide'},'fast');
  }else{
    $(this).prev().animate({height:'show'},'slow');
  }
});

$(".close").click(function() {
    $(this).parent().animate({height:'hide'},'fast');
});
$(".gallery_slide_left").click(function() {
  sliderdown=true;
  sliderup=false;
  if(upReady){
    slideGalDown();
    }
}); 
$('.up').click(function() {
  sliderdown=true;
  sliderup=false;
  if(upReady){
    slideGalDown();
    }
});

$('.up').mouseleave(function() {
  sliderdown=false;
});
$(".gallery_slide_right").click(function() {
  sliderup=true;
  sliderdown=false;
  if(downReady){
    slideGalUp();
    }
});
$('.down').click(function() {
  sliderup=true;
  sliderdown=false;
  if(downReady){
    slideGalUp();
    }
});
$('.down').mouseleave(function() {
  sliderup=false;
});

$('.gallery_big_img_right_arrow').click(function(){
  $('.gallery_big_img_left_arrow').css('display','block');
  count++;
  $('.bigimg').css('display','none');
  $('.bigimg:eq('+count+')').css('display','block');
  if(count>$('.bigimg').size()-2){
    $('.gallery_big_img_right_arrow').css('display','none');
  }
  slideGalUp();
});
$('.gallery_big_img_left_arrow').click(function(){
  $('.gallery_big_img_right_arrow').css('display','block');
  count--;
  $('.bigimg').css('display','none');
  $('.bigimg:eq('+count+')').css('display','block');
  if(count==0){
    $('.gallery_big_img_left_arrow').css('display','none');
  }
  slideGalDown();
});

function changeThumbs(){
  $('.slider_box')
}


// Track scrolling events
var trackBottomScroll = 0;
$(window).scroll(function () {
if(_gaq){
if(trackBottomScroll < 100 && ($(window).scrollTop() >= ($(document).height() - $(window).height()) / 100 * (trackBottomScroll+10) ) )
{
trackBottomScroll += 10;
_gaq.push(['_trackEvent', 'User behavior', 'scrolled to ' + trackBottomScroll + '%', location.href, (new Date()).getTime() - trackStarttime.getTime()]);
}
}
});


});

function showMainPic(i){
  //img_id=img_index.substring(img_index.indexOf(' ')+1,img_index.length);
  //$('.gallery_box_img_wrap_mid').children().css('display','none');
  //$('.id_'+img_id.substring(img_id.indexOf('_')+1,img_id.length)).css('display','block');
  
  var gallery_type = $(".slider_box").parent().parent().attr('class');
  
  if(gallery_type != 'gallery_slider') {  
  
  $('.angebot_box_img_wrap_mid').children().css('display','none');
  $('.id_'+i).css('display','block');

    var current_act = $(".slider_box").children(".active").removeClass('active');
    
    var new_active = '.mini_'+i;
    $(new_active).addClass('active');
  }
}


function slideGalUp(){
  var up = $('.up_id').text();
  var temp = parseInt(up);
  var actTop = $('.gallery_once').css('height');
  var shiftVal;
  aktPos++;

  //alert($(".gallery_once").children(".active").parent().attr('class'));

  $(".gallery_slide_wrap").animate({left:'-=489'},1000);
  $(".gallery_slide_left").show();
    
  if(actTop=='75px'){
     shiftVal='91px';
  }
  else{
    shiftVal='115px';
  }
  
  if(temp==$('.gallery_once').length-4){
    $('.up_id').text($('.gallery_once').length-3);
    $('.down').css('display','none');
  }else{
    $('.up_id').text(temp+1);
  }
  if(temp<=$('.gallery_once').length-4){
    $('.slider_box').animate({"top": "-="+shiftVal},1000);
  }
  if(aktPos==maxPos-1){
      $(".gallery_slide_right").hide();
    }
  $('.up').css('display','inline');
  
  var gallery_type = $(".slider_box").parent().parent().attr('class');
  
  if(gallery_type == 'gallery_slider') {
    var current_act = $(".slider_box").children(".active").attr('class');
    current_act = current_act.replace('gallery_once ','.');
    current_act = current_act.replace(' active','');
    
    $(current_act).removeClass('active');
    $(current_act).next().addClass('active');
  }
}
function slideGalDown(){
  var up = $('.up_id').text();
  var temp = parseInt(up);
  var actTop = $('.gallery_once').css('height');
  var shiftVal;
  
  $(".gallery_slide_wrap").animate({left:'+=489'},1000);
  $(".gallery_slide_right").show();
    aktPos--;
  if(actTop=='75px'){
     shiftVal='91px';
  }
  else{
    shiftVal='115px';
  }
  
  if(temp<=1){
    $('.up_id').text('0');
    $('.up').css('display','none');
  }else{
  $('.up_id').text(temp-1);
  }
  if(temp<=$('.gallery_once').length-3){
    $('.slider_box').animate({"top": "+="+shiftVal},1000);
    $('.down').css('display','inline');
  }
  if(aktPos==0){
    $(".gallery_slide_left").hide();
  }
  
  var gallery_type = $(".slider_box").parent().parent().attr('class');
  
  if(gallery_type == 'gallery_slider') {
    var current_act = $(".slider_box").children(".active").attr('class');
    current_act = current_act.replace('gallery_once ','.');
    current_act = current_act.replace(' active','');
  
    $(current_act).removeClass('active');
    $(current_act).prev().addClass('active');   
  }
 
}


function getHTTPObject(){
  if (window.ActiveXObject)
    return new ActiveXObject("Microsoft.XMLHTTP");
  else if (window.XMLHttpRequest)
    return new XMLHttpRequest();
  else {
    alert("Ihr Browser unterstützt kein AJAX.");
    return null;
  }
}

function register(string){
 
      httpObject = getHTTPObject();
      if (httpObject != null) {

        httpObject.open("GET", "ajax_tracking_view_all.php?var="+string);
        httpObject.send(null);
        httpObject.onreadystatechange = function() { 
  
                  if (httpObject.readyState == 4 && httpObject.status == 200) { 
                          var data = httpObject.responseText;  
                          
  		            } 
  	    }; 
      }
      return true;

}
