function start() {
	new Effect.Appear ('navigation', {from: 0.0, to:0.9, queue: 'end'}); 
	new Effect.Move ('navigation', { y: 30, mode: 'absolute' })
}


function resize() {
	  		
			//Define image ratio & minimum dimensions
			var a = $('img1');
			var minwidth = 950;
			var minheight = 694;
			var ratio = minheight/minwidth;
			
			
			//Gather browser and current image size
			var imagewidth = $(a).getWidth();
			var imageheight = $(a).getHeight();
			browserwidth = document.viewport.getWidth();;
			browserheight = document.viewport.getHeight();;
			
			//Check for minimum dimensions
			if ((browserheight < minheight) && (browserwidth < minwidth)){
				new Effect.Scale(a, 100, {scaleMode: {originalHeight: minheight, originalWidth: minwidth}, scaleFrom: 100});
			}
			else{	
				//When browser is taller	
				if (browserheight > browserwidth){
				    imageheight = browserheight;
				    imagewidth = browserheight/ratio;
					new Effect.Scale(a, 100, {scaleMode: {originalHeight: browserheight, originalWidth: imagewidth}, scaleFrom: 100});

				    if (browserwidth > imagewidth){
				    	imagewidth = browserwidth;
				    	imageheight = browserwidth * ratio;
					new Effect.Scale(a, 100, {scaleMode: {originalHeight: imageheight, originalWidth: browserwidth}, scaleFrom: 100});
				    }
				
				}
				
				//When browser is wider
				if (browserwidth >= browserheight){
				    imagewidth = browserwidth;
				    imageheight = browserwidth * ratio;
					new Effect.Scale(a, 100, {scaleMode: {originalHeight: imageheight, originalWidth: browserwidth}, scaleFrom: 100});
				    
				    if (browserheight > imageheight){
				    	imageheight = browserheight;
				    	imagewidth = browserheight/ratio;
					new Effect.Scale(a, 100, {scaleMode: {originalHeight: browserheight, originalWidth: imagewidth}, scaleFrom: 100});
				    }
				}
			}
			return false;
	};


	
function gallery(e) {
		new Effect.Fade('background');
		setTimeout("new Ajax.Updater('background','php/gallery_img.php?action=web01&id_portfolio="+e+"', {onComplete:function(){ resize(); new Effect.Appear('background', {queue: 'end'});},asynchronous:true, evalScripts:true});",1500);
}

function gallery_start(e) {
		setTimeout("new Ajax.Updater('background','php/gallery_img.php?action=web01&id_portfolio="+e+"', {onComplete:function(){ resize(); new Effect.Appear('background', {queue: 'end'});},asynchronous:true, evalScripts:true});",1500);
}

function gallery_video() {
		new Effect.Fade('background', {queue: 'front'});
		setTimeout("new Ajax.Updater('background','php/gallery_img.php?action=video', {onComplete:function(){ resize(); new Effect.Appear('background', {queue: 'end'});},asynchronous:true, evalScripts:true});",1500);
}


function changeStyle(e){
	var num = document.getElementsByTagName('a');
	
	//stuto tutti
	for (var i=0;i<num.length;i++) { 
			idx = num[i].id ;
					 
			arr = idx.split("_") ;
 		 
				if (arr[0] == "a") {   	 
					eval("$('"+idx+"').className='gallery' ;");

				} 		
		}
		eval("$('"+e+"').className='galleryH' ;");
}


function in_toggle(a) {
	var x = Math.round($(a).getHeight());
	var y = Math.round($(a).firstDescendant().getHeight());
	var z = Math.round(x/y*100);
	var zz = Math.round(100*x/2);
	allLI = document.getElementsByTagName('DIV') ;
	for (i=0; i < allLI.length; i++) {
	if(allLI[i].id.substring(0,2) == "d_") {
 			var altezza = $(allLI[i]).getHeight();
 			var altezzaLi = Math.round(100*altezza/2);
			if (altezza > 2) {
				new Effect.Scale(allLI[i].id, 100, {scaleX: false, scaleMode:{originalHeight: 2}, scaleFrom: altezzaLi, scaleContent: false}); 		
			}
	}
 
	
	}
	if (x < y) {
		new Effect.Scale(a, 100, {scaleX: false, scaleMode:{originalHeight: y}, scaleFrom: z, scaleContent: false}); 
		//$(a).firstDescendant().firstDescendant().onmouseover=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};
		//$(a).firstDescendant().firstDescendant().onmouseout=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};		
		} else if (x > 2) {
		new Effect.Scale(a, 100, {scaleX: false, scaleMode:{originalHeight: 2}, scaleFrom: zz, scaleContent: false}); 
		//$(a).firstDescendant().firstDescendant().onmouseover=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};
		//$(a).firstDescendant().firstDescendant().onmouseout=function(){this.setStyle({fontWeight: '', color: '#3c3c3c'});};
		}
	}