var CustomScript = {
	initialize: function(){
		$.ajaxSetup ({
			  // Disable caching of AJAX responses */
			  cache: false
		});

		CustomScript.disableContextMenu('#big_image_a');
		
		$('.counter').each(function(idx, el){
		CustomScript.countdownFunc('#'+$(el).attr('id'));
		});
		//CustomScript.countdownFunc('#salecounter');
	},
	disableContextMenu: function(sel){
		 $(sel).bind('contextmenu', function(e) {
			 e.stopPropagation();
			  return false;
			});
	},
	countdownFunc: function(sel){
      			if (sel!=undefined && $(sel)){
      				var now = new Date();
      				//y2k = new Date("Mar 26 2010 08:30:00");
      				var y2k = new Date($(sel).attr('rel'));
      				var days = (y2k - now) / 1000 / 60 / 60 / 24;
      				var daysRound = Math.floor(days);
      				var hours = (y2k - now) / 1000 / 60 / 60 - (24 * daysRound);
      				var hoursRound = Math.floor(hours);
      				var minutes = (y2k - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
      				var minutesRound = Math.floor(minutes);
      				var seconds = (y2k - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
      				var secondsRound = Math.round(seconds);
      				var sec = (secondsRound == 1) ? " secondo " : " secondi ";
      				var min = (minutesRound == 1) ? " minuto " : " minuti ";
      				var hr = (hoursRound == 1) ? " ora " : " ore ";
      				var dy = (daysRound == 1)  ? " giorno " : " giorni "
      				
      				var txt='';
      				if (daysRound>0){
      					txt += '<span>' + daysRound + 'DD'+'</span>'   ;
      				}
      				txt += '<span>' +hoursRound+ 'HH'+ '</span>';
      				txt += '<span>' +minutesRound + 'MM' +'</span>';
      				txt += '<span>' +secondsRound+ 'SS' +'</span>';
      				
      				$(sel).html(txt);
      				
      				
      				var newtime = window.setTimeout('CustomScript.countdownFunc("'+sel+'")', 1000);
      			}
      	}
};

$(document).ready(CustomScript.initialize)

