$(document).ready(function() {
	gmaps = new GMaps();
	
	//gmaps.loadMap(47.047863, 10.61965529999998, 5);
	
	$(".point").click(function() {
		var coords = $(this).attr("title").split(",");
		gmaps.centerMap(coords[0], coords[1], $(this).attr("id"));
		
		return false;
	});
	$(".zoomlevel").change(function() {
		gmaps.setZoom($(this).val());
		
		return false;
	});
	
	$("#delete").live('click', function() {
		$.ajax({
			url: "/building_blocks/rmvBuildingBlockToTour/"+$(this).attr('class'),
			success: function(data){
				$("#addedBuildingBlocks").html(data);
			}
		});
		return false;
	});
	$("#show").live('click', function() {
		$("#addedBuildingBlocks ul").each(function() {
			$(this).slideUp();
		});
		$("#block"+$(this).attr("class")).slideDown();
		return false;
	});
	$("#up").live('click', function() {
		$.ajax({
			url: "/building_blocks/up/"+$(this).attr('class'),
			success: function(data){
				$("#addedBuildingBlocks").html(data);
			}
		});
		return false;
	});
	$("#down").live('click', function() {
		$.ajax({
			url: "/building_blocks/down/"+$(this).attr('class'),
			success: function(data){
				$("#addedBuildingBlocks").html(data);
			}
		});
		return false;
	});
	
	$("#buildingBlockCount").html($("#buildingBlockCountLoaded").val());
	
	$("#addToBuildingBlocks").live('click', function() {
		addBuildingBlock($(this).attr("href"));
		return false;
	});
	
	$("#selectTravelType").change(function() {
		var country = '';
		var travelType = '';
		if ($(this).val() != '') travelType = '/reisvorm:'+$(this).val();
		if ($("#selectCountry").val() != '') country = '/'+$("#selectCountry").val();
		if ($(this).val() == 'Thema') {
			$("#select").slideDown();
		} else {
			$("#themeHiddenDiv").slideUp();
		}
		window.location = '/bestemmingen'+country+travelType;
	});
	
	$("#selectCountry").change(function() {
		var travelType = '';
		var country = '';
		if ($("#selectTravelType").val() != '') travelType = '/reisvorm:'+$("#selectTravelType").val();
		if ($(this).val() != '') country = '/'+$(this).val();
		window.location = '/bestemmingen'+country+travelType;
	});
	
	$("#changeCountry").change(function() {
		
		window.location = "/"+$(this).val();
	});
	
	$("#selectTheme").change(function() {
		var travelType = '';
		var country = '';
		var theme = '';
		if ($("#selectTravelType").val() != '') travelType = '/reisvorm:'+$("#selectTravelType").val();
		if ($("#selectCountry").val() != '') country = '/'+$("#selectCountry").val();
		if ($(this).val() != '') theme = '/theme:'+$(this).val();
		window.location = '/bestemmingen'+country+travelType+theme;
	});
	
//	$(".fancybox").fancybox({
//		'transitionIn'	: 'elastic',
//		'transitionOut'	: 'elastic'
//	});
});
function loadAjaxInfo(slug) {
//	$('section.content div').html('<img src="/img/ajax-loader.gif" />');
//	$.ajax({
//	  url: "/ajax/"+slug,
//	//  context: document.body,
//	  success: function(data){
//		  $('section.content div').html(data);
//	  }
//	});
	window.location = '/'+slug;
}
function loadBlockView(id) {
	$.ajax({
		url: "/building_blocks/loadBox/"+id,
		success: function(data){
			$("#infoPanel").html(data);
			$("#infoPanel").fadeIn();
		}
	});
}

function addBuildingBlock(id) {
	$.ajax({
		url: "/building_blocks/addBuildingBlockToTour/"+id,
		success: function(data){
			$("#addedBuildingBlocks").html(data);
			$("#buildingBlockCount").html($("#addedBuildingBlocks > h1").size());
		}
	});
	return false;
}
function changeZoom(zoomlevel) {
	$(".zoomlevel").val(zoomlevel);
}

function setCoords(coords) {
	$(".lat").val(coords.lat());
	$(".lon").val(coords.lng());
}

