moo = 1;
mpm = 150;
mpc = 0;

function get_expirydate(v1){
	var v2;
	v3 = new Date();
	v4=Date.parse(v3);
	v3.setTime(v4+v1*24*60*60*1000);
	v2 = v3.toUTCString();
	return v2;
}

function set_cookie(v1,v2,v3){
	v4=v1+"="+escape(v2)+";EXPIRES="+get_expirydate(v3);
	document.cookie=v4;
}

function get_cookie(v1) {
	var v2=""+document.cookie;
	var v3=v2.indexOf(v1);
	if (v3==-1 || v1=="") return ""; 
	var v4=v2.indexOf(";",v3);
	if (v4==-1) v4=v2.length; 
	return unescape(v2.substring(v3+v1.length+1,v4));
}

window.defaultStatus = "Fabaria Rally, 3-4 novembre 2006"; 

album_img = new Array(
"/2006/foto/2006/IMG_8883.jpg", "RE Felice - BARIANI Maria", "/2006/foto/index.php?foto=2006/IMG_8883.jpg",
"/2006/foto/2006/IMG_8884.jpg", "SILVA Marco - PINA Giovanni", "/2006/foto/index.php?foto=2006/IMG_8884.jpg",
"/2006/foto/2006/IMG_8886.jpg", "GIANFICO Fabio - MONGILLO Liberato", "/2006/foto/index.php?foto=2006/IMG_8886.jpg",
"/2006/foto/2006/IMG_8888.jpg", "PORRO Paolo - CARGNELUTTI Paolo", "/2006/foto/index.php?foto=2006/IMG_8888.jpg",
"/2006/foto/2006/IMG_8897.jpg", "DI BENEDETTO Alfonso - SIRACUSANO Rosario", "/2006/foto/index.php?foto=2006/IMG_8897.jpg",
"/2006/foto/2006/NE8H0007.jpg", "RE Felice - BARIANI Maria", "/2006/foto/index.php?foto=2006/NE8H0007.jpg",
"/2006/foto/2006/NE8H0017.jpg", "SILVA Marco - PINA Giovanni", "/2006/foto/index.php?foto=2006/NE8H0017.jpg",
"/2006/foto/2006/NE8H0027.jpg", "ZIVIAN Andrea - MESSINA Maurizio", "/2006/foto/index.php?foto=2006/NE8H0027.jpg",
"/2006/foto/2006/NE8H0035.jpg", "PORRO Paolo - CARGNELUTTI Paolo", "/2006/foto/index.php?foto=2006/NE8H0035.jpg",
"/2006/foto/2006/NE8H0046.jpg", "GULFI Luca - ROGGERONE Danilo", "/2006/foto/index.php?foto=2006/NE8H0046.jpg",
"/2006/foto/2006/NE8H0062.jpg", "PATTI Giuseppe - PITRUZZELLA Mariarita", "/2006/foto/index.php?foto=2006/NE8H0062.jpg",
"/2006/foto/2006/NE8H0071.jpg", "DI BENEDETTO Alfonso - SIRACUSANO Rosario", "/2006/foto/index.php?foto=2006/NE8H0071.jpg",
"/2006/foto/2006/NE8H0075.jpg", "SICILIA Calogero - CAMBRIA Massimo", "/2006/foto/index.php?foto=2006/NE8H0075.jpg",
"/2006/foto/2006/NE8H0081.jpg", "CAVALLINI Tobia - ZANELLA Flavio", "/2006/foto/index.php?foto=2006/NE8H0081.jpg",
"/2006/foto/2006/NE8H0095.jpg", "MORREALE Gabriele - BOSCO Claudio", "/2006/foto/index.php?foto=2006/NE8H0095.jpg",
"/2006/foto/2006/NE8H0159.jpg", "DI CARO Antonio - MIGLIORE Gaetano", "/2006/foto/index.php?foto=2006/NE8H0159.jpg"
); 
album_img_total = parseInt( album_img.length / 3 );


