<!--
//////////////////////////// disable right click //////////////////////////////
function clickIE4() {
	if(event.button==2)
		return false;
}

function clickNS4(e){
	if(document.layers||document.getElementById&&!document.all) {
		if(e.which==2||e.which==3)
			return false;	
	}
}

function disableRightClick() {
	if(document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById) {
		document.onmousedown=clickIE4;
	}
	document.oncontextmenu=function() {
		return false;
	}
}

///////////////////////////////////////////////////////////////////////////////
function initRefInfoDataChange() {	
	if($('references_box_main_rwm_imgs')) {
		var coverFlowDiv = $('references_box_main_rwm_imgs');
		var ImageWidth = 100;
		var ImageHeight = 100;
		var CoverFlowWidth = 360;
		var cf = new CoverFlow(coverFlowDiv, ImageWidth, ImageHeight, CoverFlowWidth, "#FFFFFF", rwmCallBack);	
		updateRwm(cf);
	}
}

function updateRwm(coverFlowObj) {
	coverFlowObj.Update();
	setTimeout(function() {updateRwm(coverFlowObj);}, 20);
}

function rwmCallBack(c) {		
	var elIndex=c.CoverIndex;
	var newRefInfo=$('info_ref_'+elIndex).innerHTML;
	$('actual_info_ref').update($('info_ref_'+elIndex).innerHTML);
	new Effect.Highlight('info_v_art', { startcolor: '#43B0AD',endcolor: '#EEEEEE',restorecolor: '#EEEEEE'});	
}

///////////////////////////////////////////////////////////////////////////////
function initRefZoomedImageChange() {
	if($$('#ref_more_pics a').length) {
		var allRefPics=$$('#ref_more_pics a');
		allRefPics.each(function(aRefPics) {
			aRefPics.observe('click',function(event) {
				event.stop();
				var firstPar=$F($('id_art_ref'));				
				var secondPar=this.readAttribute('rel');
				var parameters='id_ref='+firstPar+'&id_img='+secondPar;
				var theRequest = new Ajax.Updater($('refImagesCnt'),'upd_ref_images.php', {
					method: 'post',
					parameters: parameters,
					asynchronous: false,
					onComplete: function() {
						initZoomerObjects();
						initRefZoomedImageChange();	
					}
				});				
			});
		});
	}
}

function initZoomerObjects() {
	if($$('a.zoom').length) {
		var allObjectsToZoom=$$('a.zoom');
		allObjectsToZoom.each(function (aLink) {
			new Zoomer(aLink);
		});
	}
}

function initHomeCategsRollover() {
	if($$('#home_categories span.cat_name').length) {
		var allCategsVeils=$$('#home_categories span.cat_name');
		allCategsVeils.each(function(aCategVeil) {
			aCategVeil.observe('mouseover',function() {
				var theVeil=this.next('.cat_name_veil');
				new Effect.Morph(theVeil, {style:'width: 110px; height: 50px; top: -1px; left: -1px;',duration:0.5});
			});
			aCategVeil.observe('mouseout',function() {
				var theVeil=this.next('.cat_name_veil');
				new Effect.Morph(theVeil, {style:'width: 90px; height: 30px; top: 9px; left: 9px;',duration:0.5});
			});
		});		
	}
}

function initMenuRollover() {
	var buttons=$$('#menu a img');
	buttons.each(function(theButton) {
		theButton.observe('mouseover',function() {
			this.src=this.src.replace("_off","_on");
		});
		theButton.observe('mouseout',function() {
			if(this.className!="active_btn")
				this.src=this.src.replace("_on","_off");
		});
	});
}

function initArtAddUtility() {
	if($$('.add_q')) {
		$$('.add_q').each(function(anAddButton) {
			anAddButton.observe('click',function(event) {
				event.stop();
				inputId=this.id.replace('add_q_','quantita_1_');		
				adjustQuantity(1,parseInt(this.readAttribute('rel')),inputId);				
			});
		});
	}
	if($$('.remove_q')) {
		$$('.remove_q').each(function(aRemoveButton) {
			aRemoveButton.observe('click',function(event) {
				event.stop();
				inputId=this.id.replace('remove_q_','quantita_1_');		
				adjustQuantity(0,parseInt(this.readAttribute('rel')),inputId);
			});
		});
	}
	if($$('.q_field')) {
		$$('.q_field').each(function(aQField) {
			aQField.observe('change',function() {
				verifyQuantity(this,parseInt(this.readAttribute('rel')));
			});
		});	
	}
}

function adjustQuantity(mode,min,inputId) {
	var input=$(inputId);
	if(mode) {
		var newValue=parseInt($F(input)) + 1;
		input.value = newValue;
	}
	else {
		var actualValue=parseInt($F(input));				
		if(actualValue > min)
			input.value = actualValue-1;			
	}
}

function verifyQuantity(field,min) {
	var actualValue=parseInt($F(field));
	if (actualValue < min || isNaN(actualValue)) {
		field.value = min;
	}
}

function TargetBlank() {
  $$('a.target_blank').each(
  	function(obj){
  		obj.target = "_blank";
  	}
  );
}

function showDetails(elementId) {
    $(elementId).show();  
}

function hideDetails(elementId) {
    $(elementId).hide();  
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function initMap() {
	if($('map'))     
		showMap();
}

function showMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"),{mapTypes:[G_SATELLITE_MAP,G_NORMAL_MAP,G_HYBRID_MAP]});
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var center = new GLatLng(41.317758,16.289141);
		map.setCenter(center, 17);      		      		
		var markerDescription = "Balducci srl";
		map.addOverlay(createMarker(new GLatLng(41.317758,16.289141),markerDescription));      	    
    }
}

function createMarker(point, description) {
	var marker = new GMarker(point,{draggable: true});
	GEvent.addListener(marker, "dragstart", function() {
		map.closeInfoWindow();
	});             
	GEvent.addListener(marker, "dragend", function() {
		marker.openInfoWindowHtml(description);
	});              
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(description);
	});
	return marker;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function initFormsVerifyEvent() {
	var reqFieldsForm=$$('form.req_fields');
	if(reqFieldsForm.length) {
		reqFieldsForm.each(function(aReqFieldsForm) {
			aReqFieldsForm.observe('submit',function(event) {
				event.stop();
				var theForm=this;
				var parameters=this.serialize();
				parameters+='&fid='+this.id;
				var theRequest = new Ajax.Request('form_process_reqfields.php', {
					method: 'post',
					parameters: parameters,
					asynchronous: false,
					evalJS: 'force',
					onComplete: function(response) {
						if(response.responseText.substring(0,10)!="mustStop=1")
							theForm.submit();				
					}
				});
			});
		});
	}	
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function aggiorna_totale(value) {
  switch(value) {
   case "Contrassegno":
   		$('totale2').update("<br>+ &euro; 5,00 contrassegno");  		
   break;
   default: $('totale2').update("");
  }
}

function aggiorna_totale2(value) {
  $('totale').update(document.concludi_ordine.elements["totaleOK_"+value].value);
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function init() {
	TargetBlank();
	initMenuRollover();
	initHomeCategsRollover();	
	initFormsVerifyEvent();
	initRefInfoDataChange();
	initZoomerObjects();
	initRefZoomedImageChange();
	initArtAddUtility();
	initMap();
}

document.observe("dom:loaded", init);
//-->
