//common.js
var contentAjaxRequest;
var currentImage = 0;

// Supershort helpers!
function gEI(n){return document.getElementById(n);}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function toggle(obj) {
	var el = $(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function smoothScrollY(value) {
	neg = value < 0 ? -1 : 1;
	value = value * neg;
	if (value <= 10) {
		window.scrollBy(0,neg * value);
	}
	else {
		window.scrollBy(0, neg * 10);
		setTimeout('smoothScrollY(' + (neg * value - neg * 10) + ')',20);
	}
}
	
function disableEnterKey(e)
{
     var key;      
     if(window.event) {
          key = window.event.keyCode; //IE
	  if (key == 13) {
		e.cancelBubble = true;
		return false;
	  }
     }
     else {
          key = e.which; //firefox      
	  if (key == 13) {
		e.stopPropagation();
		return false;
	  }
     }

     return true;
}

function newContent(newContentUrl) {
	newContentUrl = encodeURI(newContentUrl);
	
	if (window.XMLHttpRequest) {
		contentAjaxRequest = new XMLHttpRequest();
		contentAjaxRequest.onreadystatechange = showNewContent;
		contentAjaxRequest.open("GET", newContentUrl, true);
		contentAjaxRequest.send(null);
	}
	else if (window.ActiveXObject) {
		contentAjaxRequest = new ActiveXObject("Microsoft.XMLHttp");
		if (contentAjaxRequest) {
			contentAjaxRequest.onreadystatechange = showOverview;
			contentAjaxRequest.open("GET", newContentUrl);
			contentAjaxRequest.send();
		}
	}
}

function showNewContent() {
	if (contentAjaxRequest.readyState == 4) {
		if (contentAjaxRequest.status != null &&  contentAjaxRequest.status == 200) {
			var newContent = contentAjaxRequest.responseText;
			var contentDiv = gEI("content"); 
			contentDiv.innerHTML = newContent;
		}
		else {
		} 
	}
}

function rollImage(direction) {
	//~ var tmp = "";
	var photoholder = gEI("innerphotoholder");
	var images = photoholder.childNodes;
	if (images.length <= currentImage + direction || currentImage + direction < 0) {
		return;
	}
	//~ for (imgNo = 0; imgNo < images.length; imgNo++) {
		//~ tmp += images[imgNo].tagName + images[imgNo].offsetLeft;
	//~ }
	//~ alert(tmp);
	move = images[currentImage].offsetLeft - images[currentImage + direction].offsetLeft;
	currentImage += direction;
	currentPos = parseInt(photoholder.style.left);
	currentPos = isNaN(currentPos) ? 0 : currentPos;
	//~ alert("" + currentPos); 
	photoholder.style.left = "" + (0 + move + currentPos) + "px";
	//~ for (imgNo = 0; imgNo < images.length; imgNo++) {
		//~ tmp += images[imgNo].tagName + images[imgNo].offsetLeft;
	//~ }
	//~ alert(tmp);
}

function changeOpacity( imageobject, opacity ) {

    var object = imageobject.style;

    object.opacity = ( opacity / 100 );

    object.MozOpacity = ( opacity / 100 );

    object.KhtmlOpacity = ( opacity / 100 );

    object.filter = "alpha(opacity=" + opacity + ")";

 

}
