/**
 * Common Javascript functions used for the
 * EuroAlumni web application
 * (c) 2001 - 2009 Euro-Alumni e.V.
 **/
 

/**
 * Date Selector functions
 * Opens a new date selector at the current position
 * and allows the selection of a month and year
 * Each input field can have it's own date selector open, but
 * the field needs to have a unique ID
 **/
function DateSelector( inputFieldID ) {

	//The ID of the input field
	this.inputFieldID = inputFieldID;
	
	//The actual input field
	this.inputField = document.getElementById( inputFieldID );
	
	//The id of the main element
	this.selectorID = "dateSelector"+inputFieldID;
	
	//Check if another copy already exists => close it
	if ( document.getElementById( this.selectorID ) ) {
		this.selectorDiv = document.getElementById( this.selectorID );
		this.remove();
		return;
	}
	
	//Is the mouse currently over this element
	this.hasMouse = false;
	
	//Create a new date selector
	var dateSelector = document.getElementById("dateSelector");
	var newDateSelector = dateSelector.cloneNode( true );
	
	//Change the main ID
	newDateSelector.setAttribute( "id", this.selectorID );
	
	//Change the function call in all links
	var allLinksInSelector = newDateSelector.getElementsByTagName("a");
	for ( var t=0; t<allLinksInSelector.length; t=t+1 ) {
	
		//Get the link
		var thisLink = allLinksInSelector[t];
		
		//Exchange the actual function call
		thisLink.href = thisLink.href.replace( /dateSelector/, "getDateSelector('"+this.inputFieldID+"')" );
	}
	
	//Change the IDs
	adjustIDs ( newDateSelector, this.selectorID );
	
	//Calculate the position, so the selector appears directly below 
	//the input field
	var xPos = this.inputField.offsetLeft;
	var yPos = this.inputField.offsetTop + this.inputField.offsetHeight + 5;
	newDateSelector.style.top = yPos + "px";
	newDateSelector.style.left = xPos + "px";
 
 	//Save the selector div to be used
 	this.selectorDiv = newDateSelector;

	//Show the selector div
	this.selectorDiv.style.display = "block";

	//Insert it into the offSet parent of the input field in question
	this.inputField.parentNode.insertBefore( this.selectorDiv, this.inputField.parentNode.firstChild );
	//alert( "Margin left: "+this.selectorDiv.style.paddingLeft + "; offsetLeft: "+this.selectorDiv.offsetLeft );

	//Clean the month highlighting(s)
	this.clearMonthSelections();

	//Get the current date
	this.currentDate = this.inputField.getAttribute("value");

	//Get the year and set it in the selector
	this.year = this.currentDate.replace(/.*\//,"");
	if ( ! ((this.year > 1900) && (this.year < 2100)) ) {
		var thisDate = new Date();
		this.year = thisDate.getFullYear();
	}
	this.setYear( this.year );		

	//Get the month and highlight it in the selector
	this.month = this.currentDate.replace(/\/.*/,"");
	this.highlightMonth();
	
	//Register functions for hasMouse
	this.selectorDiv.onmouseover = function() { getDateSelector(inputFieldID).hasMouse = true; };
	this.selectorDiv.onmouseout = function() { getDateSelector(inputFieldID).hasMouse = false; };
	
	//Register the new instance (only one per pic archive id is possible)
	DateSelectors[inputFieldID] = this;
}


	/**
	 * Opens the date selector for this input field and sets the correct ID
	 * This creates a separate, modified copy 
	 * 
	 */
	function openDateSelector( inputFieldID ) {

		//Creates a new date selector		
		var newDateSelector = new DateSelector( inputFieldID );
	}


	/**
	 * Adjusts the IDs of the elements iteratively,
	 * exchanging "dateSelector" by the selectorID
	 **/
	  function adjustIDs ( startNode, selectorID ) {
	 
		var childs = startNode.childNodes;
		for ( var t=0; t<childs.length; t=t+1 ) {
			
			//If the element has an id, change it
			var thisChild = childs[t];
			if ( thisChild.id ) {
				thisChild.id = thisChild.id.replace( /dateSelector/, selectorID );
			}
			
			//Take care of the children
			if ( thisChild.hasChildNodes() ) {
				adjustIDs ( thisChild, selectorID );
			}
		}	 	
	 }
	 

	/**
	 * Adjusts the year
	 **/
	DateSelector.prototype.adjustYear = function ( numberToAdjust ) {
	
		//Get the current year and adjust it
		var year = this.getCurrentYear();
		year = eval( year + " + "+numberToAdjust );
		
		//Put it back
		this.setYear( year );
		
		//Clear the months first, then highlight the correct month
		//(only if in the correct year)
		this.clearMonthSelections();
		this.highlightMonth();
	};
	
	/**
	 * Gets the current year
	 **/
	DateSelector.prototype.getCurrentYear = function() {
	
		//Get the span containing the year
		var yearSpan = document.getElementById( this.selectorID+"YearText");
		
		//Get the current year and return it
		var year = yearSpan.firstChild.nodeValue;
		return year;
	};
	
	
	/**
	 * Sets a year to display
	 */
	DateSelector.prototype.setYear = function( year ) {
	
		//Get the span containing the year and set it
		var yearSpan = document.getElementById( this.selectorID+"YearText");
		yearSpan.firstChild.nodeValue = year;
	};


	/**
	 * Clears the highlighting of all month selections
	 */
	DateSelector.prototype.clearMonthSelections = function() {
	
		//Remove the class from all anchors in the table
		var monthElement = document.getElementById( this.selectorID+"Months" );
		var months = monthElement.getElementsByTagName("a");
		for ( var t=0; t < months.length; t=t+1 ) {

			months[t].className = "";		
		}
	};


	/**
	 * Highlights the currently selected month
	 * if the right year is currently displayed
	 */
	DateSelector.prototype.highlightMonth = function() {
		
		//If the month is "Ongoing", highlight this field and exit
		if ( this.month == "Ongoing" ) {
			var ongoing = document.getElementById( this.selectorID+"Ongoing" );
			ongoing.className = "highlightedMonth";
			return;
		}
		
		//Check if the right year is displayed
		if ( this.getCurrentYear() == this.year ) {
		
			//Highlight the original month if it makes sense
			if ( (this.month > 0) && (this.month < 13) ) {
				var monthID = this.selectorID+"Month"+this.month;
				var monthA = document.getElementById( monthID );
				monthA.className = "highlightedMonth";
			}
		}
	};
	
	
	/**
	 * Selects the month and year and closes the date selector
	 **/
	DateSelector.prototype.thisDate = function ( month ) {
		
		//Get the currently selected year
		var year = this.getCurrentYear();
		
		//Assemble it and put it to the original field
		var finalDate = "";
		if ( month < 10 ) {
			finalDate = "0"+month+"/"+year;
		} else {
			finalDate = month+"/"+year;
		}
		
		//Put it, then close the selector
		this.inputField.setAttribute( "value", finalDate );
		this.selectorDiv.style.display = "none";
		
		//Remove this selector
		this.remove();
	};
	
	
	/**
	 * Selects the String "Ongoing"
	 **/
	DateSelector.prototype.selectOngoing = function () {
		
		//Put it, then close the selector
		this.inputField.setAttribute( "value", "Ongoing" );
		this.selectorDiv.style.display = "none";
		
		//Remove this selector
		this.remove();
	};
	
	
	/**
	 * Removes the date selector div from the page,
	 * clears the attribute and removes it from the 
	 * instances as well
	 **/
	DateSelector.prototype.remove = function() {
	
		//Remove the selector
		var selectorParent = this.selectorDiv.parentNode;
		if ( selectorParent !== null ) {
			selectorParent.removeChild( this.selectorDiv );
			this.selectorDiv = null;
			removeDateSelector( this.inputFieldID );
		}
	};
	

	/**
	 * Removes the date selector div from the page
	 * if the cursor is outside the div itself
	 **/	
	DateSelector.prototype.removeIfOutside = function( e ) {
	
		//Return if outside
		if ( this.hasMouse === true ) {
			return;
		}
	
		//Close it
		this.remove();   
	};
	
	
/**
 * Returns the correct date selector
 * for the input field
 **/
function getDateSelector( inputField ) {

	return DateSelectors[inputField];
}

function removeDateSelector( inputField ) {

	  for( var t=0; t<DateSelectors.length; t=t+1 ) {
	    if( DateSelectors[t] == DateSelectors[inputField] ) {
	    	DateSelectors.splice(t, 1);
	    }
	  }
}

//Array of date selector objects
var DateSelectors = {};


/**
 * Show a help bubble for a specific element
 * (usually to the right). Initialising the function
 * adds the onmouseover and onmouseout handlers to the
 * elements specified resp onfocus / onblur for input
 * fields.
 * @param key the key of the item for which to show the text
 * @param elementId the ID of the element next to which 
 *         to show the bubble
 * @param helpText the text to show
 */
function HelpText( key, elementId, helpText ) {
	
	//The id of the main element
	this.key = "helpText"+key;

	//Store element and help text
	this.elementId = elementId;
	this.helpText = helpText;
	
	//Get the element itself
	this.element = document.getElementById( elementId );
	
	//Exit if no element was found
	if ( this.element === null ) {
		return;
	}
	
	//Register this instance
	HelpTexts[key] = this;

	//Add the handlers (different for input fields)
	if ( (this.element.nodeName.toLowerCase() == "input") ||
		 (this.element.nodeName.toLowerCase() == "textarea") ||
		 (this.element.nodeName.toLowerCase() == "select") ) {

		this.element.onfocus = function() { getHelpText( key ).show(); };
		this.element.onblur = function() { getHelpText( key ).hide(); };

	} else {
		
		this.element.onmouseover = function() { getHelpText( key ).show(); };
		this.element.onmouseout = function() { getHelpText( key ).hide(); };
	}
	
	/**
	 * Show the help text
	 */
	this.show = function() {
		
		//Check if the div was built already
		var helpDiv = document.getElementById( this.key );
		
		//Create the div if it does not exist already
		if ( helpDiv === null ) {
			
			helpDiv = document.createElement( "div" );
			helpDiv.className = "helpDiv";
			helpDiv.id = this.key;
			//helpDiv.appendChild( document.createTextNode( this.helpText ) );
			helpDiv.innerHTML = this.helpText;
			var body = document.getElementsByTagName( "body" )[0];
			body.appendChild( helpDiv );
		}
		
		//Show to the right of the orginal element
		var pos = getObjectPosition( this.element );
		var xPos = pos.x + this.element.offsetWidth + 5;
		var yPos = pos.y - 5;
		helpDiv.style.top = yPos + "px";
		helpDiv.style.left = xPos + "px";
		helpDiv.style.display = "block";
	};
	
	/**
	 * Show the help text
	 */
	this.hide = function() {
		
		//Check if the div was built already
		var helpDiv = document.getElementById( this.key );
	
		if ( helpDiv !== null ) {
			helpDiv.style.display = "none";
		}
	};
		
}
var HelpTexts = {};

/**
 * Returns the correct help text for the key
 **/
function getHelpText( key ) {

	return HelpTexts[key];
}

/**
 * "Class" for determining the size of the current display window
 */
function WindowSize() {

	//The total height of the window
	this.height = 100;

	//The width of the window
	this.width = 100;

	//The top and bottom location of the visible area
	this.visibleTop = 0;
	this.visibleBottom = 100;
	
	//The total height of the document
	this.documentHeight = 100;

	/**
	 * Refreshes the values by re-calculating the window size
	 */
	this.refresh = function() {

		//Cross browser code
		if (window.innerHeight) { // all except Explorer
			this.height = window.innerHeight;
			this.width = window.innerWidth;
			this.visibleTop = window.pageYOffset;
		}
		else if (document.documentElement ) {
			// Explorer 6 Strict Mode
			var docElement = document.documentElement;
			if ( docElement.clientHeight ) {
				this.height = docElement.clientHeight;
				this.width = docElement.clientWidth;
				this.visibleTop = docElement.scrollTop;
			}
		}
		else if (document.body) // other Explorers
		{
			var docBody = document.body;
			this.height = docBody.clientHeight;
			this.width = docBody.clientWidth;
			this.visibleTop = docBody.scrollTop;
		}		
		
		//Use the top to calculate the bottom value
		this.visibleBottom = this.visibleTop + this.height;
		
		//Calculate the total height of the document
		var body = document.getElementsByTagName( "body" )[0];
	    var html = document.documentElement;
	    this.documentHeight = 
	    	Math.max( body.scrollHeight, body.offsetHeight, 
	                  html.clientHeight, html.scrollHeight, html.offsetHeight );
	};
}

//Initialise the window size function
var windowSize = new WindowSize();
windowSize.refresh();


/**
 * Builds the deletion panel and shows it to the user
 * with 2 buttons: Delete and Cancel
 * If the user clicks on cancel, the panel closes again.
 * If he clicks on delete, the specified delete function
 * is called.
 * @param questionText the text of the delete question
 *        to ask
 * @param deleteFunction the function that will be called
 *        if the user clicks on the delete button
 **/
function showDeletePanel( questionText, deleteFunction ) {

  //Remove any old panel if it exists
  var oldPanel = document.getElementById('confirmationPanelDelete');
  if ( oldPanel ) {
    oldPanel.parentNode.removeChild( oldPanel );
  }

  //Build the panel
  var deletePanel = document.createElement( "div" );
  deletePanel.id = "confirmationPanelDelete";
  deletePanel.className = "picarchiveConfirmationPanelDelete";
  
  //Question text
  var question = document.createElement( "p" );
  question.appendChild( document.createTextNode( questionText + "\n\n" ) );
  deletePanel.appendChild( question );
  
  //Delete button
  var deleteButton = document.createElement( "a" );
  deleteButton.title = "Delete";
  deleteButton.href = "#";
  deleteButton.className = "modernfakebutton";
  deleteButton.style.left = "20px";
  deleteButton.onclick = 
    function() {
      eval( deleteFunction );       
      vanishDeletePanel();
      return false;
    };
  var deleteText = document.createElement( "span" );
  deleteText.appendChild( document.createTextNode( "Delete" ) );
  deleteButton.appendChild( deleteText );
  deletePanel.appendChild( deleteButton );
  
  //Cancel button
  var cancelButton = document.createElement( "a" );
  cancelButton.title = "Cancel";
  cancelButton.href = "#";
  cancelButton.className = "modernfakebutton";
  cancelButton.style.right = "20px";
  cancelButton.style.marginLeft = "20px";
  cancelButton.onclick = 
    function() { 
      vanishDeletePanel();
      return false; 
    };
  var cancelText = document.createElement( "span" );
  cancelText.appendChild( document.createTextNode( "Cancel" ) );
  cancelButton.appendChild( cancelText );
  deletePanel.appendChild( cancelButton );
  
  //Grey out
  greyOut();
  
  //Add to the body, set to the right position and show
  document.getElementsByTagName("body")[0].appendChild( deletePanel );
  windowSize.refresh();
  deletePanel.style.top = Math.floor( ( windowSize.visibleTop + (windowSize.height / 2) ) - 100) + "px";
  deletePanel.style.left = Math.floor( ( (windowSize.width - 3) / 2 ) - 130) + "px";
  deletePanel.style.display = "block";
}


function vanishDeletePanel() {

  var panel = document.getElementById('confirmationPanelDelete');
  if ( panel ) {
    panel.style.display='none';
    panel.parentNode.removeChild( panel );
  }
  vanishGreyOut();
}

/**
 * Builds the grey out div overlay and displays
 * it
 **/
function greyOut() {

  //Build the div
  var greyOutOverlay = document.createElement( "div" );
  greyOutOverlay.id = "greyOutOverlay";
  greyOutOverlay.className = "greyOutOverlay";
  
  //Add it to the body
  document.getElementsByTagName("body")[0].appendChild( greyOutOverlay );
  
  //Set the right size

  //Refresh the window size
  windowSize.refresh();
  
  //Set the size correctly
  greyOutOverlay.style.height = windowSize.documentHeight +"px";
  greyOutOverlay.style.width = windowSize.width + "px";
  
  //Set it to start at the top
  greyOutOverlay.style.top = "0px";
  
  //Make it visible
  greyOutOverlay.style.display = "block";

  //Fade in with only 2 steps    
  var fader = new EaFader( "greyOutOverlay" );
  fader.fade( 0, 75, 100, 40 );
}


/**
 * Removes the grey-out layer again
 **/
function vanishGreyOut() {
  
  //Get the element
  var greyOutOverlay = document.getElementById( "greyOutOverlay" );
  if ( greyOutOverlay ) {
    
    greyOutOverlay.parentNode.removeChild( greyOutOverlay );
  }
}  


/** 
 * Blending functions thanks to http://www.brainerror.net
 */
var currentBrowser = "";

/**
 * Fades in or out an object by specifying the id,
 * start opacity, end opacity and the duration.
 * @param id the id of the object to fade
 * @param opacStart the start opacity from 0 - 100
 * @param opacEnd the end opacity from 0 - 100
 * @param totalFadingTime the total fade duration in milli-seconds
 * @param timePerStep the time per fading step in milli-seconds to use
 */
function opacity(id, opacStart, opacEnd, totalFadingTime, timePerStep ) {
	
	
	return;
	//Calculate the number steps needed
	var numberSteps = Math.round( totalFadingTime / timePerStep );
	
	//The opacity adjustment per step
	var opacityAdjustmentPerStep = Math.abs( Math.round( ( opacStart - opacEnd ) / numberSteps ) );

	//The timer always starts at 0
	var timer = 0;
	
	//If the adjustment per step is not there, use 10
	if ( opacityAdjustmentPerStep === null ) {
		opacityAdjustmentPerStep = 10;
	}
	
	//Cross browser code
	currentBrowser = "FF";
	if ( window && window.innerHeight ) { // all except Explorer
		currentBrowser = "FF";
	}
	else if ( document && document.all ) { // Explorer 6 
		currentBrowser = "IE";
	}

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(var i = opacStart; i >= opacEnd; i=i-opacityAdjustmentPerStep) {
			window.setTimeout("changeOpac('" + id + "'," + i + ")",(timer * timePerStep));
			timer=timer+1;
		}
	} else if(opacStart < opacEnd) {
		for( i = opacStart; i <= opacEnd; i=i+opacityAdjustmentPerStep) {
			window.setTimeout("changeOpac('" + id + "'," + i + ")",(timer * timePerStep));
			timer=timer+1;
		}
	}
}

