// JavaScript Document
function CheckForSubmit(NomeCampo, NomeForm, NomeBottone, Codice) {
	var idform = 1;
	var Valore = document.forms[NomeForm].elements[NomeCampo].checked;
	if (Valore) {
		document.forms[NomeForm].elements[NomeBottone].disabled=false;
		document.forms[NomeForm].elements[Codice].value="1";
		document.forms[NomeForm].action = "formsub.asp?send=true"
	}
	else {
		document.forms[NomeForm].elements[NomeBottone].disabled=true;
		document.forms[NomeForm].elements[Codice].value="0";
	};
};

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2458432-27']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

window.addEvent("load", function() {
								 /*var host = new URI();
								 var host2 = host.toString();
								 var querystring = host.get('data');
								 
								 var css = querystring['acc'];
								 if (css.toString()!="") {
									if (css.toString()=="e") {
										var myCookie = Cookie.write("css", "E", 0);
									};
								 };*/
									
								 
								 
								 

	
	if ($('gmapworld')) load();
	

	if ($('map_canvas')) initialize();

	
});



window.addEvent("domready", function() {
	$('digitaldomain').addEvent("click", function(e){
		e = new Event(e).stop();
		document.location.href=this.getChildren('a').getProperty('href');
	});
	var c1_w = 940; //  Carousal Item Width 
	var c1_n = 3; // Total Number of Carousal Items  
	var c1_pp = 1  // Number of  Carousal Items  perpage
	var c1_marginFactor = 1;
	
	var c1_sss = c1_w * c1_pp ; //sss = slide step size 
	var c1_ns =  parseInt(((c1_w * c1_n)/c1_sss) + .5); //ns= number of slides 
	c1_sss += c1_marginFactor ; //sss = slide step size , 51 for margins


	if ($('wrapslides')) var carousel1 =  new MooCarousel('wrapslides','slides','prev','next',c1_ns,c1_sss, true); //c_ns= number of slides , c_sss = slide step size
		
	/*var params = { allowScriptAccess: "always", wmode: "transparent" };
	var atts = { id: "swfvalci" };

	swfobject.embedSWF("http://www.valci.com/swf/valci.swf", "swfvalci", "150", "100", "8", null, null, params, atts);	*/
			
			
			
			
			
			
			
			
	/*
	//***************************MENU TOP SEZIONI->GRUPPI***************************
	$$('li.menutop').addEvent('mouseenter', function(e){
		e = new Event(e).stop();
		if (this.getProperty('id')) {
			if (this.getProperty('id')!="") {
				$$('div.menu_sezioni').setStyle('display','none');
				id_li = this.getProperty('id');
				Indice_Menu = id_li.replace("mnutop_","");
				$("mnu_sez_" + Indice_Menu).setStyle('display','block');
			}
			else {
				$$('div.menu_sezioni').setStyle('display','none');
			};
		}
		else {
			$$('div.menu_sezioni').setStyle('display','none');
		};
	});
	$$('li.menutop').addEvent('mouseleave', function(e){
		e = new Event(e).stop();
		$$('div.menu_sezioni').setStyle('display','none');
	});*/
			

			
	if ($('frmmail')) {
		new FormCheck('frmmail');
		$('privacy').setProperty('checked')==false;
		$('privacy').addEvent('change', function(e){
			e = new Event(e).stop();
			if (this.getProperty('checked')==true) {
				$('frmmail').setProperty('action','/include/sub_form_contatti.asp');
			}
			else {
				$('frmmail').setProperty('action','');
			};
		});
	};
	
	
	/*$('stemma_home_bottom').addEvent('click', function(e){
		e = new Event(e).stop();
		if (this.getElements('a') != "") document.location.href = this.getElements('a').getProperty('href');
	});
	$('stemma_home_top').addEvent('click', function(e){
		e = new Event(e).stop();
		if (this.getElements('a') != "") document.location.href = this.getElements('a').getProperty('href');
	});
	
	
	$$('a.noclick').addEvent('click', function(e){
		e = new Event(e).stop();
	});*/
	if ($$('a.noclick').length>0) {
		$$('a.noclick').addEvent('click', function(e){
			e = new Event(e).stop();
		});
	}
	if ($$('videogallery_e a img')) {
		$$('.videogallery_e a img').addEvent("mouseover", function(e) {
			e = new Event(e).stop();
			//this.setProperty('src','/images/bg_play_hover.png');
			var nome_file = this.getProperty('src');
			this.setProperty('src', nome_file.replace('.png', '_hover.png'));
		});
		
		$$('.videogallery_e a img').addEvent("mouseout", function(e) {
			e = new Event(e).stop();
			//this.setProperty('src','/images/bg_play.png');
			var nome_file = this.getProperty('src');
			this.setProperty('src', nome_file.replace('_hover.png', '.png'));
		});
	}
	
	//new SmoothScroll({duration: 1000}); 
	new SmoothScroll({ duration:700 }, window);
	if ($('myGallery')) {

		if (($$('div.imageElement h3')).length > 0) {
			var myGallery = new gallery($('myGallery'), {showInfopane:true});
		}
		else {
			var myGallery = new gallery($('myGallery'), {});
		};
	};
	
	

	
	if($$('thumb_list_product')) {
		ReMooz.assign('a.zoom', {
			'origin': 'div.thumb_list_product',
			'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
			'resizeFactor': 0.8, // resize to maximum 80% of screen size
			'cutOut': false, // don't hide the original
			'opacityResize': 0.4, // opaque resize
			'dragging': true, // disable dragging
			'centered': true // resize to center of the screen, not relative to the source element
		});
	};
	
	/*var myAccordion = new Fx.Accordion($$('.test_uffici_settori'), $$('.cont_uffici_settori'), {
		display: -1,
		alwaysHide: true
	});*/
	
	
	
	
	$$('a.viewdet').addEvent("click", function(e) {
		e = new Event(e).stop();
		var idelemento = this.getProperty('id').replace('openmarker','');
		idelemento = idelemento.replace('_det','');
		var idelemento2 = idelemento.toInt();
		google.maps.event.trigger(allmarkers[idelemento2], 'click');
		map.setCenter(allmarkers[idelemento2].getPosition());
		map.setZoom(14);
	});
	
	
	
});

