var ie4 = false;
var checked = 0;

if (document.all) { ie4 = true; }
function getObject(id) {
	if (ie4) {
		return document.all[id];
	} else {
		return document.getElementById(id);
	}
}

if (document.getElementsByTagName && document.getElementById) {
	if (window.addEventListener) window.addEventListener('load', setImageSwaps, false);
	else if (window.attachEvent) window.attachEvent('onload', setImageSwaps);
}

function setImageSwaps() {
	prepareImageSwap('nav',true,true,false,false,false,false);
}

// Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) {
	if (typeof(elem) == 'string') elem = document.getElementById(elem); 
	if (elem == null) return; 
	var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
	var prel = new Array(), img, imgList, imgsrc, mtchd; 
	imgList = elem.getElementsByTagName('img'); 
	for (var i=0; img = imgList[i]; i++) { 
		if (!img.rolloverSet && img.src.match(regg)) { 
			mtchd = img.src.match(regg); 
			img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
			img.outSRC = img.src; 
			if (typeof(mouseOver) != 'undefined') { 
				img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
				img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
				img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
				img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
			} 
			if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
			if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
			if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
			if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
			img.rolloverSet = true; 
		} 
	}
	function preLoadImg(imgSrc) { 
		prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
	} 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}

function copyLink(text) {
	text.focus();
	text.select();
	if (document.all)
	{
		therange = text.createTextRange();
		therange.execCommand("Copy");
	}
}

function closepix() {
	if (document.getElementById) {
		document.getElementById('hideshow').style.left = '-1000px';
		document.getElementById('hideshow').style.top = '-1000px';
		document.getElementById('pix_gallery').style.visibility = 'visible';
		document.getElementById('choose').style.visibility = 'visible';
	} else {
		if (document.layers) {
			document.hideshow.left = '-1000px';
			document.hideshow.top = '-1000px';
			document.pix_gallery.style.visibility = 'visible';
			document.choose.style.visibility = 'visible';
		} else {
			document.all.hideshow.style.left = '-1000px';
			document.all.hideshow.style.top = '-1000px';
			document.all.pix_gallery.style.visibility = 'visible';
			document.all.choose.style.visibility = 'visible';
		}
	}
}

function zoompix() {
	if (document.getElementById) {
		document.getElementById('hideshow').style.left = '35px';
		document.getElementById('hideshow').style.top = '52px';
		document.getElementById('pix_gallery').style.visibility = 'hidden';
		document.getElementById('choose').style.visibility = 'hidden';
	} else {
		if (document.layers) {
			document.hideshow.left = '35px';
			document.hideshow.top = '52px';
			document.pix_gallery.style.visibility = 'hidden';
			document.choose.style.visibility = 'hidden';
		} else {
			document.all.hideshow.style.left = '35px';
			document.all.hideshow.style.top = '52px';
			document.all.pix_gallery.style.visibility = 'hidden';
			document.all.choose.style.visibility = 'hidden';
		}
	}
}

function select_all() {
	var sgal = document.thumbs.elements['sgal[]'];
	var spix = document.thumbs.elements['spix[]'];
	if (checked == 1) {
		if (sgal) {
			if (sgal.length) {
				for (var i = 0;i < sgal.length; i++)
					sgal[i].checked = false;
			} else {
				sgal.checked = false;
			}
		}
		if (spix) {
			if (spix.length) {
				for (var i = 0;i < spix.length; i++)
					spix[i].checked = false;
			} else {
				spix.checked = false;
			}
		}
		checked = 0;
	} else {
		if (sgal) {
			if (sgal.length) {
				for (var i = 0;i < sgal.length; i++)
					sgal[i].checked = true;
			} else {
				sgal.checked = true;
			}
		}
		if (spix) {
			if (spix.length) {
				for (var i = 0;i < spix.length; i++)
					spix[i].checked = true;
			} else {
				spix.checked = true;
			}
		}
		checked = 1;
	}
}

function toggle(type, id, divId, initial) {
	var d = getObject(divId);
	var link = divId + '_link';
	var l = getObject(link);
	var lText = l.innerHTML;
	if (lText == '[+]') {
		l.innerHTML = '[-]';
		d.style.display = 'block';
		if (initial != 1) {
			setprefs(type, id, divId, 1);
		}
	} else {
		l.innerHTML = '[+]';
		d.style.display = 'none';
		if (initial != 1) {
			setprefs(type, id, divId, 0);
		}
	}
}

function addfields(divId, num) {
	var d = getObject(divId);
	var html = "";
	for (var x=0; x<num; x++) {
		html = html + '<input type="file" name="pix[]" size="52"><br>';
	}
	d.innerHTML = html;
	setprefs(4, 0, 0, num);
}
