/*

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}

*/

var srctemp="";
var idtemp="";

function openPopUp(id,src){
	if (idtemp!="") $('img'+idtemp).src=srctemp;
	for(i=1;i<=8;i++){
		if ($('p'+i)) if(i!=id) {
			$('p'+i).style.display='none';
			$('arrow'+i).style.display='none'; //for IE6
		}
	}
	if ($('p'+id).style.display=='none') {		
		if ((id==1) || (id==4)) $('p'+id).style.left='120px';
		if ((id==2) || (id==5)) $('p'+id).style.left='400px';
		if ((id==3) || (id==6)) {$('p'+id).style.left='auto'; $('p'+id).style.right='120px';}
		if ($('p7')) {
			if (id>0) $('p'+id).style.bottom='352px';
			if (id>3) $('p'+id).style.bottom='220px';
			if (id>6) $('p'+id).style.bottom='88px';	
		}else{
			if (id>3) $('p'+id).style.bottom='88px';
		}
		$('p'+id).style.display='block';
		$('arrow'+id).style.display='block';
		/*var myEffects = new Fx.Morph('p'+id, {duration: 1, transition: Fx.Transitions.Sine.easeOut});
		myEffects.start({
			'display': 'block',
			'opacity': [0, 1]
		});
		var myEffects2 = new Fx.Morph('arrow'+id, {duration: 1, transition: Fx.Transitions.Sine.easeOut}); //for IE6
		myEffects2.start({
			'display': 'block'
		});*/
	}
	idtemp=id;
	srctemp=$('img'+id).src;
	$('img'+id).src=src;
	$('maincontainer').addEvent('click', function(){
		for(i=1;i<=8;i++){
			if ($('p'+i)) {
				$('p'+i).style.display='none';
				$('arrow'+i).style.display='none';
				if (idtemp!="") $('img'+idtemp).src=srctemp;
			}
		}
	});	
}

function changeClass(id,classe,azione){
	if (azione=="add") $(id).className+=' '+classe;
	if (azione=="remove") $(id).className=$(id).className.replace(new RegExp(" "+classe+"\\b"), "");
}

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}