$(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 });
	}
	if ($("#language-selector").length) {
		$("#language-selector").hover(function() {
			$("#language-selector").css("height", "120px");
			$("#language-selector ul").css("display", "block")
		}, function() {
			$("#language-selector").css("height", "37px");
			$("#language-selector ul").css("display", "none")	
		});
	}
	if ($('.thumb-wrapper').length > 0) {
		$('.thumb-wrapper a').append('<img src="/images/thumb-mask.gif" alt="" />');	
	} // end if

	if ($('.mid-wrapper').length > 0) {
		$('.mid-wrapper a').append('<img src="/images/mid-mask.gif" alt="" />');	
	} // end if
	
	if ($('.listado-fotos-torneo').length > 0) {
		$('.listado-fotos-torneo a').append('<img src="/images/thumb-mask.gif" alt="" />');	
	} // end if
	
	$("a[rel='external']").click(function(){
		window.open($(this).attr("href"));
		return false;
	});

});

function showPreview(coords) {	
	if (parseInt(coords.w) > 0) {
		var rx = 470 / coords.w;
		var ry = 352 / coords.h;

		if ($("#tournament_image_name").length) {
			$('#preview').css({
				width: Math.round(rx * $('#tournament_image_name').width()) + 'px',
				height: Math.round(ry * $('#tournament_image_name').height()) + 'px',
				marginLeft: '-' + Math.round(rx * coords.x) + 'px',
				marginTop: '-' + Math.round(ry * coords.y) + 'px'
			});
		}
		if ($("#tournament_photo_name").length) {
			$('#preview').css({
				width: Math.round(rx * $('#tournament_photo_name').width()) + 'px',
				height: Math.round(ry * $('#tournament_photo_name').height()) + 'px',
				marginLeft: '-' + Math.round(rx * coords.x) + 'px',
				marginTop: '-' + Math.round(ry * coords.y) + 'px'
			});
		}
		if ($("#notice_image").length) {
			$('#preview').css({
				width: Math.round(rx * $('#notice_image').width()) + 'px',
				height: Math.round(ry * $('#notice_image').height()) + 'px',
				marginLeft: '-' + Math.round(rx * coords.x) + 'px',
				marginTop: '-' + Math.round(ry * coords.y) + 'px'
			});
		}		
		if ($("#curiosity_image").length) {
			$('#preview').css({
				width: Math.round(rx * $('#curiosity_image').width()) + 'px',
				height: Math.round(ry * $('#curiosity_image').height()) + 'px',
				marginLeft: '-' + Math.round(rx * coords.x) + 'px',
				marginTop: '-' + Math.round(ry * coords.y) + 'px'
			});
		}	
		if ($("#treatment_image").length) {
			$('#preview').css({
				width: Math.round(rx * $('#treatment_image').width()) + 'px',
				height: Math.round(ry * $('#treatment_image').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);		
	}
};