$(document).ready(function(){
	$('a[rel]').overlay();
	
	$('#formtickets select').change(function(){
		//console.info($(this).val());
		var anzahl = $(this).val();
		var preisEinzel = parseInt($(this).parent('td').next('td').next('td').text().substring(3));
		var gesamt = anzahl * preisEinzel;
		$(this).parent('td').next('td').next('td').next('td').text('EUR '+gesamt+',-');
		
		var total = 0;
		$("#formtickets td.price").next('td').each(function(){
			if($(this).text() != "")
				total += parseInt($(this).text().substring(3));
		});
		$('.priceTickets').text("EUR "+total+",-");
		var totalPorto = total + 2;
		$('.priceTotal').text("EUR "+totalPorto+",-");
	});
	
	//Google Maps
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(47.769099, 9.153242), 15);
	map.setUIToDefault();
	
	map.addOverlay(new GMarker(new GLatLng(47.769189,9.155195)));
	
	var text = "<b>Überlinger Klangfestspiele 2010</b><br/><br/>vom 27.05. - 30.05.2010<br/>Stadtgraben Überlingen"
	map.openInfoWindowHtml(new GLatLng(47.769189,9.155195),text);
	
	initialize();
	
});

$.fn.overlay = function(i){
	
	$(this).each(function(){
		var infoElem = $($(this).attr('rel'));
		infoElem.hide();

		$(this).click(function(){
			$('.overlay').fadeIn().focus();
			$('.overlay-content').html(infoElem.html());
			return false;
		});

		$('a.overlay-close').click(function(){
			$('.overlay').fadeOut().children('.overlay-content').empty();
			return false;
		});
	})
	
};

function calcTotal(elem){

}
