$(document).ready(function() {
	/* Multiselect */
/*	$('#stadien').multiSelect(   
	{   
		select_all_min: 500,   
		no_selection: "Bitte Stadien auswählen",   
		selected_text: " Stadien ausgewählt"   
	});               

	*/
	//$("a.fb").fancybox();
	
	
	// Tooltip 
	$('.tooltip').tooltip({ 
		showURL: false 
	});
	$('#liga_map area').tooltip({ 
		showURL: false 
	});
	
	// Login 
	$('#username').click(function(){ 			
		$(this).val('');
	});
	$('#password').click(function(){ 			
		$(this).val('');
	});
	
	// Suche 
	$("#input-search .text").click(function(){ 			
		if( $(this).val() == ' Stadion / Verein suchen' )
			$(this).val('');
	});
	
	// Treeview 
	$("#ligen").treeview();
	
	
	// Datepicker 
	$(".datepicker").datepicker({ 
	    showOn: "button", 
	    buttonImage: "img/dateSelect.png", 
	    buttonImageOnly: true 
	}).addClass("embed");
	

	// Polygon-Area
	//$('#_Image-Maps_6201006221706194 area').mouseover(function()
	$('map area').mouseover(function()
	{ 			
		hideAll(); 
		$('#overlay-land'+$(this).attr('lid')).show();	    
	});
	$('map area').mouseout(function()
	{ 			
		hideAll(); 
	});
	
	/*$('.land-name').mouseout(function()
	{ 	
		$('#overlay-land'+$(this).attr('lid')).hide();	    
	});*/
	$('.li-land').mouseover(function()
	{ 			
		hideAll(); 
		$('#overlay-land'+$(this).attr('lid')).show();	    
	});
	$('.li-land').mouseout(function()
	{ 			
		$('#overlay-land'+$(this).attr('lid')).hide();	    
	});

	// Groundliste
	$('#ankreuzen').click( function() {
		$.ajax({
			url: ('index.php?s=ajax_groundliste'),
			data: 'stadion=' + $(this).attr('stadion')+'&val='+$(this).attr('checked'),
			type: 'GET',
			cache: false,
			timeout: 10000,
			dataType: 'json',
			error: function(xhr, status, errorThrown) {
				alert('Error loading json data!'+xhr+status+errorThrown);
				//alert('Timeout: Bitte versuchen Sie es noch einmal');
			},
			success: function(json)
			{
			}
		})

	});

	// Tabs 
	$('#kontinente-tabs').tabs();

 	// Stadionauswahl (  Verein und Land )
	$('#stadionauswahl').flexbox('ajax/selectstadion.php', {  
		width: 360,  
		paging: true,
		onSelect: function() {  
			$('#stadion').val(this.getAttribute('hiddenValue'));
		}
	}); 	

	// Weitere Vereine 
	$('#showweiterevereine').click( function() {
		$('#weiterevereine').slideToggle();
	});
	
	// Quickfinder 
	$('#q_land').change(function(){
		$.ajax({
			url: ('ajax/quickfinder_land.php'),
			data: 'land=' + $("#q_land").val(),
			type: 'GET',
			cache: false,
			timeout: 10000,
			dataType: 'json',
			error: function(xhr, status, errorThrown) {
				alert('Timeout (001): Bitte versuchen Sie es noch einmal');
				//alert('Error loading json data!'+xhr+status+errorThrown);
			},
			success: function(json)
			{
				var output = '<option value="0">Liga wählen...</option>';
				for (p in json) 
				{
					output += '<option value="'+json[p].Id+'">'+json[p].Name+'</option>\n';
				}
				$('#q_liga').html(output);
				$('#q_liga').removeAttr("disabled"); 
			}
		})
	});
	$('#q_liga').change(function(){
		$.ajax({
			url: ('ajax/quickfinder_liga.php'),
			data: 'liga=' + $("#q_liga").val(),
			type: 'GET',
			cache: false,
			timeout: 10000,
			dataType: 'json',
			error: function(xhr, status, errorThrown) {
				alert('Timeout (002): Bitte versuchen Sie es noch einmal');
				//alert('Error loading json data!'+xhr+status+errorThrown);
			},
			success: function(json)
			{
				var output = '<option value="0">Verein wählen...</option>';
				for (p in json) 
				{
					output += '<option value="'+json[p].Id+'">'+json[p].Name+'</option>\n';
				}
				$('#q_verein').html(output);
				$('#q_verein').removeAttr("disabled"); 
			}
		})
	});
	$('#q_verein').change(function(){
		if( $("#q_verein").val() == 0 )
			location.href = 'http://www.europlan-online.de/index.php?s=liga&id='+$("#q_liga").val();
		else
			location.href = 'http://www.europlan-online.de/index.php?s=stadion&id='+$("#q_verein").val();
	});
	
	$('button.aufstieg').click( function() {
		
		$.ajax({
			url: ('index.php?s=ajax_aufstieg'),
			data: 'vid=' + $(this).attr('vid')+'&aufstieg=1',
			type: 'GET',
			cache: false,
			timeout: 10000,
			dataType: 'json',
			error: function(xhr, status, errorThrown) {
				alert('Error loading json data!'+xhr+status+errorThrown);
				//alert('Timeout: Bitte versuchen Sie es noch einmal');
			},
			success: function(json)
			{
				alert('Verein wurde der neuen Liga zugeordnet.');
			}
		})		
	});
	
	$('select.abstieg').change( function() {
		
		$.ajax({
			url: ('index.php?s=ajax_aufstieg'),
			data: 'lid='+$(this).val()+'&vid=' + $(this).attr('vid')+'&aufstieg=0',
			type: 'GET',
			cache: false,
			timeout: 10000,
			dataType: 'json',
			error: function(xhr, status, errorThrown) {
				alert('Error loading json data!'+xhr+status+errorThrown);
				//alert('Timeout: Bitte versuchen Sie es noch einmal');
			},
			success: function(json)
			{
				alert('Verein wurde der neuen Liga zugeordnet.');
			}
		})		
	});
	
});

function hideAll()
{
	$('.kontinent-container a').hide();
}

function createMarker(point,html, title) 
{
	var marker = new GMarker(point,{ icon:icon, title:title });
    if( html != '' )
	{
		GEvent.addListener(marker, "click", function(){ 
			marker.openInfoWindowHtml(html);
	    });
	}
    return marker;
}

function getmapdata(map)
{
	$("#center").val( map.getCenter() );
	$("#zoom").val( map.getZoom() );
}

// Setzt den Marker auf die Karte
function stadienSetJS( map, center )
{
	marker = new GMarker(center, {draggable: true});
	
	GEvent.addListener(marker, "dragend", function() {
		$('#geodaten').val( marker.getLatLng() );
	});

	map.addOverlay(marker);

}

// Ermittellt die Koordinaten anhand der eingegebenen Adresse
function getAdressData()
{
	var address = $('#strasse').val()+','+$('#plz').val()+' '+$('#ort').val();
	
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
	    address,
	    function(point) 
		{
			if (!point) 
			{
				alert("Adresse konnte nicht gefunden werden");
			} 
			else 
			{
				map.setCenter(point, 13);
				marker.setPoint(point);
				$('#geodaten').val( marker.getLatLng() );
				//var marker = new GMarker(point);
				//map.addOverlay(marker);
				//marker.openInfoWindowHtml(address);
			}
	    }
	);

}

function showAddress(address) {
	//var map = new GMap2(document.getElementById("map_canvas"));
}


