//Sets variables to keep track of what's happening
var loop, timer

//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

function makePageObject(){
	this.x=0;
	this.x2=(bw.ns4 || bw.ns5)?innerWidth:document.body.offsetWidth-4;
	this.y=0;
	this.y2=(bw.ns4 || bw.ns5)?innerHeight:document.body.offsetHeight-4;
	this.x50=this.x2/2;
	this.y50=this.y2/2;
	this.x10=(this.x2*10)/100
	this.y10=(this.y2*10)/100
	this.x15=(this.x2*15)/100
	this.y15=(this.y2*15)/100
	return this;
}
function resized(){
	page2=new makePageObject()
	if(page2.x2!=page.x2 || page2.y2!=page.y2){
		location.reload() //If the width or height have changed we reload the page.
	}
}
function myStyle(){
	page=new makePageObject()
	siz=page.x2/115 + page.y2/115
    window.onresize=resized;
}
//Object constructor
function makeObj(obj,nest){
    nest=(!nest) ? '':'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x; this.y;
    this.obj = obj+"Object"
    eval(this.obj+"=this")
    return this
}
function moveIt(x,y){
	this.x=x;this.y=y
	this.css.left=this.x
	this.css.top=this.y
}
//Makes the object go up
function goDown(move){
	if(this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if(loop) setTimeout(this.obj+".down("+move+")",speed)}
}
//Makes the object go down
function goUp(move){
	if(this.y<0){
		this.moveIt(0,this.y-move)
		if(loop) setTimeout(this.obj+".up("+move+")",speed)}
}
//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if(loaded){
		loop=true;
		if(speed>0) oScroll.down(speed)
		else oScroll.up(speed)}
}
//Stops the scrolling (called on mouseout)
function noScroll(){
	loop=false
	if(timer) clearTimeout(timer)
}

//Makes the object
var loaded;
function scrollInit(){
	oCont=new makeObj('divCont')
	oScroll=new makeObj('divText','divCont')
	oScroll.moveIt(0,0)
	oCont.css.visibility='visible'
	loaded=true;
}

function Main(){
	arrowWidth=120; 						// Larghezza Frecce
	arrowHeight=15;		 					// Altezza Frecce
	scrollerLength=490;						//Dimensioni rullo

	hPos=819;				// Posizione orizzontale Inizio rullo e frecce
	vPos=85; 				// Posizione verticale Inizio rullo

	picsHeight=picsWidth/3*2; 					// Thumbnails Height 2/3 (24x36)
	cellHeight=picsHeight + verticalSpacing; 	// Dimensione verticale cella dei thumbnails
			
	arrowUpVPos=vPos - arrowHeight - verticalSpacing; 	// Posizione verticale freccia superiore
	arrowDownVPos=vPos + scrollerLength + verticalSpacing; 	// Posizione verticale freccia inferiore
	
	getSize();
	document.write("<table cellspacing='0' cellpadding='0'>");
	for(i = 1; i <= numberOfPics; i++) {
	picnumx = i;
	if (picnumx<10) {picnumx = "0"+i;};
    document.write("<tr valign='top'><td align='center' height='"+cellHeight+"px'><img id='pic"+picnumx+"' align='middle' onClick=showBigPicture(this) onMouseOut=low(this) onMouseOver=high(this) src='"+thumbsLocation+"pic"+picnumx+".jpg' border='0' alt='© 2007-2009 Mauro Rinaldi. All rights reserved.' style='FILTER: alpha(opacity="+opacityLevel+"); -moz-opacity:"+opacityLevel/100+";'></td></tr>");
    }
    document.write("</table>");
    document.write("<style type='text/css'>");
        document.write("#divUp{position:absolute; left:"+hPos+"; top:"+arrowUpVPos+";}");
        document.write("#divDown{position:absolute; left:"+hPos+"; top:"+arrowDownVPos+";}");
        document.write("#MainDiv{position:absolute; width:"+mainTableWidth+"; height:"+mainTableHeight+"; left:"+hMain+"; top:"+vMain+";}");
        document.write("#divCont{position:absolute; width:"+page.x2+"; height:"+scrollerLength+"; overflow:hidden; top:"+vPos+"; left:"+hPos+"; clip:rect(0,"+page.x2+","+scrollerLength+",0); visibility:hidden;}");
        document.write("#divText{position:absolute; top:0; left:0;}");
	document.writeln("</style>");
    window.onresize=resized
}
function high(which){
	theobject=which;
	highlighting=setInterval("highlightit(theobject)",40)
}
function low(which){
	clearInterval(highlighting);
	objb=which.style;
	objb.MozOpacity=opacityLevel/100;
	objb.filter = "Alpha(Opacity="+opacityLevel+")";
}
function highlightit(obj){
		obj.style.MozOpacity='1';
		obj.style.filter = "Alpha(Opacity=100)";
		clearInterval(highlighting);
}
function replaceBigPicture(n){
	if (n<10) {n="0"+n};
	document.getElementById("bigPic").src = picsLocation+"pic"+n+".jpg";
} 
function getBigPictureNum(){
	s=document.getElementById("bigPic").src;
	s=s.toLowerCase();
	i=s.indexOf(".jpg");
	n=parseInt(s.substr(i-2,2),10);
	return (n)
} 
function showBigPicture(which)	{
	document.getElementById("bigPic").src = picsLocation+which.id+".jpg";
}
function nextBigPicture()	{
	n=getBigPictureNum();
	if (n<numberOfPics){n=n+1} else {n=1}
	replaceBigPicture(n)
}
function prevBigPicture()	{
	n=getBigPictureNum();
	if (n>1){n=n-1} else {n=numberOfPics}
	replaceBigPicture(n)
}
function showRandomPic() {
	var i = Math.round(numberOfPics*Math.random());
	if (i<1) {i=1}
	replaceBigPicture(i)
  }
function buyMe(){
	n=getBigPictureNum();
	if (n<10) {n="0"+n};	
	window.alert('To buy a high quality print of this picture report this code: "'+section + '-pic' + n +'"');
}
