var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;

var dragobj = null;

function falsefunc() { return false; } // used to block cascading events

(document.addEventListener) ? document.addEventListener("DOMContentLoaded", init, false) : init();

function init()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
}

function update(e)
{
  getMouseXY(e); // NS is passing (event), while IE is passing (null)
}








/*// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for <B style="color:black;background-color:#A0FFFF">mouse</B> capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold <B style="color:black;background-color:#A0FFFF">mouse</B> x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve <B style="color:black;background-color:#A0FFFF">mouse</B> x-y pos.s
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the <B style="color:black;background-color:#99ff99">position</B> values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}


*/



















function zoom(artno)
{
	var win;
	win = window.open("http://reklambutiken.com/shop/images/products/" + artno + "_big.jpg","zoom_"+artno,"WIDTH=600,HEIGHT=600,SCROLLBARS=YES");
}

function changeCurrency(catid)
{
	var win;
	win = window.open("category.php?function=changeCurrency&id=" + catid,"valuta","width=300,height=400");
}

function gallery(artno,id)
{
	var win;
	win = window.open('http://reklambutiken.com/morePics.php?id='+artno+"&pic="+id,'gallery_','WIDTH=810,HEIGHT=800');

}

function wl(word)
{
	new Ajax.Updater('wordlist', '/ordlista.php', { 
		method: 'get',
		parameters: { w: escape(word) }
	});

	$('wordlist').style.top = (mousey+20)+"px";
	$('wordlist').style.left = mousex+"px";
	$('wordlist').style.display = "block";
}

function wl_h()
{
	document.getElementById("wordlist").style.display = "none";
}

function previewGallery(galleryId, artno, width, height, text)
{
	var newWidth=0;
	var newHeight=0;
	var ratio=0;

	if(width>height)
	{
		ratio = 170/width;
		newWidth=170;
		newHeight=height*ratio;
	}
	else if(height>width || height==width)
	{
		ratio=150/height;
		newHeight=150;
		newWidth=ratio*width;
	}

	document.getElementById("prodimg"+artno).innerHTML = "<a href=javascript:gallery("+artno+","+galleryId+")><img src='http://reklambutiken.com/shop/images/gallery/"+galleryId+"_big.jpg' id='productImage_" + artno + "'></a>"
	document.getElementById("productImage_"+artno).width = newWidth;
	ddrivetip(text + ' - Klicka för större bild','#FFFF80', 100);
}

function hideTooltip()
{
	hideddrivetip();
}

function order(data, domain)
{
	var win;
	win = window.open("http://reklambutiken.com/order.php?data="+data+"&domain=" + domain + "&page="+document.location.href,"order","WIDTH=750,HEIGHT=750,SCROLLBARS=YES");
}

function provorder(artno)
{
	var provorder;
	provorder = window.open("http://reklambutiken.com/provorder.php?artno=" + artno, "provorder", "WIDTH=600,HEIGHT=400,SCROLLBARS=NO");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function changeMoms(val)
{
	var q=this.location.search;
	var addr=this.location.href;
	var anchor="";
	var tmp;

	// splitta #
	if(addr.indexOf("#") > -1)
	{
		tmp = addr.split("#");
		anchor = "#" + tmp[1];
		addr = tmp[0];
	}

	q = q.replace("moms=0","");
	q = q.replace("moms=1","");

	alert(q + "N: "+ q.indexOf("?"));
	if(q.indexOf("?") != -1)
		this.location.href=addr + q + '&moms=' + val + anchor;
	else
		this.location.href=addr + '?moms=' + val + anchor;
}

function pencolors(name)
{
	var win;
	win = window.open("http://reklambutiken.com/images/pencolors/"+name+".png","pencolors_"+name,"WIDTH=800,HEIGHT=800,SCROLLBARS=YES");
}

/** suckerfish dropdowns **/
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("topmenu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;