/**

	showpopup.js

	V 1.0

	3/17/2006

	Copyright Jacky Huang

	flashlib@gmail.com

*/



function hidePopup() {

	// hide popup window (when rollout...)

	var popup = document.getElementById('popup');

	popup.style.visibility='hidden';

	window.clearTimeout(id);

}





function isArrived(popup){

	// check if the popup window is moved to the target place, mouse location

	// return true if it is arrived, otherwise else.

	var x = popup.offsetTop;

	var y = popup.offsetLeft;

	

	return ((x==popup.targetX)&&(y==popup.targetY));

}



function getWindowSize(){

	var w = 0;

	var h = 0;

	

	if(!document.all){

		//not IE

		w = window.innerWidth;

		h = window.innerHeight;

	}else{

		//IE

		w = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;

		h = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;

	}

	winWidth = w;

	winHeight = h;

}



function getIEBody(){

	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body

}



function adjustPosition(evt,popup){

	//ajust popup window's postion if necessary

	

	//check left

	if ((evt.clientX-popup.clientWidth-hPadding)<0){

		// move to the right

		popup.targetX = nowX + hPadding;

	}

	

	//check bottom

	if ((evt.clientY+popup.clientHeight+vPadding)>=winHeight){

		// move to the top

		popup.targetY = nowY - popup.clientHeight - vPadding;

	}

}



function showPopup(evt, img, name, email, headline, location, gender, age, dating, desc, height, weight, city, state, smoke, drink, sexorient, meeting, web, price, country){

	//show popup window with the content

		

	//get the event handle, and fit the IE and MF compatibility

	evt = evt ? evt : (window.event ? window.event : null);

	

	//get infomation

	if(img == ""){

		img = "images/default_pop.gif";

	}

	

	content = 	"<div class=pop_top>&nbsp;</div>"

					+ "<div class=pop_container>"

					+ "<div class=pop_img><img width=100 height=100 src=" + img + "></div>"

					+ "<div class=pop_info>"

					+ "<div class=pop_name>" + headline + "</div><div class=pop_seperator></div>"	
+ "<div class=pop_name>" + email + "</div>"
+ "<div class=pop_name>" + web + "</div>"
					+ "<br />";



		content += "<div class=pop_seperator></div>"

					+ "<div class=pop_item><table width=175><tr><td>Description: "+ desc +"</td></tr></table></div>"
+"<div class=pop_item>City: " + city + "   State: " + state + "<br>Country: " + country + "</div>"
          + "<div class=pop_seperator></div><div class=pop_item>Contact: " + price + "</div>";



	

	content += "</div>"

				+ "</div>"

				+ "<div class=pop_buttom>&nbsp;</div>";

	

	//get the handle of popup window

	var popup = document.all ? document.all["popup"] : document.getElementById ? document.getElementById("popup") : "";

	popup.innerHTML = content;



	//get the current mouse position

	nowX = MF ? evt.pageX : evt.clientX + getIEBody().scrollLeft;

	nowY = MF ? evt.pageY : evt.clientY + getIEBody().scrollTop;


	//set the target position of the popup window to the mouse position

	popup.targetX = nowX - popup.clientWidth - hPadding;

	popup.targetY = nowY + vPadding;



	//adjust the target position to prevent the edge effect

	getWindowSize();

	

	adjustPosition(evt,popup);	



	//set the popup window visible

	popup.style.visibility = 'visible';

	

	movePopup();



}



function movePopup(){

	//move popup window

	

	//clear timeout first

	window.clearTimeout(id);

	//get popup window handle

	var popup = document.all ? document.all["popup"] : document.getElementById ? document.getElementById("popup") : "";

	

	//get current position

	var nowx = popup.offsetLeft;

	var nowy = popup.offsetTop;

	

	if(!isArrived(popup)){

		// if not arrived, move

		if(nowx < popup.targetX){

			nowx += step;

		}

		if(nowx > popup.targetX){

			nowx -= step;

		}

		if(nowy < popup.targetY){

			nowy += step;

		}

		if(nowy > popup.targetY){

			nowy -= step;

		}

		

		popup.style.left = nowx;

		popup.style.top = nowy;

		

		id = window.setTimeout("movePopup()",1);

	}

}



//init IE and MF browser tags

var IE = document.all;

var MF = document.getElementById && !document.all;



//init window height and width

var winWidth = 0;

var winHeight = 0;



var id;

var step=5;



var nowX = 1;

var nowY = 1;



var hPadding = 25;

var vPadding = 25;



//get window size(don't do)

//getWindowSize();
