$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};


/*IE6: abfrage ob browserfenster-breite > 1000 -> dann div-breite auf 100% || sonst divbreite auf 1000px*/

$(document).ready(function() {	
	/* Überschreiben der Fade-Funktionen um Cleartyp Schriften im IE7 zu unterstützen */
	jQuery.fn.fadeIn = function(speed, callback) { 
		return this.animate({opacity: 'show'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
	 
	jQuery.fn.fadeOut = function(speed, callback) { 
		return this.animate({opacity: 'hide'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
	 
	jQuery.fn.fadeTo = function(speed,to,callback) { 
		return this.animate({opacity: to}, speed, function() { 
			if (to == 1 && jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	};	
	
	/* ### Halbtransparenten Background vom Maintextfeld on Hover weniger transparent machen### */	
	$('#introtext').wait(3000).fadeTo(1500, 0);
	footerStatus = 'closed';

	 $('#introtext').hover(function() {
		if (footerStatus == 'closed') {
			$('#introtext').fadeTo(700, 1, function() {
				footerStatus = 'open';
			});	
		}
	},
	function() {
		if (footerStatus == 'open') {
			$('#introtext').fadeTo(700, 0, function() {
				footerStatus = 'closed';
			});	
		}
	});

	/* ### Bilderanimation  ### */
	function startAnimation() {
		//alert("starte Animation");
		
		$("#introbilderpool").append($("#preloadbilder_code").attr('value'));
//		$("#introbilderpool").append('<img src="images/introbild2.jpg" alt="Sylter Ferien"/><img src="images/introbild3.jpg" alt="Sylter Immobilien"/>');
		
		if ($('div#introbilderpool') && $('div#introbilderpool img').length > 1) {
			$('#introbilderpool').cycle({
				fx:    'fade',
				speed:  2500,
				requeueOnImageNotLoaded: true,
				requeueTimeout: 250
			 });
		}
	}
	
	/* ### Bilder Preloader  ### */
	/*$.preload( [ 'introbild2', 'introbild3' ], {
		base:'images/',
		ext:'.jpg',
		onFinish:startAnimation
	});*/
	$("#introbilderpool").css("position", "relative");
	$.preload( [ $("#preloadimages").attr('value') ], {
		base:'tmp/images/',
		ext:'',
		onFinish:startAnimation
	});
		
});

