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();

    }

  );


	// 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") + "; ";

		});


		var hotel = $(this).closest(".teaser_include").attr("id");

		//1-12 grosse Teaser ab12 kleine Teaser
		if(hotel<12){

			var hotel_name = $(this).closest(".teaser_include").children(".content_artikel_gross").children(".ueberschrift_gross").children("a").html();

		}else{

			var hotel_name = $(this).closest(".teaser_include").children(".content_artikel_middle").children(".ueberschrift_middle").children("a").html();

		}

		 pageTracker._trackPageview("/Details/" + hotel_name);


		$("input[name='angebote_von']").val(angebote_von);

		$("#error").hide();

	});



	// 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",

			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);

	});


	//Datum
	$(".date").datepicker({
		dateFormat: 'dd.mm.yy',
		showOn: 'both',
		buttonImageOnly: true,
		minDate: 0,
		numberOfMonths: 1
	});



});
