

$(document).ready(function(){
	
	$("a[rel='colorbox']").colorbox();
	
	getList();
	

	
	
});


function gotoLink (htmlElement) {
	
	var destinationURL = "";
	var target = "";
	
	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}
	
	if(target == "_blank") {
		window.open(destinationURL);
	}
	else {
		location.href = destinationURL;
	}
}

function getListBig() {

	$.get('/bdb/images/getlistbig/', function(data) {
		$('#downloadlistebig').html(data);
	});

}

function getList() {

	$.get('/bdb/images/getlist/', function(data) {
		$('#downloadliste').html(data);
	});
	
	getListBig()

}



function imageAdd(id, titel, format) {
	
	if(format == null) {
		format = "feindaten";
	}

	$.post('/bdb/images/add/'+id+'/'+encodeURIComponent(titel)+'/'+format, {title: titel}, function(data) {
		getList();	  
	});
	
	$('#out_'+id).show();
	$('#in_'+id).hide();
}

function imageRemove(id) {

	$.get('/bdb/images/remove/'+id, function(data) {
		getList();	  
	});
	
	$('#out_'+id).hide();
	$('#in_'+id).show();
}

function showMap() {
	

	$('#map').css({'top': $('#karte').offset().top + 30, 'left': $('#content').offset().left - 9});
	
	
	$('#map').show('slow');

	initialize();

}
 
function hideMap() {

$('#map').hide('slow');

}


function showMapSingleDetail(titel,latidude,longtidude,z,pfad,link,id,detail) {

	
	$('#map').css({'top': $('#content').offset().top, 'left': $('#content').offset().left - 9});
	
	
	$('#map').show('slow');
	initializeSingle(titel,latidude,longtidude,z,pfad,link,id);

}

function showMapSingle(titel,latidude,longtidude,z,pfad,link,id,detail) {

	
		$('#map').css({'top': $('#'+id).offset().top, 'left': $('#content').offset().left - 9});
	
	
	$('#map').show('slow');
	initializeSingle(titel,latidude,longtidude,z,pfad,link,id);

}

function initializeSingle(titel,latidude,longtidude,z,pfad,link,id) {
	
	var latlng = new google.maps.LatLng(latidude,longtidude);
	var myOptions = {
		zoom: 14,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	var map = new google.maps.Map(document.getElementById("contentMap"), myOptions);
	

	var locationSingle = new Array();
	locationSingle.push(titel,latidude,longtidude,z,pfad,link);

	var locationSingleArray = new Array();

	locationSingleArray.push(locationSingle);
		
	//setMarkersSingle(map, locationSingleArray);
	
	
	addMarker(map, informations[id]);
	
}



function initialize() {
	
	var latlng = new google.maps.LatLng(51.43003944716933,7.5640869140625);
	var myOptions = {
		zoom: 8,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("contentMap"), myOptions);
	
	
	setMarkersHTML(map, locations);
	

	
}

/**
 * Data for the markers consisting of a name, a LatLng and a zIndex for
 * the order in which these markers should display on top of each
 * other.
 */




function setMarkersHTML(map, locations) {


  
  
  for (var i = 0; i < locations.length; i++) {
  
    var location = locations[i];
	addMarker(map, location);
  }
}



function addMarker (map, location) {

	var shape = {
		coord: [1, 1, 1, 50, 50, 50, 50 , 1],
		type: 'poly'
  };

    var myLatLng = new google.maps.LatLng(location[1], location[2]);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: makeImage('/static/img/map_image_marker.png'),
        shape: shape,
        title: location[0],
        zIndex: 11
    });
  
	var contentString = '<table border="0" cellpadding="3" cellspacing="0">'+
						'<tr><td colspan="2" style="font-size:15px;">'+location[0]+' &nbsp; <small>(Bild Nr.:'+location[8]+')</small></td></tr>'+
						'<tr><td style="vertical-align:top;" rowspan="3"><a href="'+location[5]+'"><img border="0" src="'+location[4]+'"></a></td></tr>'+
						'<tr><td style="vertical-align:bottom; height:22px;font-size:14px; font-weight:bold;  width:300px;" >Beschreibung</td></tr>'+
						'<tr><td style="vertical-align:top; ">'+location[6]+'</td></tr>'+
						'<tr><td style="vertical-align:top; font-style:italic; " colspan="2">'+location[10]+'</td></tr>'+

						'</table>';

	var infowindow = new google.maps.InfoWindow({
		content: contentString
		
		
		
	});

	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
  
}

function setMarkersSingle(map, locations) {

  
  	var shape = {
		coord: [1, 1, 1, 170, 168, 170, 168 , 1],
		type: 'poly'
  };


  
  for (var i = 0; i < locations.length; i++) {
  
    var location = locations[i];
    var myLatLng = new google.maps.LatLng(location[1], location[2]);
	
	
	
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: makeImageSingle(location[4]),
        shape: shape,
        title: location[0],
        zIndex: 11
    });
	
	
	
  google.maps.event.addListener(marker, 'click', function() {
    
	document.location.href = location[5];
});

  
  
    var location = locations[i];
    var myLatLng = new google.maps.LatLng(location[1], location[2]);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: makeImageSingleBG('/static/img/map_image_bg_single.png'),
        zIndex: 10
    });
  
  
  
  }
}

function makeImage(pfad) {

	var image = new google.maps.MarkerImage(pfad,
	new google.maps.Size(48, 51),
	new google.maps.Point(0,0),
	new google.maps.Point(23,48));
	
	return image;
	
	
}

function makeImageSingleBG(pfad) {

	var image = new google.maps.MarkerImage(pfad,
	new google.maps.Size(170, 188),
	new google.maps.Point(0,0),
	new google.maps.Point(85,190));
	
	return image;
	
	
}


function makeImageSingle(pfad) {	

	var image = new google.maps.MarkerImage(pfad,
	new google.maps.Size(150, 150 ),
	new google.maps.Point(0,0),
	new google.maps.Point(75,179));
	


  return image;

}

var showMe;

function showPreview(id) {
	detailId = id;
	detailCounter = 3;
}


function hidePreview(id) {	
	$('.previewContent').hide();
	detailId = 0;
	detailCounter = 0;
}


var detailId = 0;
var detailCounter = 0;
setInterval(function () {
	detailCounter--;
	if ( detailId && !detailCounter ) {
		for (var i = 0; i < array_ids.length; i++) {
			$('#preview_'+array_ids[i]).hide();
		}
		$('#preview_'+detailId).show('slow');
	}
}, 300);


function showDetailSearch () {

	$('#DetailSearch').show();
	$('#detailSearchValue').val('1');
	
	$('#datum_von').val('');
	$('#datum_bis').val('');
	$('#region').val('');
	$('#kategorie').val('');
	

}

function hideDetailSearch () {

	$('#DetailSearch').hide();
	$('#detailSearchValue').val('0');

}







