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

function setImage(img){
	pic = document.getElementById('img');
	pic.onload = function () { redefineMap() };
	if(y>=768){
		switch (img) {
			case "5":
					pic.src='images/background/contact_cache.jpg'
				break;
			default:
					pic.src='images/background/home_cache.jpg'
				break;
		}
	} else {
		pic.src='neil_barclay_photography.php?h='+y+'&f='+img;
	}
}

var zoomFile  = 'images/portfolio/neil_barclay_portfolio.php';

function zoomPicture(img, file){

	setNavigation(img);
	
	// set table opacity to 100 (start position)
	changeOpac(100, 'scrollarea')
	
	// show progress bar
	document.getElementById('loading').style.visibility = 'visible';
	
	// load image to clear.gif and set onLoad event to fire showZoomPic function
	zPic = document.getElementById('zoomPic');
	zPic.onload = function () { showZoomPic(this) };
	
	zPic.f= img;

	zPic.src = file;

	// fade table OUT
	shiftOpacity('scrollarea', 600);
}

var descOn;
var descOff;

descArray = Array ('Italy','Zurich','Lake Zurich','New Mexico','Texas','Fluela Pass','New York City','New York City','New York City','Stelvio Pass','Zurich','Switzerland','Utah','Zurich','Sweden','Switzerland','Switzerland','India','Switzerland','Switzerland','Sweden','India','New York City','Sydney','Lake Zurich','Tuscany','Switzerland');

function showZoomPic(img){ // wenn bild geladen wurde tabelle ausblenden und bild einblenden
	// get image number
	imgNr = img.f;
	descText = descArray[imgNr - 1];

	// disable prpgress bar
	document.getElementById('loading').style.visibility = 'hidden';
	
	// den zoom layer transparent machen (opacity = 0) 
	changeOpac(0, 'zoom')
	// den zoom layer anzeigen
	document.getElementById('zoom').style.visibility = 'visible';
	
	// den zoom layer einblenden (opacity = 100)
	shiftOpacity('zoom', 600);
	if(document.getElementById('desc')){
		document.getElementById('descriptionText').innerHTML = descText;
		zImg = document.getElementById('zoomPic');
		descript = document.getElementById('desc');

		descript.style.visibility = 'hidden';
		changeOpac(0, 'desc');
		
		/*desc.style.left = zImg.offsetLeft + "px";
		desc.style.width = zImg.offsetWidth + "px";
		desc.style.top = zImg.offsetTop + "px";
		*/
		
		descript.style.left = x/2 - 110 + "px";
		descript.style.width = "220px";
		descript.style.top = y/2 - 180 + "px";
		if(document.all)descript.style.top =  (zImg.offsetTop - 50) + "px";
		descript.style.visibility = 'visible';
		//opacity('description', 0, 80, 1200);
	
		descOn  = window.setTimeout("opacity('desc', 0, 70, 600);",1200);	
		descOff = window.setTimeout("opacity('desc', 70, 0, 600);",2800);
	}	
}

function changePic(direction){

	if(typeof descOn != 'undefined')window.clearTimeout(descOn);
	if(typeof descOff != 'undefined')window.clearTimeout(descOff);


	// aktuelles zoom pic ausblenden
	changeOpac(0, 'zoom');
	// show progress bar
	document.getElementById('loading').style.visibility = 'visible';
	
	// nächstes bild anzeigen
	zPic = document.getElementById('zoomPic');

	img = parseInt(zPic.f,10) + direction; // next image

	//directory = zPic.t;
	img = (img<10)?'0'+img:img;

	setNavigation(img);	
	// BUG -- wenn extension wechselt krachts!!!
	//alert(zPic.src.replace("/"+zPic.f+".","/"+img+"."));
	zPic.src = zPic.src.replace("/"+zPic.f+".","/"+img+".");
	//
	
	zPic.f= img;
}

function setNavigation(img){
	document.getElementById('next').style.display= (parseInt(img, 10) < maxPic)?'':'none';
	document.getElementById('prev').style.display= (parseInt(img, 10) != 1)?'':'none';
}

function hideZoomPic(){
	if(document.getElementById('desc'))document.getElementById('desc').style.visibility = 'hidden';

	zoomLayer =  document.getElementById('zoom');
	// den zoom layer transparent machen (opacity = 0)
	shiftOpacity('zoom', 600);
	// den zoom layer ausblenden
	zoomLayer.style.visibility = 'hidden';
	// die thumbtable tabelle einblenden (opacity = 100)
	shiftOpacity('scrollarea', 600);
	//document.getElementById('thumbTable').style.display = '';
}

function redefineMap(){
	document.getElementById('loading').style.visibility = 'hidden';
	origHeight = 650;// origHeight = 768;
	newHeight = document.getElementById('img').offsetHeight;	// newHeight = y;
	faktor = (newHeight / origHeight);
	
	map = document.getElementById('Map');
	coords = map.childNodes.length;
	for(j=0; j< coords; j++){
		area = map.childNodes[j];
		if(area.nodeName == 'AREA'){
			coordsArray = area.getAttribute('coords').split(',');
			
			for(i=0; i < coordsArray.length ; i++){
				coordsArray[i] = parseInt(coordsArray[i] * faktor);
			}
			area.setAttribute('coords',coordsArray)
		}
	}
}



function scrollBar(direction,stat,speed,pixel){
	if(stat == 'start'){
		document.scrollStatus = stat;
	}
	if(stat == 'stop'){
		document.scrollStatus = '';
		if(typeof scroller != 'undefined')window.clearTimeout(scroller);
	}

	s=(speed)?speed:65;
	p=(pixel)?pixel:24
	area = 	document.getElementById('scrollarea');

	content = document.getElementById('scrollcontent');
	if(document.scrollStatus == 'start'){
		content.lPosition = parseInt(content.offsetLeft);
	//	log(content.lPosition);
		//content.style.left = content.offsetLeft;
		
	//	log(content.offsetWidth * -1 + area.offsetWidth);
		if( (( content.lPosition > ((content.offsetWidth - 1) * -1 + area.offsetWidth)) && (direction == -1)) || ((content.lPosition < 0) && direction == 1)){
			shiftLeft = (content.lPosition + (p * direction));
			content.style.left = shiftLeft + 'px';
			//setScrollImages(shiftLeft);
		 	scroller = window.setTimeout("scrollBar("+direction+",'"+stat+"',"+s+","+p+")",s);
		}
	}

}
var imageOffset = 0;
function setScrollImages(offs){
	imageOffset = imageOffset + offs;
	
	div = document.getElementById('scrollcontent');
	firstImage = div.firstChild;
	//alert(firstImage.offsetLeft +"\n"+ (firstImage.offsetWidth * -1));
	
	//alert( imageOffset +"\n"+ (firstImage.offsetWidth * -1) )
	if(imageOffset < (firstImage.offsetWidth * -1) ){
		div.appendChild(firstImage);
		imageOffset = offs + firstImage.offsetWidth;
	}
}
