var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


var wedjets = new Array();
function wedjet_get(id)
{
	if (!wedjets[id])
	{
		wedjets[id]=document.getElementById(id + 'ContentArea');
	}
	return wedjets[id];
}
function wedjet_swap(id,shortname,number)
{
	wedjet_get(id).className = shortname + number;
}
function wedjet_buildswap(cid,id,path,shortname,count,instruction,poweredby)
{
	var str = new Array();
	str.push('<table align="center"  border="0" cellpadding="0" cellspacing="0" height="20">');
	str.push('<tr><td class=Directions colspan=' + count + '>' + instruction + '</td></tr>');
	str.push('<tr class=Selector>');
	for (wedjeti=1;wedjeti<=count;wedjeti++)
	{
		str.push('<td width="24"><img src="' + path + shortname + wedjeti + '.gif" onClick="wedjet_swap(\'' + cid + '\',\'' + shortname + '\',' + wedjeti + ');" border="0" border="0" style="cursor:pointer;"></td>');		
	}
	str.push('</tr>');
	str.push('<tr><td class=PoweredBy colspan=' + count + '>' + poweredby + '</td></tr>');
	str.push('</tr></table>');
	document.getElementById(cid+id).innerHTML = str.join('');
}

var a=50;
pos = 5;
TO = null;
function shake(object,speed)
{ 
  obj = eval(object)
 
  if (pos == 5)
  {
	pos = -5;
  }
  else
  {
	pos = 5;
  }  
  obj.style.left = parseInt(obj.style.left) + pos;
  obj.style.top = parseInt(obj.style.top) + pos;
  obj = object
  sp = speed
  TO = setTimeout("shake(obj,sp)",speed);
}
function stopshake(id)
{
	clearTimeout(TO);
	document.getElementById(id + "floatingbox").style.top = '102';
	document.getElementById(id + "floatingbox").style.left = '381';
}

function DoGetPos(event)
{
tempX = event.clientX + document.body.scrollLeft;
tempY = window.event.clientY + document.body.scrollTop;
}

function openfloatingrel(id,xpos,ypos)
{
var floater = document.getElementById(id + "floatingbox");
floater.style.top = ypos + 3; 
floater.style.left = xpos + 3; 
floater.style.display = 'block'; 
}

function openfloating(id)
{
   document.getElementById(id + "floatingbox").style.display = 'block';
}

function closefloating(id)
{
	//var str="<div class=normal><input type=checkbox id=" +id +"wigetclosecheck value=1 /> close this box in my future visits in next 24 hours</div>";
	//str += "<br /><div class=normal align=center>close</div>";
	//document.getElementById(id + "_ContentPane").innerHTML =str;
   setcookie(id + 'wigetclosecheck','closed',1);
   document.getElementById(id + "floatingbox").style.display = 'none';
}
function show_oio(id)
{
   document.getElementById(id + "floatingbox").style.display = '';
   shake(document.getElementById(id + "floatingbox"),75);
   setTimeout("stopshake('" + id + "')",1000);
}


function IsIE() {
	return (window.navigator.appName == 'Microsoft Internet Explorer')
}

function getWidth() {
	var iWidth = 0;
	
	if (IsIE()) {
		iWidth = document.body.clientWidth;
	}
	else {
		iWidth = window.innerWidth;
	}
	
	return (iWidth);
}
function getHeight() {
	var iHeight = 0;
	
	if (IsIE()) {
		iHeight = document.body.clientHeight;
	}
	else {
		iHeight = window.innerHeight;
	}
	
	return (iHeight);
}


function wedjet_floatPosition(id,top,left)
{
	var xfloatingbox = document.getElementById(id + 'floatingbox');
	xfloatingbox.style.top=top;
	xfloatingbox.style.left=left;
}

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setcookie(name,value,duration){
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	document.cookie=cookiestring;
	
	if(!getcookie(name)){
		return false;
	}
	else{
		return true;
	}
}

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function getmycookie(id,cookiename) {
	var cookiestring=getcookie(cookiename);
	if(cookiestring=='closed')
		{
			document.getElementById(id + "floatingbox").style.display = 'none';
			//alert(cookiestring);
		}
}
