/* FILMATO YOUTUBE */
function youtube(id,W,H,container) {
	var params = {
		allowfullscreen: 'true',
		allowscriptaccess: 'sameDomain',
		wmode: 'transparent'
	};
	var attributes = {
		id: container,
		name: 'YOUTUBE'
	};
	
	swfobject.embedSWF('http://www.youtube.com/v/'+id+'&showinfo=0&fs=1', container, W, H, '9.0.0', false, false, params, attributes);
}

/* GOOGLE MAPS */
var markers = [];
var counter=0;
var map;

function setTo(lat,lon){
	var centro = new GLatLng(lat, lon);
	map.setCenter(centro, 18);
}

function setToGe(lat,lon,zoom){
	var centro = new GLatLng(lat, lon);
	map.setCenter(centro, zoom);
}

function initialize() {
	if (GBrowserIsCompatible()) {      	
		map = new GMap2(document.getElementById("map_canvas",{mapTypes:[G_HYBRID_MAP,G_NORMAL_MAP,G_SATELLITE_MAP]}));
		map.setMapType(G_HYBRID_MAP);
		
		var centro = new GLatLng(38.1175926, 13.3662347);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.setCenter(centro, 14);
	}
}

function addPoint(address,title,body){
	geocoder = new GClientGeocoder();   
	geocoder.getLatLng(address,
		function(point) {
		  if (!point) {
			errors[counter]= address+"//";
			counter++;
		  } else {
			var marker = new GMarker(point,{'title': title});			        			        
			marker.bindInfoWindowHtml(body);
			markers[counter]=marker;
			counter++;
			map.addOverlay(marker);
		  }
		}
	);
}

function addBig(lat,lng,title,body){
	var point = new GLatLng(lat,lng);
	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://festival.ariadne.it/contents/instance1/images/markers/markerB.png";
	markerOptions = { 'icon':blueIcon , 'title': title};
	var marker = new GMarker(point,markerOptions);
	marker.bindInfoWindowHtml(body);
	map.addOverlay(marker);
}

function addInfo(lat,lng,title,body){
	var point = new GLatLng(lat,lng);
	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://festival.ariadne.it/contents/instance1/images/markers/markerI.png";
	markerOptions = { 'icon':blueIcon , 'title': title};
	var marker = new GMarker(point,markerOptions);
	marker.bindInfoWindowHtml(body);
	map.addOverlay(marker);
}

function addLatLng(lat,lng,title,body,num){
	var point = new GLatLng(lat,lng);
	var point = new GLatLng(lat,lng);
	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://festival.ariadne.it/contents/instance1/images/markers/marker"+num+".png";  			
	var marker = new GMarker(point,{'title': title,'icon':blueIcon});
	marker.bindInfoWindowHtml(body);
	map.addOverlay(marker);
}

/* MAPPA DEI POLI */
$(function(){
	$('#art-poli-container').hide();
	$('.art-poli').each(function(i){
		$(this).css({'display':'none','z-index':i,'position':'absolute','left':0,'top':0});
		$(this).addClass('.art-poli-js');
		$(this).css('z-index',i);
	});
});

function setPoliPoint(idart) {
	$('#art-poli-container').show();
	$('.art-poli').each(function(){
		if($(this).attr('id') != idart){
			$(this).fadeOut('fast');
			$(this).next('a').hide();
		} else {
			$('#art-poli-container').height($('#'+idart).outerHeight());
			$(this).fadeIn('slow');
			$(this).next('a').show();
			$(this).next('a').css({'position':'absolute','left':($('#'+idart).outerWidth())+3,'top':0});
		}
	});
}

/* QUESTIONARI */
$(function(){
	$('#modulo').submit( function(){
		if($('#modulo input[name="privacy"]:checked').val()=='Y'){
			return true;
		} else {
			return false;	
		}
	});
});

/* AREA RISERVATA */
$(function(){
	$('#reset').click(function(){
		var form_id = $(this).parents('form').attr('id');
		$('#'+form_id).find('input:text, input:password').each(function(){
			$(this).attr('value','');
		});
	});
});

/* SLIDE IMMAGINI HOMEPAGE */
function slideTopImg() {
	var i=1;
	
	$('#img-top-container img.img-top-home:first').show();
	if ($('#img-top-container img.img-top-home').length > 1) {
		var timer = setInterval(function(){
			$('#img-top-container img.img-top-home:visible').fadeOut(2000);
			if ( i >= $('#img-top-container img.img-top-home').length) i = 0;
			$('#img-top-container img.img-top-home:eq('+i+')').fadeIn(2000);
			i++;
		},6000);
	}
}

/* AGGIUNGE UNA PAGINA NEI PREFERITI */								
function preferiti(titolo,indirizzo) {
	title =titolo;
	url = indirizzo;
	if (window.sidebar) {
	// Preferiti per Mozilla Firefox 
	window.alert('Clicca con il tasto destro del mouse e scegli Aggiungi pagina nei segnalibri\noppure premi Ctrl D')
	} else if( window.external ) {
	// Preferiti per MSIE 
	window.external.AddFavorite(url, title);
	}
	// Preferiti per altri browser
	else {window.alert('Aggiungi questo sito ai preferiti')
	}
}
		