/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/
//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } }; Object.extend = function(destination, source) { for (property in source) destination[property] = source[property]; return destination; }; Function.prototype.bind = function(object) { var __method = this; return function() { return __method.apply(object, arguments); } }; Function.prototype.bindAsEventListener = function(object) { var __method = this; return function(event) { __method.call(object, event || window.event); } }; function $() { if (arguments.length == 1) return get$(arguments[0]); var elements = []; $c(arguments).each(function(el){ elements.push(get$(el)); }); return elements; function get$(el){ if (typeof el == "string") el = document.getElementById(el); return el; } }; if (!window.Element) var Element = new Object(); Object.extend(Element, { remove: function(element) { element = $(element); element.parentNode.removeChild(element); }, hasClassName: function(element, className) { element = $(element); if (!element) return; var hasClass = false; element.className.split(" ").each(function(cn){ if (cn == className) hasClass = true; }); return hasClass; }, addClassName: function(element, className) { element = $(element); Element.removeClassName(element, className); element.className += " " + className; }, removeClassName: function(element, className) { element = $(element); if (!element) return; var newClassName = ""; element.className.split(" ").each(function(cn, i){ if (cn != className){ if (i > 0) newClassName += " "; newClassName += cn; } }); element.className = newClassName; }, cleanWhitespace: function(element) { element = $(element); $c(element.childNodes).each(function(node){ if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node); }); }, find: function(element, what) { element = $(element)[what]; while (element.nodeType != 1) element = element[what]; return element; } }); var Position = { cumulativeOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop  || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; } while (element); return [valueL, valueT]; } }; document.getElementsByClassName = function(className) { var children = document.getElementsByTagName("*") || document.all; var elements = []; $c(children).each(function(child){ if (Element.hasClassName(child, className)) elements.push(child); }); return elements; }; Array.prototype.iterate = function(func){ for(var i=0;i<this.length;i++) func(this[i], i); }; if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate; function $c(array){ var nArray = []; for (var i=0;i<array.length;i++) nArray.push(array[i]); return nArray; }

/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
Sunday, March 05, 2006
v 1.2.3
*/
var fx = new Object(); 
fx.Base = function(){}; 
fx.Base.prototype = { setOptions: function(options) { this.options = { duration: 500, onComplete: "", transition: fx.sinoidal }; Object.extend(this.options, options || {}); }, 
step: function() { var time  = (new Date).getTime(); if (time >= this.options.duration+this.startTime) { this.now = this.to; clearInterval (this.timer); this.timer = null; 
if (this.options.onComplete) { setTimeout(this.options.onComplete.bind(this), 10); } else {
// if - else -- Opacity
	switch( this.el.id ) {
	
		case "album-loading": switch( moo ) {
			
				// inizializzazione terminata
				case 1: 
					moo++; 
					document.getElementById("click-a").style.cursor="pointer"; 
				break;

				// inizio cambio immagine
				case 4: 
					albumOpacity.custom(1,0); 
				break;

				case 5: 
					moo = 3; 
				break; 
		} break; 
		
		case "album": switch( moo ) {
	
				// sposto il coso del caricamento
				case 4: 
					if ( loadingTop != mpm ) {
						loadingPos.move( [ loadingLeft, loadingTop ],[ loadingLeft, mpm ] ); loadingTop = mpm;
					} else {
						album_load();
					}
				break; 
				
				case 5: 
					loadingOpacity.custom(0.75,0); 
				break;
		} break;
		
	}

} } else { var Tpos = (time - this.startTime) / (this.options.duration); this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from; } this.increase(); }, custom: function(from, to) { if (this.timer != null) return; this.from = from; this.to = to; this.startTime = (new Date).getTime(); this.timer = setInterval (this.step.bind(this), 13); }, hide: function() { this.now = 0; this.increase(); }, clearTimer: function() { clearInterval(this.timer); this.timer = null; } }; fx.Layout = Class.create(); fx.Layout.prototype = Object.extend(new fx.Base(), { initialize: function(el, options) { this.el = $(el); this.el.style.overflow = "hidden"; this.iniWidth = this.el.offsetWidth; this.iniHeight = this.el.offsetHeight; this.setOptions(options); } }); fx.Height = Class.create(); Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), { increase: function() { this.el.style.height = this.now + "px"; }, toggle: function() { if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0); else this.custom(0, this.el.scrollHeight); } }); fx.Width = Class.create(); Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), {	increase: function() { this.el.style.width = this.now + "px"; }, toggle: function(){ if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0); else this.custom(0, this.iniWidth); } }); fx.Opacity = Class.create(); fx.Opacity.prototype = Object.extend(new fx.Base(), { initialize: function(el, options) { this.el = $(el); this.now = 1; this.increase(); this.setOptions(options); }, increase: function() { if (this.now == 1 && (/Firefox/.test(navigator.userAgent))) this.now = 0.9999; this.setOpacity(this.now); }, setOpacity: function(opacity) { if (opacity == 0 && this.el.style.visibility != "hidden") this.el.style.visibility = "hidden"; else if (this.el.style.visibility != "visible") this.el.style.visibility = "visible"; if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + opacity*100 + ")"; this.el.style.opacity = opacity; }, toggle: function() { if (this.now > 0) this.custom(1, 0); else this.custom(0, 1); } }); fx.sinoidal = function(pos){ return ((-Math.cos(pos*Math.PI)/2) + 0.5); }; fx.linear = function(pos){ return pos; }; fx.cubic = function(pos){ return Math.pow(pos, 3); }; fx.circ = function(pos){ return Math.sqrt(pos); };

