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.
	//Defaultvalue
	$("input.defaultvalue, textarea.defaultvalue").each(function() {

		$(this).defaultvalue($(this).attr("title"));

	});


	// 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.
	// k_ > steht für Katalog
	$("form.validate").validate({
		rules: {
			k_anrede:"required_without_defaultvalue",
			k_strasse:"required_without_defaultvalue",
			k_plz:"required_without_defaultvalue",
			k_ort:"required_without_defaultvalue",
			k_land:"required_without_defaultvalue",
			name: "required_without_defaultvalue",
			vorname: "required_without_defaultvalue",
			email: {
				required_without_defaultvalue: true,
				email: true
			}
		},
		messages: {
			k_anrede: "",
			k_strasse: "",
			k_plz: "",
			k_ort: "",
			k_land: "",
			name: "",
			vorname: "",
			email: ""
		}
	});

	//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);

	});


});