function cm_setInfowindow(newInfowindow) {
  if (cm_openInfowindow != undefined) {
    cm_openInfowindow.close();
  }
 
  cm_openInfowindow = newInfowindow;
}

var cm_openInfowindow;
var map;
var allmarkers = [];
function load() {
	var latlng = new google.maps.LatLng(42.04342076215259,14.740551710128784);
	var myOptions = {
		zoom: 2,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("gmapworld"), myOptions);
	
	
	
	
	var req_baloon2 = new Request.JSON({
		url: '/include/mondo.asp',
		onSuccess:function(responseJSON) {
			var marker = new google.maps.Marker({
				position: latlng, 
				map: map,
				title:"Valci"
			});
			attachSecretMessage(marker, null);
			allmarkers.push(marker);
			responseJSON.nazioni.each(function(nazione) {
				var point2 = new google.maps.LatLng(nazione.GoogleMapLatitudine,nazione.GoogleMapLongitudine);
				
				
				
				var marker_nazioni = new google.maps.Marker({
					position: point2, 
					map: map,
					title:nazione.Citta + ", " + nazione.Nazione
				});
				attachSecretMessage(marker_nazioni, nazione)
				
				var id_naz = nazione.IdElemento;
				allmarkers.push(marker_nazioni);
				
				
				
				
				
				
				
				
				
				
			});
			
			google.maps.event.trigger(allmarkers[0], 'click');
		}
		
	}).send();
}


