function viewgallery(img) {
	window.open('gallery.php?gallery%5Bimage%5D='+img, 'gallery', 'width=440,height=440,status=0');
	return false;
}
var galleryobj=null;
function gallery() { // gallery object
	this.scrollWidget = document.getElementById('imagelistscroll');
	this.scroll = 0;
	this.req = 0;
	this.max = this.scrollWidget.offsetWidth - 336;
	this.ticker = null;
	this.scrollnext = function () {
		if (this.max > 0) {
			if ((this.req + 90) < this.max) {
				this.req += 90;
			} else {
				this.req = this.max;
			}
			this.tickerkicker();
		}
	}
	this.scrollback = function() {
		if (this.max > 0) {
			if ((galleryobj.req - 90) > 0) {
				galleryobj.req -= 90;
			} else {
				galleryobj.req = 0;
			}
			this.tickerkicker();
		}
	}
	this.tickerkicker = function() {
		if (this.ticker == null) {
			this.ticker = setInterval(this.updatescroll, 20);
		}
	}
	this.updatescroll = function() {
		galleryobj.scroll = (galleryobj.scroll + galleryobj.req) / 2;
		var temp = Math.round(galleryobj.scroll);
		galleryobj.scrollWidget.style.left = (0 - temp)+'px';
		if (temp == galleryobj.req) {
			galleryobj.scroll = galleryobj.req;
			clearInterval(galleryobj.ticker);
			galleryobj.ticker = null;
		}
	}
}
function galleryinit() {
	if (galleryobj == null) {
		galleryobj = new gallery();
	}
}
function gallerynext() {
	galleryinit();
	galleryobj.scrollnext();
	return false;
}
function galleryprevious() {
	galleryinit();
	galleryobj.scrollback();
	return false;
}

function galleryopen(id,pt) {
	if (document.getElementById) {
		var imagediv = document.getElementById("image");
		var newimg = document.createElement("img");
		newimg.src = "image.php?op=gallery&id="+id+"&s=3";
		newimg.style.paddingTop=pt+'px';
		var oldimg = imagediv.getElementsByTagName('img');
		oldimg[0].parentNode.replaceChild(newimg, oldimg[0]);
		return false;
	}
	return true;
}

function cartconf() {
	if (confirm("Are you sure you want to delete this product?")) {
		return true;
	} else {
		return false;
	}
}

function httpreq() {
  var req = false;
  if(window.XMLHttpRequest) { // 'standards'
    try {
      req = new XMLHttpRequest();
    } catch(e) {
      req = false;
    }
  } else if(window.ActiveXObject) { // ie
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        req = false;
      }
    }
  }
  return req;
}

