Shadowbox.loadSkin('shadowbox', liveurl+'/style/');
window.onload = Shadowbox.init;


$(document).ready(function() {

  ///fix PNG-BUG IE<=6
  $("img").ifixpng();
  $("div#header").ifixpng();
  $("#logo img").ifixpng();
  $(".png_fix img").ifixpng();

  //Alle bis auf die erste Detailansicht ausblenden
  $(".show_detail").hide();
  $("#detail_" + $(".teaser_include").attr("id")).show();


  $("#abschicken").hover(

    //mouseover
    function () {
      $(this).removeClass("gsend_do");
      $(this).addClass("send_up")
      $(this).ifixpng();

    },

    //mouseout
    function () {
      $(this).removeClass("send_up");
      $(this).addClass("send_do")
      $(this).ifixpng();

    }

  );

    $("#detail img").hover(

    //mouseover
    function () {

      $(this).attr("src", $(this).parent("a").attr("rel_up"));

      $(this).ifixpng();

    },

    //mouseout
    function () {

      $(this).attr("src", $(this).parent("a").attr("rel_do"));

      $(this).ifixpng();

    }

  );

  $("#gratis_button").hover(

    //mouseover
    function () {
      $(this).removeClass("gratis_do");
      $(this).addClass("gratis_up")
      $(this).ifixpng();

    },

    //mouseout
    function () {
      $(this).removeClass("gratis_up");
      $(this).addClass("gratis_do")
      $(this).ifixpng();

    }

  );

  //Tooltip einblenden
  $(".tooltip").tooltip({
    track: true,
    showBody: " - ",
    showURL: false
  });


  // Die Input Felder werden mit den Feldbezeichnungen gefüllt. Validate bleibt trotzdem aktiv.
  $('.input_anrede').example('Anrede');
  $('.input_name').example('Name*');
  $('.input_vorname').example('Vorname*');
  $('.input_strasse').example('Strasse, Nr');
  $('.input_plz').example('PLZ');
  $('.input_ort').example('Ort');
  $('.input_land').example('Land');
  $('.input_telefon').example('Telefonnummer');
  $('.input_email').example('E-Mail-Adresse*');
  $('.input_sonstiges').example('Ihre Wünsche/Sonstiges');

  $('.input_kanrede').example('Anrede*');
  $('.input_kname').example('Name*');
  $('.input_kvorname').example('Vorname*');
  $('.input_kstrasse').example('Strasse, Nr*');
  $('.input_kplz').example('PLZ*');
  $('.input_kort').example('Ort*');
  $('.input_kland').example('Land*');
  $('.input_ktelefon').example('Telefonnummer');
  $('.input_kemail').example('E-Mail-Adresse');



  // Um Name und ID zu speichern >> GET AJAX
  $(".get_ajax").click(function(){

    if (($(this).attr("checked"))) {
      var status = 1;
    }else{
      var status = 0;
    }
    $.get(liveurl+"/ajax.php", { id: $(this).closest(".teaser_include").attr("id"), save: status },
    //Rückgabewert wird über data in die Klasse angebote_von geschrieben
    function(data){
      $("#angebote_von").html(data);
    });

  });

  //Favoriten hinzufügen
  $(".check_favourite").click(function() {

    $(".angebote_von").html("");
    $("input[name='angebote_von']").val("");

    var angebote_von = "";

    $(".check_favourite:checked").each(function() {

      $(".angebote_von").append($(this).attr("name") + "<br />");
      angebote_von = angebote_von + $(this).attr("titel") + "; ";

      });

      $("input[name='angebote_von']").val(angebote_von);

      $("#error").hide();

    });

  //Details anzeigen
  $(".details").click(function() {

    var hotel = $(this).closest(".teaser_include").attr("id");
    var hotel_name = $(this).closest(".teaser_include").children(".content_artikel_middle").children(".ueberschrift").children("span").html();

    if (!hotel_name) {

    	hotel_name = $(this).closest(".teaser_include").children(".content_artikel_groß").children(".ueberschrift").children("span").html()

    }

    //Alle ausblenden
    $(".show_detail").hide();

    //Details des Hotels anzeigen
    $("#detail_" + hotel).fadeIn(800);

    pageTracker._trackPageview("/Details/" + hotel_name);

  });


  // Captcha
  $("#captcha").click(function(){
    var random = Math.floor(Math.random()*25600);
    $("#captcha img").attr("src", "../../captcha/image.php?new_captcha=true&" + random);

  });


  // Prüfung ob alle Pflichtfelder ausgefüllt sind.
  $(".validate").validate();

  //alle externen Links kennzeichnen
  $('a').filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).addClass('external');

  //alle externen Links in Analytics
  $("a.external").click(function(){

    var site = $(this).attr('href');
    site = site.replace("http://", "");

     pageTracker._trackEvent("external", site);

  });

  //alle mailto Links kennzeichnen
  $('a[href^="mailto:"]').click(function() {

    var site = $(this).attr('href');
    site = site.replace("mailto:", "");

    pageTracker._trackEvent("mailto", site);

  });


});