function attachSecretMessage(marker, nazione) {
	google.maps.event.addListener(marker, 'click', function() {
		if (nazione) {
			//var content_string = "<div id='baloon_" + nazione.IdElemento + "' class='baloon_info'><strong>" + nazione.Citta + ", " + nazione.Nazione +"</strong></div>";
			var content_string = "";
			var obj_main = new Element('div', {
				'id': 'baloon_' + nazione.IdElemento,
				'class': 'baloon_info'
			});
			var obj_em  = new Element('em', {
				'text': "Clicca sulle immagini per maggiori dettagli"
			});
			var obj_br = new Element('br');
			var obj_strong = new Element('strong', {
				'text': nazione.Citta + ", " + nazione.Nazione
			});
			obj_strong.inject(obj_main);
			
			if (nazione.imgs) {
				var obj_main_gallery = new Element('div', {
					'class': 'gallery_baloon_info'
				});
				obj_br.inject(obj_main);
				obj_em.inject(obj_main);
				var c_count_imgs = 0;
				nazione.imgs.each(function(img) {
					var t_img_n = img.tname;
					var t_img_l = img.tl;
					var t_img_a = img.ta;
					
					var i_img_n = img.iname;
					var i_img_l = img.il;
					var i_img_a = img.ia;
					
					if (t_img_l < t_img_a) {
						var obj_div_b = new Element('div', {
							'class': 'cont_div_baloon f_left'
						});
						t_img_a = 60;
						t_img_l = 45;
						
					};
					
					
					var obj_a = new Element('a', {
						'href': img.iname,
						'title': img.ides,
						'class': 'zoom f_left'
					});
					var obj_img = new Element('img', {
						'class': 'imgrec_hor',
						'src': img.tname,
						'alt': img.ides,
						'height': t_img_a,
						'width': t_img_l
					});
					obj_img.inject(obj_a);
					//if ($("baloon_" + img.eid)) {
					if (t_img_l > t_img_a) {
						obj_a.inject(obj_main_gallery);
					}
					else {
						obj_a.inject(obj_div_b);
						obj_div_b.inject(obj_main_gallery);
					};
					//obj_a.inject(obj_main_gallery);
					//}
					//else {
						
						//alert ("no");
					//}
					c_count_imgs++;
					if (c_count_imgs == 3) {
						c_count_imgs = 0;
						var obj_div_spacer = new Element('div', {
							'class': 'clear spacer5 force_display_block'
						});
						obj_div_spacer.inject(obj_main_gallery);
					};
					
				});
				obj_main_gallery.inject(obj_main);
				//content_string = obj_main;
			};
			content_string = obj_main;
		}
		else {
			content_string = "<div class='baloon_info'><strong>Valci S.r.l.</strong><br /><em>Stabilimento di produzione</em/><br /><strong>Phone</strong>: +39.0873.549404, <strong>Fax</strong>: +39.0873.12.14<br /><strong>E-mail</strong>: <a href='mailto:info@valci.com' title='invia un messaggio di posta elettronica'>info@valci.com</a></div>";
			


			
			
		}
		var infowindow_nazioni = new google.maps.InfoWindow({
			content: content_string
		});
		infowindow_nazioni.open(map,marker);
		cm_setInfowindow(infowindow_nazioni);
		ReMooz.assign('a.zoom', {
			//'origin': 'div.thumb_list_product',
			'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
			'resizeFactor': 0.8, // resize to maximum 80% of screen size
			'cutOut': false, // don't hide the original
			'opacityResize': 0.4, // opaque resize
			'dragging': true, // disable dragging
			'centered': true // resize to center of the screen, not relative to the source element
		});
	});
	
}


function mia() {
	
	GEvent.addListener(map5, "moveend", function() {
		var center = map5.getCenter();
		var lt =center.Longitude;
		var lng=center.Latitude;
		document.getElementById("mioooooo").innerHTML = center.toString() + ',' + map5.getZoom();
	});
};





function carmine12345() {

var bl_swfUrl = "http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf";

var bl_flashver = "9.0.0"; //flex publishing version

var bl_params = {
allowfullscreen: "true",
menu: "false",
salign: "tl",
scale: "noscale",
allowscriptaccess: "never",
base: "http://static.issuu.com/site/",
wmode: "transparent"
};
var bl_attr = { 
id: bl_domId,
name: bl_domId
}; 

swfobject.embedSWF(bl_swfUrl, bl_domId, bl_width, bl_height,
bl_flashver, {}, bl_flashvars, bl_params, bl_attr);

}