/*
funzioni personalizzate
*/

//fx.position extension
fx.Position = Class.create();
fx.Position.prototype = Object.extend(new fx.Base(), { initialize: function(el, options) { this.el = $(el); this.setOptions(options); this.now = [0,0]; }, step: function() { var time  = (new Date).getTime(); if (time >= this.options.duration+this.startTime) { this.now = this.to; clearInterval (this.timer); this.timer = null; if (this.options.onComplete) { setTimeout(this.options.onComplete.bind(this), 10); } else {
// if - else -- Positioning
	switch( this.el.id ) {
		case "main": switch( moo ) {
	
				// inizializzazione
				case 1: 
					// albumPos.move( [0, mpm + 36 ], [0,0] ); 
				break; 
		
				// main è appena sceso, moo va a 3
				case 2: 
						moo++; 
						document.getElementById('click-img').style.top='-60px';
				break; 
		
				// main è appena salito, moo torna a 2
				case 3: 
						moo--; 
				break;
				
				case 5: 
					// risetto questa variabile
					mpc = document.getElementById("album-img").height - main_spacer; 
					// faccio riapparire la foto
					albumOpacity.custom(0,1);
				break;
				
		} break;

		case "album": switch( moo ) {

				// inizializzazione
				case 1: 
					// loadingOpacity.custom(0.75,0); 
					moo++;
					document.getElementById("click-a").style.cursor="pointer"; 
				break;
			
		} break;
		
		case "album-loading": switch( moo ) {
			
				// faccio caricare la foto
				case 4: 
					album_load(); 
				break;
				
		} break;
		
} } } else { var Tpos = (time - this.startTime) / (this.options.duration); var tmp = []; tmp[0] = (this.options.transition(Tpos) * (this.to[0]-this.from[0]) + this.from[0]); tmp[1] = (this.options.transition(Tpos) * (this.to[1]-this.from[1]) + this.from[1]); this.now = tmp; } this.increase(); }, increase: function() { this.el.style["left"] = this.now[0] + "px";  this.el.style["top"] = this.now[1] + "px"; }, move: function(from, to) { to = to ? to : this.now; this.custom(from, to); } });	

