// JavaScript Document
var xmlHttp
function GetXmlHttp() {
	var xmlhttp = false;
	if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest()
	else if (window.ActiveXObject) {
		// code for IE
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			} catch (E) {
				xmlhttp=false
			}
		}
	}
	return xmlhttp;
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = $("menu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
					//findPos(this);
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
Event.observe(window,'load',startList)

Number.prototype.moneyFormat = function() {
	n = this
	s = ''
	toFixedFix = function (n, prec) {
		var k = Math.pow(10, prec);
		return '' + Math.round(n * k) / k;
	}
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (2 ? toFixedFix(n, 2) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
    }
    if ((s[1] || '').length < 2) {
        s[1] = s[1] || '';
        s[1] += new Array(2 - s[1].length + 1).join('0');
    }
    return s.join('.');
}

	function moveToFolder(folder,element) {
		if(element.id.substring(0,5)=='file_') {
			var num = element.id.substr(5)
			var type = 'file'
		} else {
			var num = element.id.substr(7)
			var type = 'folder'
		}
		xmlHttp=GetXmlHttp()
		xmlHttp.onreadystatechange=function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				var num = xmlHttp.responseText
				if(num==1) {
					element.parentNode.removeChild(element)
				} else {
					alert("There has been an error and the " + type + " has not been moved")
				}
			}
		}
		xmlHttp.open("GET",'/_managedocs?action=move&type=' + type + '&num=' + num + '&targ=' + folder,true)
		xmlHttp.send(null)
	}
	function deleteFile(element) {
		if(element.id.substring(0,5)=='file_') {
			var num = element.id.substr(5)
			var type = 'file'
			var name = 'file'
		} else {
			var num = element.id.substr(7)
			var type = 'folder'
			var name = 'folder, and all its contents?'
		}	
		if(confirm('Are you sure you want to delete this ' + type + '? This process cannot be reversed.')) {
			xmlHttp=GetXmlHttp()
			xmlHttp.onreadystatechange=function() {
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
					var num = xmlHttp.responseText
					if(num==1) {
						element.parentNode.removeChild(element)
					} else {
						alert("There has been an error and the " + type + " has not been removed")
					}
				}
			}
			xmlHttp.open("GET",'/_managedocs?action=delete&type=' + type + '&num=' + num,true)
			xmlHttp.send(null)
		}
	}
	function resetFiles() {
		$('delbox').style.display = 'none'
		var f = $$('.icon')
		for(var i = 0; i<f.length; i++) {
			f[i].style.top = ''
			f[i].style.left = ''
		}
	}
	
	
function randOrd(){
	return (Math.round(Math.random())-0.5); 
} 



var images = new Array()
var randNumber = new Array('1','2','3','4','5','6', '7')
var topimage = 1

function startSlideshow() {
	randNumber.sort(randOrd);

	for(var i=1; i<=7; i++) {
		images[i] = document.createElement('IMG')
		images[i].src = '/assets/images/front/' + randNumber[i-1] + '.jpg'
		$('slideshow').appendChild(images[i])
		images[i].style.zIndex = 101-i
	}
		
	window.setInterval(function() {
		images[topimage].fade()
		window.setTimeout(function() {
			var oldtop = topimage
			topimage++
			if(topimage>7) 
				topimage = 1
			
			images[topimage].style.zIndex = 100
		
			var z = 99
			for(var i = topimage+1; i<=7; i++) {
				images[i].style.zIndex = z
				z--
			}
			for(var i=1; i<topimage; i++) {
				images[i].style.zIndex = z
				z--		
			}
			images[oldtop].show()
		},1100)
	}, 7500)
}
