function Suedring() { }

var photoListPosition = 0, photoListMax;

$(window).load(function () {
	$('body').supersleight();
});

$(document).ready(function() {
	//$(document).pngFix();
	
	$('.mediumBeschriftung').each(function() {
		$(this).parent().prev('a').attr('title', $(this).text());
	});
	
	photoListMax = $('.bewertungContent > div').length - 1;
	Suedring.shopListMax = $('.scrollBarContentWrapper > div').length - 1;
	Suedring.topBildMax = $('#bildWechsel > img').length - 1;
	Suedring.topBildSpeed = 5000;
	Suedring.topBildFadeSpeed = 500;
	if ($('#bildWechsel img').size() > 1) Suedring.bildTimeout = window.setTimeout("Suedring.wechselBild()", Suedring.topBildSpeed);
	$('#bildWechsel img').hide().eq(0).show();
	$('#bildWechsel img:last').addClass('last');
});

Suedring.wechselBild = function() {
	if ($('#bildWechsel img:visible').hasClass('last')) {
		$('#bildWechsel img:visible').fadeOut(Suedring.topBildFadeSpeed);
		$('#bildWechsel img:eq(0)').fadeIn(Suedring.topBildFadeSpeed);

	} else {
		$('#bildWechsel img:visible').fadeOut(Suedring.topBildFadeSpeed).next().fadeIn(Suedring.topBildFadeSpeed);
	}
	clearTimeout(Suedring.bildTimeout);
	if ($('#bildWechsel img').size() > 1) Suedring.bildTimeout = window.setTimeout("Suedring.wechselBild()", Suedring.topBildSpeed);
};

Suedring.shopListPosition = 0;
Suedring.OnNextShop = function(speed) {
	if(this.shopListMax < 1) return;
	
	var curElement = $('.scrollBarContentWrapper > div:eq(' + this.shopListPosition + ')');
	curElement.animate({ top: '-100px' }, speed);
	
	this.shopListPosition++;
	if(this.shopListPosition > this.shopListMax) this.shopListPosition = 0;
	
	var nextElement = $('.scrollBarContentWrapper > div:eq(' + this.shopListPosition + ')');
	/*if(nextElement.attr('rel') != undefined)
	{
		$('#contentImage').css('background', '#D50023 url(' + nextElement.attr('rel') + ') no-repeat');
	}
	else
	{
		$('#contentImage').css('background', '#D50023');
	}*/
	
	nextElement.css('top', '100px').show().animate({ top: '0' }, speed);
}

Suedring.OnBackShop = function(speed, mainImage) {
	if(this.shopListMax < 2) return;

	var curElement = $('.scrollBarContentWrapper > div:eq(' + this.shopListPosition + ')');
	curElement.animate({ top: '100px' }, speed);
	
	this.shopListPosition--;
	if(this.shopListPosition < 0) this.shopListPosition = this.shopListMax;
	
	var nextElement = $('.scrollBarContentWrapper > div:eq(' + this.shopListPosition + ')');
	if(nextElement.attr('rel') != undefined)
	{
		$('#contentImage').css('background', '#D50023 url(' + nextElement.attr('rel') + ') no-repeat');
	}
	else
	{
		$('#contentImage').css('background', '#D50023');
	}
	
	nextElement.css('top', '-100px').show().animate({ top: '0' }, speed);
}

Suedring.InitializeGMaps = function(gMapsElement) {
	if (GBrowserIsCompatible())
	{
		//Hier Daten anpassen:
		suchadresse = "Pohlweg 110, 33100 Paderborn";
		glatl = 51.703723;
		glatw = 8.769042;
		showadresse = "<b>Klingenthal Südring GmbH</b><br/>Pohlweg 110<br/>33100 Paderborn";
		zoomstufe = 14;

		adresse = [suchadresse, glatl, glatw, showadresse];
		map = new GMap2(document.getElementById(gMapsElement));
		map.enableScrollWheelZoom();
		this.gdir = new GDirections(map, document.getElementById("maps_ergebnis"));
		//GEvent.addListener(this.gdir, "load", onGDirectionsLoad);
		GEvent.addListener(this.gdir, "error", this.handleGMapsErrors);
		//GEvent.addListener(map, 'click', onMapClick);
		map.addControl(new GSmallMapControl());
		geocoder = new GClientGeocoder();

		/*GEvent.addListener(map, "click", function(overlay, latlng) {
		  var myHtml = "The GLatLng value is: " + latlng.lat() + ":" + latlng.lng() + " at zoom level " + map.getZoom();
		  map.openInfoWindow(latlng, myHtml);
		  setDirectionsLat(latlng);
		});*/
		zielAdresse = adresse[0];
		map.setCenter(new GLatLng(adresse[1], adresse[2]), zoomstufe); // Zentriere die Map auf den entsprechenden Ort

		marker = new GMarker(new GLatLng(adresse[1], adresse[2]));
		map.addOverlay(marker);

		GEvent.addListener(marker, "mouseover", function() {
		  marker.openInfoWindowHtml(adresse[3]);
		});

		GEvent.addListener(marker, "mouseout", function() {
		  marker.closeInfoWindow();
		});
	}
}

Suedring.handleGMapsErrors = function handleErrors() {
   if (this.gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS || this.gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("Die gesuchte Adresse wurde nicht gefunden.");
   else if (this.gdir.getStatus().code == G_GEO_SERVER_ERROR || this.gdir.getStatus().code == G_GEO_BAD_KEY || this.gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("Der Geo-Server wurde nicht erreicht.");
   else alert("Es ist ein fehler aufgetreten.");
}

Suedring.setDirections = function(fromAddress, fromStreet) {
	this.gdir.load("from: " + fromAddress + " " + fromStreet + " to: " + zielAdresse, { "locale": "de_DE" });
}

function OnNextButton()
{
	var curElement = $('.bewertungContent > div:eq(' + photoListPosition + ')');
	curElement.animate({ left: '-300px' }, 300);
	
	photoListPosition++;
	
	if(photoListPosition > photoListMax) photoListPosition = 0;
	
	var nextElement = $('.bewertungContent > div:eq(' + photoListPosition + ')');
	nextElement.css('left', '300px').show().animate({ left: '0px' }, 300);
}

function OnBackButton()
{
	var curElement = $('.bewertungContent > div:eq(' + photoListPosition + ')');
	curElement.animate({ left: '300px' }, 300);
	
	photoListPosition--;
	
	if(photoListPosition < 0) photoListPosition = photoListMax;
	
	var nextElement = $('.bewertungContent > div:eq(' + photoListPosition + ')');
	nextElement.css('left', '-300px').show().animate({ left: '0px' }, 300);
}

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: baseUrl + 'js/blank.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					//self.css('position', 'relative');
				};
			});
		};
	});
};
