var GeoDirection = '';
var x=0;
var y=0;
var appearX = 0;
var appearY = 0;
var current_direction = '';
var winWid = 630, winHei = 460;
var myWidth = 0, myHeight = 0;
var change = '';


function geotrust(direction) {
//	alert(direction);
	if (GeoDirection == '' || direction == 'hide') {
		GeoDirection = direction;
	}
if (GeoDirection == direction) {

	var incr = 0;
	var geo_style = document.getElementById('GeoTrust').style;
	var curMar = geo_style.marginTop;
	curMar = parseInt(curMar);
	if (direction == 'hide') {
	  curMar += 1;
	} else {
	  curMar -= 1;
	}
//alert(curMar);
	if (curMar > 0 || curMar < -37) {
		clearTimeout(t);
		GeoDirection = '';
	} else {
		geo_style.marginTop = curMar;
		t=setTimeout("geotrust('"+direction+"')",25); 
	}
	
}
}


function setPopupCentre() {
	winSize();
	appearX = myWidth/2 ;
	appearY = (myHeight/2)-75+ document.documentElement.scrollTop;
}

function resetPopupOrigin() {
	appearX = 0;
	appearY = 0;
}

function expand(targetid, direction, maxX, maxY, removeBorder) {
	if (removeBorder == '') {
		removeBorder = "false";
	}

	if (current_direction == '') {
		current_direction = direction;
	}

	if (current_direction == direction) {
		winSize();
		
		if (direction == 'hide') {
		  document.getElementById(targetid+'_inner').style.display='none';
		  borderShow(targetid);
		}
	
		var target_style = document.getElementById(targetid).style;
	
		if (target_style.display != 'block'){
			target_style.display = 'block';
		}
		if(appearX == 0 || appearY == 0){
		  appearX = xMousePos;	
		  appearY = yMousePos + 10;	
	//	  target_style.top=appearY+'px';
		}
	
		var leftPos = appearX-(x/2);
		var topPos = appearY;
		if (leftPos > (myWidth - x - 25)) {
		leftPos = (myWidth - x - 25);
		}
	
		var topPos = appearY;
		if (appearY > (myHeight - y - 100)) {
		  topPos = (myHeight - y - 100);
		}
		target_style.top=topPos+'px';
	//alert("appear"+appearY+" max: "+yMousePosMax+" y => "+y+" winH"+winHei);
	
		target_style.left=leftPos+'px';
		target_style.display='block';
		target_style.height=y+'px';
		target_style.width=x+'px';
	
		if (direction == 'show') {
			if(x>maxX || y>maxY) { 
				clearTimeout(t);
				document.getElementById(targetid+'_inner').style.display='block';
				current_direction = '';
				if (removeBorder == "true") {
					borderRemove(targetid);
				}
				return;
			}
			y=y+16;
			x=x+24;
		} else {
			y=y-16;
			x=x-24;
		}
		if(x<=0) { 
			clearTimeout(t);
			document.getElementById(targetid).style.display='none';
			appearX = 0;
			appearY = 0;
			current_direction = '';
			return;
		}
		t=setTimeout("expand('"+targetid+"', '"+direction+"', '"+maxX+"', '"+maxY+"', '"+removeBorder+"')",25); 
	}
}

function borderShow(targetid) {
	var targetDiv = document.getElementById(targetid).style;
	targetDiv.border = '1px solid #660033';
	targetDiv.background = '#ffffff';
}
function borderRemove(targetid) {
	var targetDiv = document.getElementById(targetid).style;
	targetDiv.border = 'none';
	targetDiv.background = 'transparent';
}

function hideDiv(targetid) {
	document.getElementById(targetid).style.display='none';
}

function grow(targetid, increment){
theheight=document.getElementById(targetid).offsetHeight;
alert(document.getElementById(targetid).style.height);
if(theheight<100){
document.getElementById(targetid).style.height=theheight+increment+'px';
}
else if(theheight>100){
clearInterval(change);
}
}
//change=setInterval("grow('thediv')",150);
function growmore(targetid, increment){
theheight=document.getElementById(targetid).offsetHeight;
if(theheight<100){
document.getElementById(targetid).style.height=theheight+increment+'px';
}
else if(theheight>100){
clearInterval(change);
}
//document.getElementById(targetid).style.height=theheight+10+'px';
}
function growless(targetid){
theheight=document.getElementById(targetid).offsetHeight;
document.getElementById(targetid).style.height=theheight-10+'px';
}

function start_grow(target_id, interval){
	change=setInterval("growmore(\'thediv\', \'10\')", 1000);
}

function winSize() {
  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;
  }
}