/**
 * Change the opacity for different browsers
 * @param id the id of the object for which to change the
          opacity
 * @param opacity the desired opacity from 0 - 100
 */
function changeOpac( id, opacity ) {
	
	/** Get the object **/
	var object = document.getElementById( id );

	/** Some security **/	
	if ( opacity > 99 ) {
		opacity = 99;
	}
	if ( opacity < 0 ) {
		opacity = 0;
	}
	
	if ( object && object.style ) {
		if ( document && document.all ) {
			object.style.filter = "alpha(opacity=" + opacity + ")";
		} else {
			try {
				object.style.MozOpacity = ( opacity / 100 );
			} catch ( err ) {
				//Try other browsers
				if ( object.style.KhtmlOpacity ) {
					object.style.KhtmlOpacity = ( opacity / 100 );
				} else if ( object.style.opacity ) {
					object.style.opacity = ( opacity / 100 );
				}
			}				
		}
	}
}



/**
 * Object oriented version of the fader 
 **/
function EaFader( objectID ) {

	/** The object id **/
	this.objectID = objectID;
	
	/** The actual object reference **/
	this.object = document.getElementById( objectID );
	
	/** The starting opacity **/
	this.opacStart = 100;
	
	/** The ending opacity **/
	this.opacEnd = 0;
	
	/** The total fading time in milliseconds **/
	this.totalFadingTime = 500;
	
	/** The time taken per step in milliseconds **/
	this.timePerStep = 50;
	
	/** At which step we currently are **/
	this.currentStep = 0;
	
	/** How many steps are needed in total **/
	this.totalSteps = 10;
	
	/** The opacity adjustment per step **/
	this.opacityAdjustmentPerStep = 10;

	/** The unique id **/
	this.uniqueID = this.ObjectID + "_" + Math.floor( Math.random()*10000 );
	
	/** Register this fader **/
	EaFaders[ this.uniqueID ] = this;

	/** Is this Firefox or IE **/
	this.ff = false;
	this.ie = false;
		

	/**
	 * Fades in or out an object by specifying the 
	 * start opacity, end opacity and the duration.
	 * @param opacStart the start opacity from 0 - 100
	 * @param opacEnd the end opacity from 0 - 100
	 * @param totalFadingTime the total fade duration in milli-seconds
	 * @param timePerStep the time per fading step in milli-seconds to use
	 */
	this.fade = function ( opacStart, opacEnd, totalFadingTime, timePerStep ) {
		
		//Remember the variables
		this.opacStart = opacStart;
		this.opacEnd = opacEnd;
		this.totalFadingTime = totalFadingTime;
		this.timePerStep = timePerStep;
		
		//Calculate the number steps needed
		this.totalSteps = Math.round( totalFadingTime / timePerStep );
		
		//The opacity adjustment per step
		this.opacityAdjustmentPerStep = Math.abs( Math.round( ( opacStart - opacEnd ) / this.totalSteps ) );
	
		//The timer always starts at 0
		this.timer = 0;
		
		//If the adjustment per step is not there, use 10
		if ( this.opacityAdjustmentPerStep === null ) {
			this.opacityAdjustmentPerStep = 10;
		}
		
		//Browser recognition
		if ( document && document.all ) {
			this.ie = true;
		} else {
			try {
				this.object.style.MozOpacity = ( this.opacStart / 100 );
				this.ff = true;
			} catch ( err ) {
				//Do nothing, this.ff is already false
			}
		}
		
		
		//Start with the first step
		this.nextFadeStep();
	};

	/**
	 * Do the next fading step
	 **/
	this.nextFadeStep = function() {

		//Calculate the opacity
		var currentOpacity = this.opacStart;
		if( this.opacStart > this.opacEnd) {
			currentOpacity = Math.floor( this.opacStart - ( this.currentStep * this.opacityAdjustmentPerStep ) );
		} else if ( this.opacEnd > this.opacStart ) {
			currentOpacity = Math.floor( this.opacStart + ( this.currentStep * this.opacityAdjustmentPerStep ) );
		}
		
		//Set it on the object
		//changeOpac( this.objectID, currentOpacity );

		/** Some security **/	
		if ( currentOpacity > 99 ) {
			currentOpacity = 99;
		}
		if ( currentOpacity < 0 ) {
			currentOpacity = 0;
		}
		
		//Actually set the opacity on the object
		if ( this.ie === true ) {
				this.object.style.filter = "alpha(opacity=" + currentOpacity + ")";
		} else if ( this.ff === true ) {
				this.object.style.opacity = ( currentOpacity / 100 );
		} else {
				//Try other browsers
				if ( this.object.style.KhtmlOpacity ) {
					this.object.style.KhtmlOpacity = ( currentOpacity / 100 );
				} else if ( this.object.style.opacity ) {
					this.object.style.opacity = ( currentOpacity / 100 );
				}
		}				
		
		//Increase the current step
		this.currentStep = this.currentStep + 1;
		
		//If there is more to do, do it
		if ( (this.currentStep < this.totalSteps) && (this.currentStep < 50) ) {
			window.setTimeout( "EaFaders['"+this.uniqueID+"'].nextFadeStep()", (this.timePerStep - 2) );
		} else {
			//Remove the object
			EaFaders[ this.uniqueID ] = null;
		}
	};
}

//Array of faders
var EaFaders = {};


/**
 * Get the position of the cursor
 * @param event the event
 **/
function getCursorPosition( event ) {
	var e = event;
    if (!e) { 
    	e = window.event;
    }
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


/**
 * Finds the position of an object
 * relative to absolute zero (0,0)
 **/
function getObjectPosition( obj ) {
  var position = {x:0, y:0};
	if (obj.offsetParent) {
		position.x = obj.offsetLeft;
		position.y = obj.offsetTop;
		while (obj = obj.offsetParent) {
			position.x += obj.offsetLeft;
			position.y += obj.offsetTop;
		}
	}
	return position;
}


/**
 * Checks if the mouse cursor is over an object
 * @param obj the object to check for
 * @return true if the mouse cursor is over an
 *         object and false if it is not
 */
function isMouseOverObject( obj ) {
	
	//Get the object and cursor position
	var position = getObjectPosition( obj );
	var cursor = getCursorPosition( window.event );
	
	//Compare
	if ( (cursor.x >= position.x) && 
		 (cursor.x <= (position.x+obj.offsetWidth)) &&
		 (cursor.y >= position.y) &&
		 (cursor.y <= (position.y+obj.offsetHeight))) {
       return true;
	}
	return false;
}
