// JavaScript Document
function AccordionMenu() {
	var accordion = new Accordion('h2.headdir', 'div.dircontent', {
		opacity: false,
		alwaysHide: true,
		start: 'all-closed',
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff3300');

			element.setStyle('height','400px');
			
			expandDirection(element);
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222');
		}
	}, $('accordion'));
};
function MenuCategoria() {
	var verticalmenu = new BySlideMenu('menu_categoria', {
		vertical: true,
		elementWidth: 354,
		elementHeight: 219
	});
};

function expandDirection(divelement) {
	switch(divelement.firstChild.id) {
		case "dira14":
			map2.setCenter(point2_center, 15);
			
			break;
		case "dirss650":
			map3.setCenter(point3_center, 13);

			break;
		case "dirvss":
			map4.setCenter(point4_center, 11);
			
			break;
	};
};

function ReloadFieldSearch() {
	NomeNegozio = $('nome_negozio').value;
	var req = new Request({
		url: '/negozi_id.asp',
		method: 'post',
		data: {'value':NomeNegozio},
		onSuccess:function(risp) {
			$('id_negozio').value = risp;
		}
	}).send();
};
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";
	};
};
window.addEvent("domready", function() {
	if ($('frmmail')) new FormCheck('frmmail');
	if ($('frmmailinglist')) new FormCheck('frmmailinglist');
	if ($('frmbusiness')) new FormCheck('frmbusiness');
	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');
		});
		
		$$('.videogallery_e a img').addEvent("mouseout", function(e) {
			e = new Event(e).stop();
			this.setProperty('src','/images/bg_play.png');
		});
	};
	if ($('logotop')) {
		$('logotop').addEvent("click", function(e) {
			document.location.href="/index.asp";
		});
	};
	if ($('nome_negozio')) {
		Item11 = new Autocompleter.Request.JSON($('nome_negozio'), '/negozi_centro.asp', {'indicatorClass': 'autocompleter-loading', 'onSelection': ReloadFieldSearch});
	};
	
	if ($('categoria_negozio')) {
		$('categoria_negozio').addEvent("change", function(e) {
			e = new Event(e).stop();
			var req = new Request.HTML({
				url: '/negozi_categoria_reload.asp',
				method: 'post',
				data: {'categoria_negozio':$('categoria_negozio').value},
				update: $('listanegozi'),
				onComplete: function() {
					if ($$('a.link_negozi')) {
						$$('div.cont_categoria_grp h2').addEvent('click', function(e){
							e = new Event(e).stop();
							document.location.href = this.getElements('a').getProperty('href');
						});
					};
				}
			}).send();
		});
	}
	if ($('send_id_negozio')) {
		$('send_id_negozio').addEvent('click', function(e){
			e = new Event(e).stop();
			if ($('id_negozio').value!="") {
				document.location.href="/e_view.asp?E=" + $('id_negozio').value;
			};
		});
	};
	if ($$('h2.box_main_sx')) {
		$$('h2.box_main_sx').addEvent('click', function(e){
			e = new Event(e).stop();
			document.location.href = document.getElementById(this.id + 'link').getProperty('href');
		});
	};
	
	if ($$('a.link_negozi')) {
		$$('div.cont_categoria_grp h2').addEvent('click', function(e){
			e = new Event(e).stop();
			document.location.href = this.getElements('a').getProperty('href');
		});
	};
	
	if ($('nome_negozio')) {
		$('nome_negozio').addEvent('keypress', function(e){
			if (($('id_negozio').value !="") && (e.key == "enter")) {
				e = new Event(e).stop();
				document.location.href="/e_view.asp?E=" + $('id_negozio').value;
			};
		});
	};
	
	
	new SmoothScroll({duration: 1000}); 
	if ($('myGallery')) {

		if (($$('div.imageElement h3')).length > 0) {
			var myGallery = new gallery($('myGallery'), {showInfopane:true});
		}
		else {
			var myGallery = new gallery($('myGallery'), {});
		};
	};
	
	
	
	
	
	if($$('a.zoom')) {
		ReMooz.assign('a.zoom', {
			'origin': 'img',
			'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
		});
	};
	if($('navbar'))	new SlideList($('navbar').getElement('ul'));
	if ($('accordion')) AccordionMenu();
	if ($('menu_categoria')) MenuCategoria();

});

var map = null;
var map2 = null;
var map3 = null;





var geocoder = null;
var directionsPanel;
var directions;
var point2 = null;
var point3 = null;
var point4 = null;
var point2_center = null;
var point3_center = null;
var point4_center = null;
function load() {

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap"));
		geocoder = new GClientGeocoder();
		map.setCenter(new GLatLng(42.06346417232811,14.77763056755066), 14);
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		var point = new GLatLng(42.06346417232811,14.77763056755066);
		
		
		new Request({
			method: 'get',
			url: '/cmsystem/modules/Elemento/baloon.asp',
			evalScripts: true,
			onComplete: function(risposta) {
				

				map.addOverlay(createMarker(point, risposta));
			}
		}).send();
		
		
		initializedir();
	}
}
function initializedir() {
	map2 = new GMap2(document.getElementById("dira14"));
	map2.addControl(new GMapTypeControl());
	map2.addControl(new GLargeMapControl());
	map3 = new GMap2(document.getElementById("dirss650"));
	map3.addControl(new GMapTypeControl());
	map3.addControl(new GLargeMapControl());
	map4 = new GMap2(document.getElementById("dirvss"));
	map4.addControl(new GMapTypeControl());
	map4.addControl(new GLargeMapControl());
	var point = new GLatLng(42.06346417232811, 14.77763056755066);




	point2 = new GLatLng(42.0581034187728, 14.771225452423096); //a14
	point3 = new GLatLng(42.02979464341945, 14.743534326553345); //ss650
	point4 = new GLatLng(42.008568735826685, 14.95938777923584); //termoli


	point2_center = new GLatLng(42.0626118985286, 14.774336814880371); //a14
								

	
	point3_center = new GLatLng(42.05018492520078, 14.765968322753906); //ss650
	point4_center = new GLatLng(42.02787400232195, 14.86724853515625); //vasto san salvo

	//directionsPanel = document.getElementById("route");
	var directions = new GDirections(map2); 
	//Create an array to house the two GLatLng Objects 
	var arrLocation = new Array(2); 
	arrLocation[0] = point2; 
	arrLocation[1] = point; 
	directions.loadFromWaypoints(arrLocation); 
	map2.setCenter(point2_center, 15);
	var directions2 = new GDirections(map3); 
	var arrLocation2 = new Array(2); 
	arrLocation2[0] = point3; 
	arrLocation2[1] = point; 
	directions2.loadFromWaypoints(arrLocation2); 
	map3.setCenter(point3_center, 13);
	var directions3 = new GDirections(map4); 
	var arrLocation3 = new Array(2); 
	arrLocation3[0] = point4; 
	arrLocation3[1] = point; 
	directions3.loadFromWaypoints(arrLocation3); 
	map4.setCenter(point4_center, 11);
};




function createMarker(point, label) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(label);
	});
	return marker;
}


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);

}

window.addEvent("load", function() {
	if ($('gmap')) load();
});

