////////////////////////////////////////////////////////////////////////
// cplib.js by Alex Davidovic, alex.d@c-point.com                     //
// Copyright 2002 C Point                                             //
// This script is free for personal, educational, and commercial use  //
// provided that this header is left unmodified                       //
//                                                                    //
//           Created with Antechinus JavaScript Editor                //
//                        www.c-point.com                             //
////////////////////////////////////////////////////////////////////////

// C Point JavaScript Library v3.6

// ************  Move object functions ************ 
function initClassdraggable()
{
	bMoving = false;
	document.onmousedown=startMove;
	document.onmousemove=moveObj;
	document.onmouseup=new Function("bMoving=false");
}

function moveObj()
{
	if(!bMoving) return true;
	if(event.button!=1) return true;

// Reposition the object, keeping the same distance from the cursor
	ob.style.pixelLeft=event.clientX-xdif;
	ob.style.pixelTop=event.clientY-ydif;
	return false;
}

function startMove()
{
// Only "draggable" objects can move
	if(event.srcElement.className!="draggable") return;

	bMoving=true;
// Store the object and the differnce between the obj pos and cursor pos: it must remain the same
	ob=event.srcElement;
	xdif=event.clientX-event.srcElement.style.pixelLeft;
	ydif=event.clientY-event.srcElement.style.pixelTop;
}


// ************ Button Functions ************ 

// 2-state button (checkbox): function toggles the 2 states
function cpClickState(obj)
{
	if(obj.cpType=="2")
	{
		obj.cpType="1";
		obj.src=obj.cpDn;			
	}
	else
	{
		obj.cpType="2";	
		obj.src=obj.cpUp;
	}
}

function cpMouseOver(obj, f)
{
	obj.src=f;
}

function cpMouseOut(obj, f)
{
	obj.src=f;	
}

// Move/display the object at the specified location
function cpPopup(ob2, x, y)
{
	ob2.style.posLeft=x;
	ob2.style.posTop=y;
	ob2.style.visibility="visible";	
}

// Roll the first object, display the second at the specified location
function cpMousePopOver(ob1, f, ob2, x, y)
{
	cpMouseOver(ob1, f);
	cpPopup(ob2, x, y);	
}

// Roll the first object, display the second
function cpRollPopOver(ob1, f, ob2)
{
	cpMouseOver(ob1, f);
	ob2.style.visibility="visible";
}

// Restore the first object, hide the second
function cpMousePopOut(ob1, f, ob2)
{
	cpMouseOut(ob1, f);
	ob2.style.visibility="hidden";		
}

// Toggle the object's visibility
function cpPop(ob)
{
	if(ob.style.visibility=="visible") ob.style.visibility="hidden";	
	else ob.style.visibility="visible";	
}

// ************  Misc functions ************ 

// Return the random number between min and max
function cpRandom(min, max)
{
	var nRand = Math.random()*(max-min+1);
	return(Math.round(nRand + 0.5)+min-1);
}


