$(document).ready(function() {

   //Global id from main menu
    GUID = GUID?GUID:2;  
    var imgMenu = {
    2: 'home',
    3: 'reiseziel_england',
    4: 'reiseziel_florida',
    5: 'sport_camps',
    6: 'termine_und_preise'
  }
  var menu =  imgMenu[GUID];
  
  var imgCont = 7;
    var imgObj = $('.top-img img');
    imgObj.attr('src', "fileadmin/template/images/slideshow_"+menu+"_1.jpg").fadeIn(1000);  
    var imgSrc = imgObj.attr('src');
  for(i = 2 ; i< imgCont+1 ; i++) {
     imgSrcNew = imgSrc.replace(/\d+/i, i);
       imgObj
         .clone()
         .attr("src", imgSrcNew)
         .appendTo(imgObj.parent())
         .hide();
     }
  
  var options = {  
    delayBetweenImage : 6000,
    delayEffect : 800,
    imgCont : imgCont,
    fadeIn : function(obj) {
        obj.fadeIn(2000);
      }
    };
  var data = {
     imgCur : 1,
     imgNxt : 2
   };
  
  
  
  setInterval(function(){
      if(options.imgCont == data.imgCur) {
        $("img[src$='fileadmin/template/images/slideshow_"+menu+"_"+data.imgCur+".jpg']").fadeOut(1000, function() {
        options.fadeIn($("img[src$='slideshow_"+menu+"_1.jpg']"));
      });
        data.imgCur = 0;
      }
       data.imgNxt = data.imgCur +1;
    $("img[src$='slideshow_"+menu+"_"+data.imgCur+".jpg']").fadeOut(1000, function() {
        options.fadeIn($("img[src$='slideshow_"+menu+"_"+data.imgNxt+".jpg']"));
      });
    //$("img[src$='fileadmin/template/images/slideshow_home_"+data.imgNxt+".jpg']").fadeIn(4000);
    data.imgCur++;                
    },options.delayBetweenImage); 
    
    //top meunu effect
    $('.nudge').mouseover(function() { //mouse in
        $(this).animate({ paddingTop: '5px' }, 500);
      }).mouseout(function() { //mouse out
        $(this).animate({ paddingTop: 0 }, 500);
     });
     
    
     //main menu mouse over
     $('.menu1-level1-no').children().children().mouseover(function() {
         $(this).attr('src', $(this).attr('src').replace('no', 'act'));
      }).mouseout(function(){
         $(this).attr('src', $(this).attr('src').replace('act', 'no'));
      });
      
      //sub menu mouse over
      
      $('.menu1-level2-no').hover( function () {
          $(this).addClass('menu1-level2-hover');
         // $(this).animate( { backgroundColor: '#F5C9D4' }, 300);
          
        }, function () {
          $(this).removeClass('menu1-level2-hover');
          //$(this).animate( { backgroundColor: 'white' }, 100);
        }
      );
      
        
    //Anmeldeformular  
   $('#form-submit').click(function(){
      $("#dataform_submit").validate({
         submitHandler : function(errorMap, errorList) {
           $('#pflichtfelder').hide();
          $.ajax({
             type: "POST",
             url: "fileadmin/template/mail.php",
             data: $("#dataform_submit").serialize(),
             success: function(data){
                  data =data.split('#^^#');
              
              $('.result').html(data[0]);
              $('.button_print').click(function() {
                fillPrintForm(data[1]);
              });
              
             }
           });
        },
        invalidHandler: function(form, validator) {
          $('#pflichtfelder').show();
        }
      });  
    });  
      
      
    //Kontaktformular  
    $('#form-submit2').click(function(){
       $("#dataform_submit").validate({
         submitHandler : function(errorMap, errorList) {
          $.ajax({
             type: "POST",
             url: "fileadmin/template/mail2.php",
             data: $("#dataform_submit").serialize(),
             success: function(data){
              $('.content').html(data);
             }
           });
        }
      });       
    });
    
    function fillPrintForm(data) {
      var fields = $("#dataform_submit").serializeArray();
      var mywindow = window.open('', 'Formular', 'height=400,width=600');
      mywindow.document.write('<html><head><title>Formular</title><META http-equiv="Content-Type" content="text/html; charset=UTF-8">');
      mywindow.document.write('<link rel="stylesheet" href="http://fhc-sprachreisen.de/fileadmin/template/css/style.css?v=2" type="text/css" />');
      mywindow.document.write('</head><body >');
      mywindow.document.write(data);
      mywindow.document.write('</body></html>');
      mywindow.document.close();
      mywindow.print();
      return true;
    }
    
   $("#typo3-previewInfo").hide(); 
    
    
  

});
