$(function(){
	$.datepicker.regional['en'] = {
			closeText: 'Done',
			prevText: 'Prev',
			nextText: 'Next',
			currentText: 'Today',
			monthNames: ['January','February','March','April','May','June',
			'July','August','September','October','November','December'],
			monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
			'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
			dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
			dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
			dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
			weekHeader: 'Wk',
			dateFormat: 'dd/mm/yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
	$.datepicker.regional['it'] = {
			closeText: 'Chiudi',
			prevText: '&#x3c;Prec',
			nextText: 'Succ&#x3e;',
			currentText: 'Oggi',
			monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
				'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
			monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
				'Lug','Ago','Set','Ott','Nov','Dic'],
			dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
			dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
			dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
			weekHeader: 'Sm',
			dateFormat: 'dd/mm/yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};

	Shadowbox.init({
		language: language['code'],
		players: ['img', 'flv', 'qt', 'html']
	});
	
	$.datepicker.setDefaults($.datepicker.regional[language.code]);
	$('#calendar').datepicker({
		dateFormat: 'yy-mm-dd',
		defaultDate: $.cookie('cal_ym') ? new Date(parseInt($.cookie('cal_ym'))) : new Date(),
		beforeShowDay: function(date){
			var spect = spects && spects[date.valueOf() / 1000];
			return [spect,
			        spect ? 'ui-state-highlight' : 'ui-datepicker-unselectable ui-state-disabled',
			        spect ? spect[1] : ''];
		},
		onSelect: function(dateText, inst){
			var dt = dateText.split(/\D+/);
			dt = new Date(dt[0], dt[1] - 1, dt[2]);
			var spect = spects[dt.valueOf() / 1000];
			location.href = spect[0];
		},
		onChangeMonthYear: function(year, month, inst){
			$.cookie('cal_ym', (new Date(year, month - 1, 1)).valueOf());
		}
	});
	
	$('a[rel=ipop]').click(function(){
		window.scroll(0, 0);
		
		var popup = $('<div id="popup"><div class="close"></div><img src="' + URL_WS_SITE + 'images/design/loading.gif" alt="" style="margin-top:100px;" /><iframe src="" border="0" width="100%" height="100%" frameborder="0" style="display:none;"></iframe></div>').prependTo('body').hide();
		var bw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
		var bh = $('body').height();
		var w = parseInt(popup.css('width'));
		var h = parseInt(popup.css('height'));
		
		var ifr = $('iframe', popup);
		ifr.load(function(){
			$('img', popup).remove();
			ifr.fadeIn();
		});
		ifr.attr('src', $(this).attr('href'));
		
		popup.css({
			position: 'absolute',
			top: Math.max(100, Math.round((window.innerHeight - h) / 2)) + 'px',
			left: Math.round((bw - w) / 2) + 'px',
			width: w + 'px',
			height: h + 'px',
			zIndex: '1000',
			textAlign: 'center'
		}).fadeIn();
		
		$('.close', popup)
			.css('cursor', 'pointer')
			.click(function(){ $(popup).fadeOut('normal', function(){ $(this).remove(); }); });

		return false;
	});
	
	html = '';
	for(var i in hdr_images)
		html += '<img src="' + hdr_images[i] + '" alt="Testata Napoli Teatro Festival" />';
		
	if(html) {
		var cur = $('#testata').html();
		$('#testata').html(html).cycle({ delay:2000, speed:1000 }).append(cur);
	}
});