function album_onload() {

	album_desc_link = "";
	if ( album_img_current > 0 || album_img_current < album_img_total - 1 ) {
		album_desc_link += "<div id=\"album-next-prev\" >";
		if ( album_img_current > 0 ) {
			album_desc_link += "<a href=\"#top\" onclick=\"album_prev();\" title=\"foto precedente\" id=\"album-prev\" >&#0171;<\/a>";
		}
		if ( album_img_current > 0 && album_img_current < album_img_total - 1 ) {
			album_desc_link += " ";
		}
		if ( album_img_current < album_img_total - 1 ) {
			album_desc_link += "<a href=\"#top\" onclick=\"album_next();\" title=\"foto successiva\" id=\"album-next\" >&#0187;<\/a>";
		}
		album_desc_link += "<\/div>";
	}
	if ( album_img[ parseInt( album_img_current * 3 ) + 1 ] != "" || album_img[ parseInt( album_img_current * 3 ) + 2 ] != ""  ) {
		if ( album_img[ parseInt( album_img_current * 3 ) + 2 ] != "" ) {
			if ( album_img[ parseInt( album_img_current * 3 ) + 1 ] != "" ) {
				album_desc_link += "<div id=\"album-desc-h\" ><a href=\""+ album_img[ parseInt( album_img_current * 3 ) + 2 ] +"\" title=\"vai alla foto\" ><h3>"+ album_img[ parseInt( album_img_current * 3 ) + 1 ] +"<\/h3></a><\/div>";
			}
		} else {
			if ( album_img[ parseInt( album_img_current * 3 ) + 1 ] != "" ) {
				album_desc_link += "<div id=\"album-desc-h\" ><h3>"+ album_img[ parseInt( album_img_current * 3 ) + 1 ] +"<\/h3><\/div>";
			}
		}
	}
	document.getElementById("album-desc").innerHTML = album_desc_link;
	document.getElementById("album-desc").style.width = document.getElementById("album-img").width +"px";
	document.getElementById("album-dx").style.width = "18px";
	document.getElementById("album-sx").style.width = "18px";
	document.getElementById("album-dx").style.height = document.getElementById("album-img").height +"px";
	document.getElementById("album-sx").style.height = document.getElementById("album-img").height +"px";
	switch( moo ) {
	
		// inizializzazione
		case 1: 
			// mainPos.move( [0, 0 ], [0, mpm ] ); 
			albumPos.move( [0, mpm + 36 ], [0,0] ); 
		break;
		
		// sposto main
		case 4: 
			moo++; 
			if ( parseInt( mpc ) != parseInt( document.getElementById("album-img").height - main_spacer ) ) {
				mainPos.move( [0, mpc ], [0, document.getElementById("album-img").height - main_spacer ] );
				mpc = parseInt( document.getElementById("album-img").height - main_spacer );
			} else {
				mpc = parseInt( document.getElementById("album-img").height - main_spacer );
				albumOpacity.custom(0,1);
			}
		break;
	
	}
}

function album_load() {
	switch( moo ) {
		case 4: mpc = parseInt( document.getElementById("album-img").height - main_spacer );break;
	}
	document.getElementById("album-img").src = album_img[ parseInt( album_img_current * 3 ) ] ;
}

function album_prev() {
	// lo stato di moo si porta a 4 per effettuare la prima parte del cambiamento
	moo = 4;
	// se l'immagine attualmente visibile è maggiore di zero
	if ( album_img_current > 0 ) {
		album_img_current--; 
		set_cookie( "album" , album_img_current , 360 );
		loadingOpacity.custom(0,0.75);
	} else {
		return false;
	}
}

function album_next() {
	// lo stato di moo si porta a 4 per effettuare la prima parte del cambiamento
	moo = 4;
	// se l'immagine attuale NON è l'ultima
	if ( album_img_current < album_img_total -1 ) {
		album_img_current++; 
		set_cookie( "album" , album_img_current , 360 );
		loadingOpacity.custom(0,0.75);
	} else {
		return false;
	}
}

function album_initialize() {
	document.getElementById("click-a").style.cursor="wait";
	album_load();
}

function main_move() {
	switch( moo ) {
	
		// faccio scendere main
		case 2: 
			mainPos.move( [0, mpm ], [0, document.getElementById("album-img").height - main_spacer ] ); 
		break; 
		
		// faccio salire main
		case 3: 
			mainPos.move( [0, document.getElementById("album-img").height - main_spacer ], [0, mpm ] ); 
		break; 
	}
}

function click_over() {
	if ( moo > 1 ) {
		if ( moo >= 2 ) {
			document.getElementById("click-img").style.top="-30px";
		} else {
			document.getElementById("click-img").style.top="-120px";
		}
	}
}

function click_out() {
	if ( moo > 1 ) {
		if ( moo >= 2 ) {
			document.getElementById("click-img").style.top="0";
		} else {
			document.getElementById("click-img").style.top="-60px";
		}
	}
}
