function getIcon(image)
{
	var icon = new GIcon();
	icon.image = "http://verdwaaldvuil.be/images/icons/ico_map_"+image+".png";
	icon.shadow = "http://verdwaaldvuil.be/images/icons/shadow.png";
	icon.iconSize = new GSize(30.0, 33.0);
    icon.shadowSize = new GSize(31.0, 33.0);
    icon.iconAnchor = new GPoint(13.0, 33.0);
    icon.infoWindowAnchor = new GPoint(13.0, 33.0);
	
	return icon;
}

function initMaps()
{
	$('.map').each(function(){
		var lat = $(this).find('.lat').text();
		var long = $(this).find('.long').text();
		var cat = $(this).find('.cat').text();
		var map = new GMap2(document.getElementById(this.id));
		map.setCenter(new GLatLng(lat,long), 15);
        map.setUIToDefault();
        map.addOverlay(new GMarker(new GPoint(long, lat),{icon: getIcon(cat)}));
	});
	
	if(jQuery.support.htmlSerialize)
	{
		$(".detail_entry").hide();
	}
	else
	{
		$(".more").toggleClass("less");
	}
}

$(document).ready(function() 
{
	initMaps();
	//
	var hash = document.location.hash;
	$(hash).nextAll('.detail_entry').show();
	$(hash).next().next().find(".more").toggleClass("less");
	
	$(".more").click(function(){
		if(jQuery.support.htmlSerialize)
		{
			$(this).parent().next().slideToggle();
		}else{
			$(this).parent().next().toggle();
		}
		
	    $(this).toggleClass("less");
	});
	
	$('.vote').click(function(){
		var urlSeg = this.name;
		var voteBtn = $(this);
		$.ajax({
			type:"GET",
			url:'/map/add_vote/'+urlSeg.replace(/_/, "/"),
			error:function(data){
				//console.log(data);
			},
			success:function(data){
				voteBtn.prevAll(".count").html(data);
				voteBtn.text("Bedankt voor je stem");
			}
		});
	});
	$(".lightbox").lightbox();
});


