jQuery(document).ready(function(){
  
  $("#de img").attr("src","images/de_aktiv.png");
  
  $(".header-start-images a").click(function(){
    
    change_sprache($(this).attr("id"));
    
  });

  change_sprache("de");
    
    kursangebot.init();
    $("a[rel='example1']").colorbox({                                                          
      "iframe":true,
      "innerWidth":"600px",
      "innerHeight":"800px"
    });
    
    jQuery("#totop").click(function(){
      $('html, body').animate({scrollTop:0}, 'fast');         
      return false;
    });
    newsslider.init();  
    $.address.change(function(){
        $.address.strict(false);
        if(jQuery("#sprachtestfortschritt").length > 0){
          if($.address.value() != ""){             
            formnavigation.step($.address.value());              
          }
        }

    });    

    if(jQuery("#sprachtestfortschritt").length > 0){

      if(location.href.match("/fr")){
        
        jQuery(".nav2nd a").each(function(i,element){
          if(jQuery(element).html() == "Französisch"){
            jQuery(element).addClass("current");
            jQuery(element).parent().addClass("active");            
          }
        });
        
      }      
    }

    if(jQuery("#sprachtestfortschritt").length > 0){

      if(location.href.match("/es")){
        
        jQuery(".nav2nd a").each(function(i,element){
          if(jQuery(element).html() == "Spanisch"){
            jQuery(element).addClass("current");
            jQuery(element).parent().addClass("active");            
          }
        });
        
      }      
    }

    if(jQuery("#sprachtestfortschritt").length > 0){

      if(location.href.match("/de")){
        
        jQuery(".nav2nd a").each(function(i,element){
          if(jQuery(element).html() == "Deutsch"){
            jQuery(element).addClass("current");
            jQuery(element).parent().addClass("active");            
          }
        });
        
      }      
    }

    if(jQuery("#sprachtestfortschritt").length > 0){

      if(location.href.match("/en")){
        
        jQuery(".nav2nd a").each(function(i,element){
          if(jQuery(element).html() == "Englisch"){
            jQuery(element).addClass("current");
            jQuery(element).parent().addClass("active");            
          }
        });
        
      }      
    }

    if(jQuery("#sprachtestfortschritt").length > 0){

      if(location.href.match("/it")){
        
        jQuery(".nav2nd a").each(function(i,element){
          if(jQuery(element).html() == "Italienisch"){
            jQuery(element).addClass("current");
            jQuery(element).parent().addClass("active");            
          }
        });
        
      }      
    }




});    


function change_sprache(sprache){  
    
    if(sprache == "right"){
      
      $(".header-start-images a").each(function(i,element){
        if($(element).hasClass("active")){
          
          if( $(element).attr("id") == "es"){
           sprache = "de";
          }else{
          sprache = $(element).next().attr("id");
          }          
        }                                        
       
        
      });
      
    } 
    
    if(sprache == "left"){
      
      $(".header-start-images a").each(function(i,element){
        if($(element).hasClass("active")){
          
          if( $(element).attr("id") == "de"){
           sprache = "es";
          }else{
          sprache = $(element).prev().attr("id");
          }          
        }                                        
       
        
      });
      
    } 
    
    
    
  
    $("#superheader").removeClass("de");
    $("#superheader").removeClass("gb");
    $("#superheader").removeClass("it");
    $("#superheader").removeClass("fr");
    $("#superheader").removeClass("es");
    
    $("#de img").attr("src","images/de.png");
    $("#fr img").attr("src","images/fr.png");    
    $("#gb img").attr("src","images/gb.png");        
    $("#es img").attr("src","images/es.png");        
    $("#it img").attr("src","images/it.png");       
    
    $("#"+ sprache + " img").attr("src","images/"+ sprache +"_aktiv.png");                
    $(".header-start-images a").removeClass("active");    
    $("#"+ sprache).addClass("active");
      


    $("#superheader").addClass(sprache);


    var html = $("#header-startboxes ."+sprache+" .info-boxes").html();
    $("#superheader .info-boxes").html("");
    $("#superheader .info-boxes").append(html);
}

