jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true,
        find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
        replace: '$1@$2'
    }, settings);
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            $(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
            var is_link = true;
        }
        $(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
    });
};

$(document).ready(function(){
	
	$('#resteVide').hide();
	
	var semaine = new Array('wednesday','thursday','friday','saturday','sunday');
	var total = 0;
	$('input[name="compute"]').hide();
	for (var i=0; i < semaine.length; i++) {
		$('input[name="buyTickets[tickets]['+semaine[i]+'][quantity]"]').keyup(function(e){
			$(this).parent().parent().children().children(".subTotal").val($(this).val() * $(this).parent().parent().children(".price").html().replace(/ €/gi, ""));
			$('.subTotal').each(function() {
				total += parseInt($(this).val());
			});
			if(total > 0){
				total += parseFloat($('input[name="fees"]').val());
			}
			// console.log(total.toString().replace(/ €/gi, ""));
			$('#total').html(total.toString().replace(/\./, "\,")+" €");
			total = 0;
		});
	};
	$('input[name="emptyTickets"]').click(function() {
		$('#total').html("0 €");
	});
	
	$("#diaporama").append('<img src="/images/diapo/diapo-12.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-11.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-10.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-9.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-8.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-7.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-6.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-5.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-4.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-3.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-2.jpg" alt="Ethias Trophy 2009 - Challenger Tour" /><img src="/images/diapo/diapo-1.jpg" alt="Ethias Trophy 2009 - Challenger Tour" />');
	$("#diaporama").innerfade({
    speed: 3000,
    timeout: 4000,
    type: 'random',
    containerheight: '238px'
  });

  $(".adresse").defuscate();

   $.gaTracker('UA-10081017-1');

});

// Open a window of the desired size in the centre of the screen.
function openLSWindowTandR(year, wkno, lang, tabno, eventid, ref_file, width, height, hasScrollBars) {
	// ADD NAME FIELD and make sure it get's focus!!!
	var theWidth = width;
	var theHeight = height;
	var scrollBars = "scrollbars";
	if (hasScrollBars == false) scrollBars = "scrollbars=0";
	if ((theWidth == "")||(theWidth == null)) theWidth =500;
	if ((theHeight == "")||(theHeight == null)) theHeight =668;
	var theLeft = (screen.availWidth - theWidth)/2;
	var theTop = (screen.availHeight - theHeight)/2;
	var strCheckRef = escape(ref_file);

	var lsURL = "http://www.protennislive.com/frameset.asp?year="+year+"&wkno="+wkno+"&lang="+lang+"&tabno="+tabno+"&eventid="+eventid+"&ref="+strCheckRef;
	var popupWin = window.open(lsURL, '_' + Math.round(Math.random() * 1000000),'top='+theTop+',left='+theLeft+',menubar=0,toolbar=0,location=0,directories=0,status=0,'+scrollBars+',width='+theWidth+', height='+theHeight);
}
