DialogPerfect = function() { };





$(window).load(function() {
	if(typeof(DD_belatedPNG) != 'undefined') DD_belatedPNG.fix('.png_bg, img');
});

var first_image = $('.gallery_reel_element a:first');
if(first_image.length > 0){
	
	if(first_image.data('desc') != 'redirect'){
		$('#image_holder').hide();
		var html_data = '';
		html_data = html_data + '<img src="' + first_image.attr('href') + '" /><br />';
		html_data = html_data + first_image.data('desc');
		$('#image_holder').html(html_data);
		$('#image_holder').fadeIn();
	}
	
	
}


$(document).ready(function() {
	

	function moveReelLeft(){
		$('.gallery_reel_element:first').animate({marginLeft : "-100px"},500,
		function (){
			$('.gallery_reel_element:first').appendTo($('#gallery_reel_inner ul'));
			$('.gallery_reel_element:last').css('marginLeft','0.8em');


		});
	}
	
	function moveReelRight(){
		$('.gallery_reel_element:last').css('marginLeft','-100px');
		$('.gallery_reel_element:last').insertBefore($('.gallery_reel_element:first'));
		
		
		
		$('.gallery_reel_element:first').animate({marginLeft : "0.8em"},500,
		function (){
		});
	}
	
	$('.gallery_reel_element a').click(function(){
		$('#image_holder').hide();
		var html_data = '';
		html_data = html_data + '<img src="' + $(this).attr('href') + '" /><br />';
		html_data = html_data + $(this).attr('data-desc');
		if($(this).data('desc') != 'redirect'){
			$('#image_holder').html(html_data);
			$('#image_holder').fadeIn();
			return false;
		} else {
			return true;
		}
		
	});
	
	
	$('#galleryLeftBtn').click(function(){
		if(first_image.data('desc') == 'redirect') return true;
		moveReelRight();
	});
	
	$('#galleryRightBtn').click(function(){
		if(first_image.data('desc') == 'redirect') return true;
		moveReelLeft();
	});
	
	
	
	
	
	
	$('.mediumBeschriftung').each(function() {
		$(this).parent().prev('a').attr('title', $(this).text());
	});
});

window.log = function() {
	log.history = log.history || [];   // store logs to an array for reference
	log.history.push(arguments);
	if(this.console) {
		console.log( Array.prototype.slice.call(arguments) );
	}
};

// catch all document.write() calls
(function(doc) {
	var write = doc.write;
	doc.write = function(q) {
		log('document.write(): ', arguments);
		if (/.*/.test(q)) { write.apply(doc, arguments); }
	};
})(document);

jQuery.fn.inputBlurText = function(settings) {
	return this.each(function() {
		$(this).focus(function() {
			if($(this).attr('value') === settings.text) {
				$(this).attr('value', '');
			}
		}).blur(function() {
			if($(this).attr('value') === '') {
				$(this).attr('value', settings.text);
			}
		});
	});
};

DialogPerfect.initMap = function(options) {
	if (GBrowserIsCompatible())
	{
		var defaults = {
			zoom: 13,
			center: new GLatLng(51.726284, 8.797302),
			divContainer: 'google_map'
		};
		
		var options = $.extend(defaults, options);
		
		this.searchAddress = options.searchAddress;
		
		this.map = new GMap2(document.getElementById(options.divContainer));
		this.map.setCenter(options.center, options.zoom);
		this.map.enableScrollWheelZoom();
		this.map.addControl(new GSmallMapControl());
		
		marker = new GMarker(options.center);
		this.map.addOverlay(marker);

		GEvent.addListener(marker, "mouseover", function() {
			marker.openInfoWindowHtml(options.markerText);
		});

		GEvent.addListener(marker, "mouseout", function() {
			marker.closeInfoWindow();
		});
	}
};

DialogPerfect.findAddress = function(from, to) {
	if(this.gdir === undefined)
	{
		this.gdir = new GDirections(this.map, document.getElementById("maps_ergebnis"));
	
		GEvent.addListener(this.gdir, "load", function() { });
		GEvent.addListener(this.gdir, "error", function() {
			var statusCode = DialogPerfect.gdir.getStatus().code;
			
			if (statusCode == G_GEO_UNKNOWN_ADDRESS || statusCode == G_GEO_MISSING_QUERY)
			{
				alert("Die gesuchte Adresse wurde nicht gefunden.");
			}
			else if (statusCode == G_GEO_SERVER_ERROR || statusCode == G_GEO_BAD_KEY || statusCode == G_GEO_BAD_REQUEST)
			{
				alert("Der Geo-Server wurde nicht erreicht.");
			}
			else alert("Es ist ein fehler aufgetreten.");
		});
	}
	
	if(to === undefined) to = this.searchAddress;
	
	this.gdir.load("from: " + from + " to: " + to, { "locale": "de_DE" });
};

jQuery.fn.ticker = function(options) {
	var defaults = {
		speed: 50
	};

	var options = $.extend(defaults, options);
	
	var leftPosition = $(this).width();
	var startPosition = leftPosition;
	var tickerDiv = $(this).children().eq(0);
	var isMouseOver = false;
	
	$(tickerDiv).css('left', leftPosition + 'px').hover(function() {
		isMouseOver = true;
	}, function() {
		isMouseOver = false;
	});
	
	jQuery.fn.ticker.tickerTimer = function() {
		if(!isMouseOver) leftPosition -= 3;
		
		if(leftPosition < -(tickerDiv.width()))
		{
			leftPosition = startPosition;
		}
		
		$(tickerDiv).css('left', leftPosition + 'px');
		
		setTimeout("jQuery.fn.ticker.tickerTimer()", options.speed);
	};
	
	jQuery.fn.ticker.tickerTimer();
};
