/* ##### jquery um timer erweitern */
jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};


// Dok laden
$(document).ready(function(){
	
	/* ##########################	Weltkarte */
	var link = $('ul.dropdown #resorts');
	var karte = $('ul.dropdown #resortsflash');
	var active = 0;

	link.mouseover(function(){
		karte.stop().show();
	});
	
	link.mouseout(function(){
		var timers	= {};
		var time	= 500;
		timers = $.timer(time,function(){
			if(active == 0){
				karte.stop().hide();
			}
		});
	});
	
	karte.hover(function(){
		active = 1;
	},
	function(){
		active = 0;
		timers = $.timer(500,function(){
			karte.stop().hide();
		});
		
	});
	
	/* ##########################	Bildwechsel */
	$('.search_text').click(function(){
		$(this).addClass('active');
	});

	
	$('.search_text').blur(function(){
		$(this).removeClass('active');
	});
	
	
	
	
	
	/* ##########################	Bildwechsel */
	// Angebote cachen
	var inhalt	= $('.left .angebot .images');
	
	// Fuer jedes Angebot den Slider starten
	inhalt.each(function(e){
		
		// Obj, Bild und Timer cachen
		var obj		= $(this);
		var images	= $('img', obj).size();
		var timers	= {};
		var time	= (e+1) * 2000;
		
		// Zeitversetzt den Imagewechsel starten
		timers = $.timer(time,function(){
			changeImage(obj, 6000, 84, images);
		});
	});
	$('#veranstalter').change(function(){
		var veranstalterID = $('#veranstalter').val();
		$('#landDropdown').empty();
		$('#landDropdown').load("include/request.ax.php?act=3&veranstalter="+veranstalterID);
	});
	// Function mit Selbstaufruf
	function changeImage(obj, delay, pixel, images){
		
		// Timer, Pixel cachen
		var timer	= {};
		var pix		= '-' + pixel + 'px';
		
		// Versetzen
		$('span', obj).css('margin-top', pix);
		
		// Zeitversetzt selbstaufrufen
		timer = $.timer(delay,function(){
			var new_px = pixel + 84;
			// Wenn 
			if(new_px <= (images * 3)) {
				changeImage(obj, delay, pixel + 84, images);
			} else {
				changeImage(obj, delay, 0, images);
			}

		});

	}
	$("#textsucheBTN").hover(function () { 
		$(this).css("cursor","pointer");
	});
	$("#textsucheBTN").click(function () { 
	      $('#volltextsuche2').submit();
    });
	var actDetailsuche = 0;
	$(".detailsuche").hide();
	$("#detailsuche_btn").click(function (){
		if(actDetailsuche == 0)
		{
			$(".detailsuche").show();
			actDetailsuche = 1;
		}else
		{
			$(".detailsuche").hide();
			actDetailsuche = 0;
		}
	});

});

function load_zimmerSkizzen(fk_anlagen_id)
{
	$("#overlay").css("opacity","0.8").show().click(function(){
		$("#overlay").hide();
		$("#overlay_box").hide();
	});
	$.get("include/request.ax.php?act=4&fk_anlagen_id="+fk_anlagen_id,function(data){
		$("#overlay_box").html(data).show();

		$("#mini_close_button").click(function(){
			$("#overlay").hide();
			$("#overlay_box").hide();
		});
	});
	
}