kursangebot = {
  init : function(){

    $(".kursangebot").mouseenter(function(){
      $(this).css("cursor","pointer");
      
      $(".kursangebot").removeClass("aktiv");
      $(this).addClass("aktiv");
    });     

    $(".newsteaser-item").mouseenter(function(){
      $(this).css("cursor","pointer");
      
      $(".newsteaser-item").removeClass("aktiv");
      $(this).addClass("aktiv");
    });     
    
                               
    
    $("#post-4 .kursangebot").click(function(){   
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=sprachkurs'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });

    $("#post-1 .newsteaser-item").click(function(){   
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=sprachkurs'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });


      $("#post-19 .kursangebot").click(function(){   
        $.colorbox({
          "html":'<iframe src="/iframe/kontaktform.php?typ=einzel'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
          "innerWidth":"650px",
          "innerHeight":"600px",
          onComplete : function(){
            jQuery("#cboxClose").css({
              "right":"60px",
              "top":"90px"
            });
          }
        });                           
    });

      $("#post-20 .kursangebot").click(function(){   
        $.colorbox({
          "html":'<iframe src="/iframe/kontaktform.php?typ=gruppe'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
          "innerWidth":"650px",
          "innerHeight":"600px",
          onComplete : function(){
            jQuery("#cboxClose").css({
              "right":"60px",
              "top":"90px"
            });
          }
        });                           
    });  
    
      $("#post-21 .kursangebot").click(function(){   
        $.colorbox({
          "html":'<iframe src="/iframe/kontaktform.php?typ=firmen'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
          "innerWidth":"650px",
          "innerHeight":"600px",
          onComplete : function(){
            jQuery("#cboxClose").css({
              "right":"60px",
              "top":"90px"
            });
          }
        });                           
    });

      $("#post-22 .kursangebot").click(function(){   
        $.colorbox({
          "html":'<iframe src="/iframe/kontaktform.php?typ=reisen'+ jQuery(this).attr("id") + '" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
          "innerWidth":"650px",
          "innerHeight":"600px",
          onComplete : function(){
            jQuery("#cboxClose").css({
              "right":"60px",
              "top":"90px"
            });
          }
        });                           
    });



    $("#post-28 #info-fuer-workshop").click(function(){        
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=meeting" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });

    $("#post-29 #info-fuer-workshop").click(function(){        
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=praesentation" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });

    $("#post-30 #info-fuer-workshop").click(function(){        
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=verhandlung" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });

    $("#post-31 #info-fuer-workshop").click(function(){        
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=telefon" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });

    $("#post-32 #info-fuer-workshop").click(function(){        
      $.colorbox({
        "html":'<iframe src="/iframe/kontaktform.php?typ=personal" width="600" height="590" frameBorder="0" allowTransparency="allowTransparency"></iframe>',
        "innerWidth":"650px",
        "innerHeight":"600px",
        onComplete : function(){
          jQuery("#cboxClose").css({
            "right":"60px",
            "top":"90px"
          });
        }
      });                           
    });





    $("#info-fuer-workshop").mouseover(function(){
      $(this).css("cursor","pointer");
    });


    
  }                
  
  
  
}           

newsslider = {       
  init : function(){
    $("#news-slider-arrow-right").click(function(){
      newsslider.right();
      return false;
    });

    $("#news-slider-arrow-left").click(function(){
      newsslider.left();
      return false;
    });

  },
  right : function(){             
    // 1. content befüllen
    // 2. verschieben
    // 3. neuer 0.      
    
    
    var cloneFirst = $(".newsteaser-item").first().clone();                        
    
    $(".slider .newsteaser-item").first().html($("#newslider-archiv .newsteaser-item").last().html());
    
    $(".slider").animate({"left":0}, 500, function(){
      $(".slider").prepend(cloneFirst);
      $(".slider").css({"left":"-189px"});      
    });
    $(".slider .newsteaser-item").last().remove();                   
    
    $("#newslider-archiv").prepend($("#newslider-archiv .newsteaser-item").last());
  },
              
  
  
  left : function(){
    var cloneFirst = $(".newsteaser-item").last().clone();
  
    $(".slider .newsteaser-item").last().html($("#newslider-archiv .newsteaser-item").first().html());
    $(".slider").append(cloneFirst);
    $(".slider").animate({"left":"-378px"}, 500, function(){
      $(".slider .newsteaser-item").first().remove();
      $(".slider").css({"left":"-189px"});      
    });

    $("#newslider-archiv").append($("#newslider-archiv .newsteaser-item").first());

  }
}   

jQuery(document).ready(function(){

  formnavigation.init();
      
});

formnavigation = { 
  currentFormblock : 0,

  init : function(){
    formnavigation.step(formnavigation.currentFormblock);

    jQuery("#sprachtestfortschritt a").click(function(){
      formnavigation.step(jQuery(this).html()-1);                
      return false;
    });
    
    jQuery(".frageblock_weiter a").click(function(){
      if(formnavigation.currentFormblock != 7){
        formnavigation.step(formnavigation.currentFormblock++);                          
      }
      return false;
    });        

    var sprachkuerzel = "";
    
    array = location.href.split("/");

    array.reverse();

    kuerzel = array[0].split("#");
    sprachkuerzel = kuerzel[0];
   
    jQuery(".frageblock input[type=radio]").click(function(){
       createCookie(sprachkuerzel,jQuery("form").serialize(),300);
    });


    if(readCookie(sprachkuerzel) != null){
      antworten = readCookie(sprachkuerzel).replace(/%5B/g,"");

      antworten = antworten.replace(/%5D/g,"");
      antworten = antworten.replace(/frage/g,"");
      antworten = antworten.split("&");



      jQuery(antworten).each(function(i,element){

        element = element.split("=");



        jQuery("table").eq(element[0]-1).find("input[value="+ element[1] +"]").attr("checked","checked");


      });
      
    }

    jQuery(".vorzeitig-absenden").unbind("click");
    
    jQuery("#einstufungstest-submit").unbind("click");


  },
  
  step : function(targetblock){  
    formnavigation.currentFormblock = targetblock;
    jQuery("#sprachtestfortschritt a").removeClass("aktiv");
    jQuery("#sprachtestfortschritt a").eq(targetblock).addClass("aktiv");
    jQuery(".frageblock").hide();
    jQuery(".frageblock").eq(targetblock).show();            
    formnavigation.currentFormblock++; 
            if(jQuery("#sprachtestfortschritt").length > 0){
              $('html, body').animate({scrollTop:450}, 'fast');
            }
  }
}  



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}       
