function addEmoticon(area, code) {
  $('#'+area).val($("#"+area).val()+" " + code + " ");
}

function deleteComment(id) {
	$.get("/modules/destinations/ajax/deleteComment.php?id="+ id, 
	  function(data){
	    if(data == "YES") {
		    $("#commentBox"+id).fadeTo("slow",0.01).slideUp("slow");
	    }
	    else {
	    	alert('Възникнала е грешка при изтриването.')
	    }
  	}
  );
}

/*
 * PHOTOS
 */
function selectAllCheckBoxes(b) {	
	$("input[type='checkbox']").each(function() {
		this.checked = b;
		
		var id = $(this).val();
		
		if(b) {
			$("#photoBox"+id).css('border-color','red');
		}
		else {
			$("#photoBox"+id).css('border-color','#908768');
		}
		
	});
}

$(document).ready(function () {
	$("input[name^='delete']").click(function () {
		var id = $(this).val();
		if($('#iDelete'+id).is(':checked')){
			$("#photoBox"+id).css('border-color','red');
		}
		else{
			$("#photoBox"+id).css('border-color','#908768');
		}
		
	});
	
});

/*
 * AJAX BOX
 */
$().ajaxSend(function(r,s){  
	$("#loading").show();  
});  
	   
$().ajaxStop(function(r,s){  
	$("#loading").fadeOut("fast");  
});

/*
 * GOOGLE MAP
 */

var googleMap = null;
var googleGeoCoder = null;
var googleMarkerManager = null;
var reload = true;

function initializeGoogleMaps() {
	if (GBrowserIsCompatible()) {
		googleMap = new GMap2(document.getElementById("map"));
      
		var center = new GLatLng(43.076913126087106, 25.6201171875);
        googleMap.setCenter(center, 12);
        googleMap.setMapType(G_HYBRID_MAP);
        googleMap.addControl(new GLargeMapControl());
        googleMap.addControl(new GMapTypeControl());
        
        googleMarkerManager = new MarkerManager(googleMap);
        //mgr.refresh();
    }
  }

var destinationIcon = new GIcon();
destinationIcon.image = "/data/images/icons/32/globe.png";
destinationIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
destinationIcon.iconSize = new GSize(32, 32);
destinationIcon.shadowSize = new GSize(22, 20);
destinationIcon.iconAnchor = new GPoint(6, 20);
destinationIcon.infoWindowAnchor = new GPoint(5, 1);
                
var sightIcon = new GIcon();
sightIcon.image = "/data/images/icons/32/pin.png";
sightIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
sightIcon.iconSize = new GSize(32, 32);
sightIcon.shadowSize = new GSize(22, 20);
sightIcon.iconAnchor = new GPoint(6, 20);
sightIcon.infoWindowAnchor = new GPoint(5, 1);
                
var restaurantIcon = new GIcon();
restaurantIcon.image = "/data/images/icons/32/coffee_cup.png";
restaurantIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
restaurantIcon.iconSize = new GSize(32, 32);
restaurantIcon.shadowSize = new GSize(22, 20);
restaurantIcon.iconAnchor = new GPoint(6, 20);
restaurantIcon.infoWindowAnchor = new GPoint(5, 1);
                
var entertainmentIcon = new GIcon();
entertainmentIcon.image = "/data/images/icons/32/music.png";
entertainmentIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
entertainmentIcon.iconSize = new GSize(32, 32);
entertainmentIcon.shadowSize = new GSize(22, 20);
entertainmentIcon.iconAnchor = new GPoint(6, 20);
entertainmentIcon.infoWindowAnchor = new GPoint(5, 1);
                
var shopIcon = new GIcon();
shopIcon.image = "/data/images/icons/32/shopping_cart.png";
shopIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
shopIcon.iconSize = new GSize(32, 32);
shopIcon.shadowSize = new GSize(22, 20);
shopIcon.iconAnchor = new GPoint(6, 20);
shopIcon.infoWindowAnchor = new GPoint(5, 1);
                
function reloadMarkers() {
	jQuery.getJSON('/modules/destinations/ajax/mapMarkers.php', {'zoomLevel' : googleMap.getZoom(), 'swlat' : googleMap.getBounds().getSouthWest().lat(), 'swlng' : googleMap.getBounds().getSouthWest().lng(), 'nelat' : googleMap.getBounds().getNorthEast().lat(), 'nelng' : googleMap.getBounds().getNorthEast().lng()}, function(data) {
		googleMarkerManager.clearMarkers();
		var batch = [];
		var marker = new Array();		
		jQuery.each(data, function(i, val) {
			if(val.type == 'destination') {
				marker[i] = new GMarker(new GLatLng(val.google_lat, val.google_lit), { icon: destinationIcon });				
			}
			else if(val.type == 'sight') {
				marker[i] = new GMarker(new GLatLng(val.google_lat, val.google_lit), { icon: sightIcon });
			}
			else if(val.type == 'restaurant') {
				marker[i] = new GMarker(new GLatLng(val.google_lat, val.google_lit), { icon: restaurantIcon });
			}
			else if(val.type == 'entertainment') {
				marker[i] = new GMarker(new GLatLng(val.google_lat, val.google_lit), { icon: entertainmentIcon });
			}
			else if(val.type == 'shop') {
				marker[i] = new GMarker(new GLatLng(val.google_lat, val.google_lit), { icon: shopIcon });
			}
			GEvent.addListener(marker[i], 'click', function() {
				reload = false;
				marker[i].openInfoWindowHtml('<a href="'+ val.url +'" title="">'+ val.name +'</a><br /><br />Вид на обекта: '+ val.description);
		      });
			batch.push(marker[i]);
	    });
		
		googleMarkerManager.addMarkers(batch, 0);
		googleMarkerManager.refresh();
	}); 
}