var updatesdiv = null;
function closeupdates() {
	updatesdiv.style.visibility="hidden";
	document.body.onclick=null;
}
function showupdates() {
	if (document.getElementById) {
		if (updatesdiv == null) {
			var req = httpreq();
			if (req) { // woohoo...
				req.onreadystatechange=function() {
					if (req.readyState == 4) {
						updatesdiv = document.createElement("div");
						updatesdiv.id="rightpanel";
						updatesdiv.style.position="absolute";
						updatesdiv.style.top="150px";
						updatesdiv.style.right="0px";
						updatesdiv.style.width="200px";
						updatesdiv.style.visibility = 'visible';
						updatesdiv.innerHTML=req.responseText;
						document.body.appendChild(updatesdiv);
						setTimeout("document.body.onclick=closeupdates", 10)
					}
				}
				req.open("GET", "/updates.php", true);
				req.send(null);
			} else { // no good... load news.php
				return true;
			}
		} else if (updatesdiv.style.visibility  == 'visible') {
			updatesdiv.style.visibility = 'hidden';
			document.body.onclick=null;
		} else {
			updatesdiv.style.visibility = 'visible';
			setTimeout("document.body.onclick=closeupdates", 10)
		}
		return false;
	}
	return true;
}
function initdllang() {
	if (document.getElementById) {
		var other = document.getElementById('otherlangs');
		if (other) {
			other.style.display="none";
			document.images['dllangbutton'].src='style/images/closed.gif';
		}
	}
}
function toggledllang() {
	if (document.getElementById) {
		var other = document.getElementById('otherlangs');
		if (other.style.display == 'none') {
			other.style.display="block";
			document.images['dllangbutton'].src='style/images/opened.gif';
		} else {
			other.style.display="none";
			document.images['dllangbutton'].src='style/images/closed.gif';
		}
	}
	return false;
}
var ratingpopup = false;
var ratingpopupinner;
var ratingvalue = -1;
function clearratingpopup(e) {
	if (document.all) e = window.event;

	if ((e.clientY > (ratingpopup.toptotal - document.body.parentNode.scrollTop + 4)) &&
			(e.clientY < (ratingpopup.toptotal - document.body.parentNode.scrollTop + 20)) &&
			(e.clientX > (ratingpopup.lefttotal - document.body.parentNode.scrollLeft + 4)) &&
			(e.clientX < (ratingpopup.lefttotal - document.body.parentNode.scrollLeft + 84))) {

		var left = e.clientX - ratingpopup.lefttotal - document.body.parentNode.scrollLeft - 4;
		left = Math.floor(left / 16);

		var req = httpreq();
		if (req) { // woohoo
			req.onreadystatechange=function() {
				if (req.readyState == 4) {
					document.getElementById('ratingvalue').style.width=req.responseText;
				}
			}
			req.open("GET", "/products.php?s%5Bid%5D="+ratingpopup.productid+"&op=rate&rating="+(left + 1), true);
			req.send(null);
		}

		alert('Thankyou for rating this product.');
	}

	ratingpopup.style.visibility="hidden";
	document.body.onclick=null;
	document.body.onmousemove=null;
}
function ratingpopupcaller(e) {
	if (document.all) e = window.event;

	if ((e.clientY > (ratingpopup.toptotal - document.body.parentNode.scrollTop + 4)) &&
			(e.clientY < (ratingpopup.toptotal - document.body.parentNode.scrollTop + 20)) &&
			(e.clientX > (ratingpopup.lefttotal - document.body.parentNode.scrollLeft + 4)) &&
			(e.clientX < (ratingpopup.lefttotal - document.body.parentNode.scrollLeft + 84))) {
		var left = e.clientX - ratingpopup.lefttotal - document.body.parentNode.scrollLeft - 4;
		left = Math.floor(left / 16);
		if (ratingvalue != left) {
			ratingvalue = left;
			ratingpopupinner.style.width=(left * 16 + 16)+'px';
		}
	}
}
function ratethis(id) {
	if (document.getElementById) {
		if (ratingpopup == false) {
			var anchor = document.getElementById('rate');
			ratingpopup = document.createElement('div');
			ratingpopupinner = document.createElement('div');
			var top=0;
			var left=0;
			var node = anchor;
			while (node != undefined) {
				top += node.offsetTop;
				left += node.offsetLeft;
				node = node.offsetParent;
			}
			ratingpopup.style.top = (top + 18)+'px';
			ratingpopup.toptotal = (top + 18);
			ratingpopup.style.left = left+'px';
			ratingpopup.lefttotal = left;
			ratingpopup.style.visibility = 'visible';
			ratingpopup.className="ratingdiv";
			ratingpopup.productid = id;
			ratingpopupinner.className="ratinginnerdiv";
			ratingpopup.appendChild(ratingpopupinner);
			document.body.appendChild(ratingpopup);
		} else {
			if (ratingpopup.style.visibility == 'visible') {
				return false;
			} else {
				ratingpopup.style.visibility = 'visible';
			}
		}
		setTimeout("document.body.onclick=clearratingpopup", 10);
		setTimeout("document.body.onmousemove=ratingpopupcaller", 10);
	}
	return false;
}

