function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggle( targetId ){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if (target.style.display == "none"){
			target.style.display = "";
		} else {
			target.style.display = "none";
		}
	}
}

// -----------------------------------------------------------------------------------

window.addEvent('domready', function(){

	var hli = $$(".highlight");
	
	hli.each(function(element) {

		element.addEvent('click', function(e) {
			
			e = new Event(e).stop();
			expanded = new Element('div', {'class': 'expanded', 'events': {
				'click': function(e){
					e = new Event(e).stop();
					new Fx.Style(this, 'opacity', {duration: 300}).start(0);
				}}
			});
			
			var hide = new Fx.Style(expanded, 'opacity', {duration: 300});
			
			expanded.inject(document.body);
			expanded.setOpacity(0);

			loadedImages = '';

			var neww = 0;
			var newh = 0;
			
			new Asset.images(element, {
			
				onProgress: function() {
				
					expanded.setStyles({
						'left': e.page.x - (this.width / 2),
						'top': e.page.y - (this.height / 2),
						'width': this.width,
						'height': this.height
					});

					loadedImages = this;										
				},
			
				onComplete: function() {
					
					loadedImages.inject( expanded );
					
					hide.start(0, 1);
					
				}
				
			});

		});				

	});
	
});

// -----------------------------------------------------------------------------------

function o(who) {
	return document.getElementById(who);
}

// -----------------------------------------------------------------------------------

// stretch overlay to fill page and fade in
function mostraOverlay(url) {
	
	$('overlay_background').setStyles({
		height: window.getScrollHeight(),
		visibility: 'visible'
	});

	exampleFx = new Fx.Style('overlay_background', 'opacity', {
		duration: 500, 
		transition: Fx.Transitions.quartIn
	});

	exampleFx.start(0,0.6).chain(function() {
		$('overlay').setStyles({
			top: window.getScrollTop()+20,
			left: Math.round((window.getWidth()-900)/2),
			visibility: 'visible'			
		});
		new Ajax(url, {
				method: 'get',
				update: $('overlay')
			}).request();
		
	});
	
}

// -----------------------------------------------------------------------------------

// fade overlay out
function nascondiOverlay() {

	$('overlay').setStyle('visibility','hidden');	
	
	exampleFx = new Fx.Style('overlay_background', 'opacity', {
		duration: 500, 
		transition: Fx.Transitions.quartInOut
	});
	exampleFx.start(0.6,0).chain(function() {
		
		$('overlay').innerHTML="";		
		$('overlay_background').setStyle('visibility','hidden');	
		
	});
}


// -----------------------------------------------------------------------------------
function setHeight(el, h) {
	o(el).style.height = h +"px";
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}