/**
 * This function shows the over state of a image
 *
 * @param   img   The img to rollover
 */
function doOver(img) {
	img.setAttribute("src",img.getAttribute("src").replace(/.gif/g,"_o.gif"));
}

/**
 * This function shows the out state of a image
 *
 * @param   img   The img to rollout
 */
function doOut(img) {
	img.setAttribute("src",img.getAttribute("src").replace(/_o\./g,"."));
}

/**
 * Open a new window
 */
function openNewWindow(url) {

	if(document.all) {
		var w = 817;
	} else {
		var w = 819;
	}
	
	var x = (screen.width / 2) - (w / 2);
	var y = (screen.height / 2) - (750 / 2);

	var new_win = window.open(url, "droppiewater", "menubar=0, toolbar=0, scrollbars=1, resizable=1, scale=1, status=0, width=" + w + ", height=550, left=" + x + ", top=" + y);
	new_win.focus();
}

/**
 * Open a new window
 */
function openNewWindowSize(url,width,height) {

	var x = (screen.width / 2) - (width / 2);
	var y = (screen.height / 2) - (750 / 2);

	var new_win = window.open(url, "droppiewater", "menubar=0, toolbar=0, scrollbars=1, resizable=1, scale=1, status=0, width=" + width + ", height="+ height +", left=" + x + ", top=" + y);
	new_win.focus();
	
}



function openFullscreenWindow( url ) {
	
	var width = screen.width;
	var height = screen.height;
	
	var x = 0;
	var y = 0;

	var new_win = window.open(url, "droppiewater", "menubar=0, toolbar=0, scrollbars=1, resizable=1, scale=1, status=0, width=" + width + ", height="+ height +", left=" + x + ", top=" + y);
	new_win.focus();
	
}


/**
 * Let Droppie scroll, wheeeee...
 */
function scrollingDroppie(obj) {
	
	var obj = findObj("droppie");
	var regio = findObj("regio_holder");
	if( !regio ) regio = findObj("regio_wrapper");
		
	var scrollSettings = getScrollXY();
	var windowSettings = getWindowSize();

	var oldx = parseInt(obj.style.top);
	var dx   = parseInt(oldx - (scrollSettings[1] + 20));
	var x    = oldx - dx / 12;
	
	if(x > 160 && x < (findPosY(regio) - 211)) {
		obj.style.top = x  + "px";
	}
	
}


/**
 * Initialize scrolling Droppie
 */
function initDroppie() {
	
	var droppie=findObj( 'droppie' );
	droppie.style.top = 160 + "px";
	setInterval(scrollingDroppie, 10, droppie);
	
}


/**
 * Return scroll X/Y position
 */
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement &&
	( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}
 
/**
 * Return window width/height setting
 */
function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
	  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

// Example: obj = findObj("image1");

function findObj(theObj, theDoc)

{

  var p, i, foundObj;

  

  if(!theDoc) theDoc = document;

  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)

  {

    theDoc = parent.frames[theObj.substring(p+1)].document;

    theObj = theObj.substring(0,p);

  }

  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

  for (i=0; !foundObj && i < theDoc.forms.length; i++) 

    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 

    foundObj = findObj(theObj,theDoc.layers[i].document);

  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  

  return foundObj;

}


function findPosX(obj)
{
	var curleft = 0;
	
	if( obj != null ){
	
		if ( obj != null && obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		
	}
	
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	//var printstring = '';
	
	if( obj != null ){
	
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				//printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		
	}
	//window.status = printstring;
	return curtop;
}

