$(document).ready(function() {
	$('a.delete').click(function() {
		if (jQuery(this).attr('title').indexOf("el ") > -1)
			return confirm('\u00BFDesea borrar '+jQuery(this).attr('title')+' seleccionado?');
		else
			return confirm('\u00BFDesea borrar '+jQuery(this).attr('title')+' seleccionada?');
	}); 
	if($.fn.fancybox) {	
		$("a.fancybox").fancybox({ 'overlayShow': true, 'zoomSpeedIn': 300, 'zoomSpeedOut': 300 });
		$("a.lightbox").fancybox({ 'overlayShow': true, 'zoomSpeedIn': 300, 'zoomSpeedOut': 300 });
	}
	$('a[class="external"]').click( function() {
		this.target = "_blank";
	});
	$('a.linkback').click(function() {
		history.back();
		return false;
	});

});

function showPreview(coords) {	
	if (parseInt(coords.w) > 0) {
		var rx = 470 / coords.w;
		var ry = 352 / coords.h;

		if ($("#shirt_image_name").length) {
			$('#preview').css({
				width: Math.round(rx * $('#shirt_image_name').width()) + 'px',
				height: Math.round(ry * $('#shirt_image_name').height()) + 'px',
				marginLeft: '-' + Math.round(rx * coords.x) + 'px',
				marginTop: '-' + Math.round(ry * coords.y) + 'px'
			});
		}	
		jQuery('#x').val(coords.x);
		jQuery('#y').val(coords.y);
		jQuery('#w').val(coords.w);
		jQuery('#h').val(coords.h);		
	}
};
function setMarkers(map, locations) {
	var image = new google.maps.MarkerImage(
		'/images/shop-icon.png',
		// This marker is 20 pixels wide by 32 pixels tall.
		new google.maps.Size(20, 32),
		// The origin for this image is 0,0.
		new google.maps.Point(0,0),
		// The anchor for this image is the base of the flagpole at 0,32.
		new google.maps.Point(0, 32)
	);
	var shadow = new google.maps.MarkerImage(
		'/images/shop-shadow.png',
		// The shadow image is larger in the horizontal dimension
		// while the position and offset are the same as for the main image.
		new google.maps.Size(37, 32),
		new google.maps.Point(0,0),
		new google.maps.Point(0, 32)
	);
		// Shapes define the clickable region of the icon.
		// The type defines an HTML <area> element 'poly' which
		// traces out a polygon as a series of X,Y points. The final
		// coordinate closes the poly by connecting to the first
		// coordinate.
		var shape = {
		coord: [1, 1, 1, 20, 18, 20, 18 , 1],
  		type: 'poly'
		};
	for (var i = 0; i < shops.length; i++) {
		var shop = shops[i];
		var myLatLng = new google.maps.LatLng(shop[1], shop[2]);
		var marker = new google.maps.Marker({
        	position: myLatLng,
        	map: map,
        	shadow: shadow,
        	icon: image,
        	shape: shape,
        	title: shop[0],
        	zIndex: shop[3]
    	});
    	markerInfowindow = Array();
    	markerInfowindow = new google.maps.InfoWindow({ content: shop[4] });
    	google.maps.event.addListener( marker, 'click', function() { markerInfowindow.open(map, marker) });
  	}
}
