
var _ge=function(id)
{
	el=document.getElementById(id);
	return el;
};

var _pi=function(str)
{	
	return parseInt(str,10);
};

var _pf=function(str)
{
	return parseFloat(str);
};



var decorate_tooltipContainer = function()
{
	// arg[0] = tooltip container
	var EL = arguments[0];
		
	// create the extent object for the container
	EL.EXT = new Image_ToolTip_Container_EXT( arguments[0], arguments[1] );
	
	return EL;
};

Image_ToolTip_Container_EXT=function(el,photo_div )
{
	var 	EL = this.EL=el;
	var 	myself = this;
	
	myself.isOver=0;
	myself.which_note=null;
	myself.photo_div=photo_div;
	myself.hex_colors={
		yellow:"#ffffd3",green:"#d0fdaf"
	};
	
	photo_div.EL = el;
	myself.notes_text_div=_ge("notes_text_div");
	myself.notes_text_div.innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"padding:0px;\" id=\"notes_text_table\">"+"<tr><td><img width=\"3\" height=\"3\" src=\"/images/tc_yellow_tl.gif\"></td><td class=\"td_note_yeller\"></td><td><img width=\"3\" height=\"3\" src=\"/images/tc_yellow_tr.gif\"></td></tr>"+"<tr><td class=\"td_note_yeller\"></td>"+"<td class=\"td_note_yeller\" style=\"padding:3px\">"+"<span id=\"notes_text_span\" style=\"font-family:arial; font-size:12px;\"></span>"+"<form id=\"notes_text_form\"><input type=\"hidden\" name=\"magic_cookie\" value=\"\" />"+""+"</form>"+"</td><td class=\"td_note_yeller\"></td></tr>"+"<tr><td><img width=\"3\" height=\"3\" src=\"/images/tc_yellow_bl.gif\"></td><td class=\"td_note_yeller\"></td><td><img width=\"3\" height=\"3\" src=\"/images/tc_yellow_br.gif\"></td></tr></table>"+"<form id=\"notes_text_buttons_form\"></form><div id=\"temp_div\" style=\"visibility:hidden;\"></div>";
	myself.notes_text_table=_ge("notes_text_table");
	myself.notes_text_span=_ge("notes_text_span");
	// myself.notes_text_area=_ge("notes_text_area");
	myself.notes_text_form=_ge("notes_text_form");
	myself.notes_text_div.style.zIndex="1000";
	myself.notes_text_div.style.display="none";
	myself.notes_text_div.style.width="220px";
	myself.notes_text_div.style.position="relative";
	window.temp_div=_ge("temp_div");
	// temp_div.style.width=myself.notes_text_area.style.width;

	
	myself.photo_div.onmouseover=function(){
		EL.onmouseover();
	};
	
	myself.photo_div.onmouseout=function() {
		// EL.onmouseout();
		var 	EL = this.EL;
		
		EL.EXT.take_her_away('EXT.photo_div.onmouseout');
	};


	for(var i=0;i<EL.childNodes.length;i++){
		if(EL.childNodes[i].className=="tooltip"){
			EL.childNodes[i].EXT.papa=EL;
		}
	}

	EL.onmouseover=function() {
		EL.style.visibility="visible";

		clearTimeout(this.EXT.hide_tim);

		this.EXT.isOver=1;
		this.EXT.change_display();
	};

	
	this.take_her_away=function( el ){
		myself.isOver=0;
		myself.stop_showing_one("take_her_away " + el);
		myself.change_display();
	};

	this.make_note_this_color=function( whichColor ){
		var lastColor=(myself.last_note_color)?myself.last_note_color:"yellow";
		if(lastColor==whichColor){
			return;
		}
		// myself.notes_text_area.style.backgroundColor=myself.hex_colors[whichColor];
		var tds=EL.getElementsByTagName("TD");
		for(var i=0;i<tds.length;i++){
			if(tds[i].className=="td_note_yeller"){
				tds[i].style.backgroundColor=myself.hex_colors[whichColor];
			}
		}
		var _28=EL.getElementsByTagName("IMG");
		for(var i=0;i<_28.length;i++){
			if(_28[i].src){
				_28[i].src=_28[i].src.replace(lastColor,whichColor);
			}
		}
		myself.last_note_color=whichColor;
	};


	this.start_showing_one=function( el ){
		clearTimeout(myself.hide_tim);
		if(myself.which_note){
			clearTimeout(myself.which_note.EXT.hide_timmy);
		}
		if(myself.which_note != el ){
			myself.stop_showing_one();
		}
		myself.make_note_this_color(el.EXT.use_color);
		var txt=el.EXT.render_text_for_display();

		myself.notes_text_span.innerHTML=txt;
		myself.which_note=el;
		myself.notes_text_span.style.display="inline";
		myself.notes_text_div.style.display="block";
		myself.place_notes_text_div();
	};

	this.place_notes_text_div=function(_31,_32){
		if(_31&&_32){
			var nx=_31;
			var ny=_32+myself.which_note.EXT.get_note_h()+5;
		}
		else
		{
			var _35=100;
			var _36=200;
			var nx=_pi(myself.which_note.style.left);
			var ny=_pi(myself.which_note.style.top)+myself.which_note.EXT.get_note_h()+5;
			if(ny+myself.notes_text_div.offsetHeight>myself.get_image_h()+_35){
				ny=_pi(myself.which_note.style.top)-myself.notes_text_div.offsetHeight-10;
				if(document.all&&navigator.userAgent.indexOf("Opera")==-1){
					ny+=15;
				}
			}
			if(ny<-_36){
				ny=_pi(myself.which_note.style.top)+myself.which_note.EXT.get_note_h()+5;
			}
		}
		myself.notes_text_div.style.left=nx+"px";
		myself.notes_text_div.style.top=ny+"px";
	};


	this.stop_showing_one=function(_37){
		myself.notes_text_div.style.display="none";
		if(myself.which_note){
			myself.which_note.EXT.isOver=0;
			myself.which_note.EXT.change_display();
		}
	};

	this.get_image_w=function(){
		return myself.photo_div.childNodes[0].width;
	};

	this.get_image_h=function(){
		return myself.photo_div.childNodes[0].height;
	};


	this.change_display=function()
	{
		if(myself.isOver){
			EL.style.visibility="visible";
		}
		else{
			EL.style.visibility="hidden";
		}
	};

	
};

var decorate_tooltip = function()
{
	// arg[0] = tooltip container
	var EL = arguments[0];
		
	// create the extent object for the tooltip
	EL.EXT = new Image_ToolTip_EXT( arguments[0], arguments[1] );
	
	return EL;
};

Image_ToolTip_EXT=function(el,theText )
{	
	var EL=this.EL=el;
	var EXT=this;

	EXT.isOver=0;
	EXT.last_rendered_txt="";

	EXT.box_div=EL.childNodes[0];
	EXT.innermost_div=EXT.box_div.childNodes[0].childNodes[0].childNodes[0];
	if(document.all&&!window.opera){
		// EXT.innermost_div.style.backgroundColor="#00ff00";
		// EXT.innermost_div.style.filter="alpha(opacity:0)";
	}
	EXT.text_div=EL.childNodes[1];
	EXT.saved_txt=theText;

	EXT.saved_x=_pi(EL.style.left);
	EXT.saved_y=_pi(EL.style.top);
	EXT.saved_w=_pi(EXT.innermost_div.style.width);
	EXT.saved_h=_pi(EXT.innermost_div.style.height);
	EXT.box_div.onmouseover=EXT.onmouseover;
	EXT.box_div.onmouseout=EXT.onmouseout;
};

Image_ToolTip_EXT.prototype.render_text_for_display=function(){
	var EL=this.EL;
	var EXT=this;
	var txt=EXT.saved_txt;
	if(EXT.last_saved_txt!=EXT.saved_txt){
		// txt=_hyperlink(txt);
		// txt=txt.trim().nl2br();
		EXT.last_saved_txt=EXT.saved_txt;
		EXT.last_rendered_txt=txt;
	}
	return EXT.last_rendered_txt;
};



Image_ToolTip_EXT.prototype.get_note_w=function(){
	var EL=this.EL;
	var EXT=this;
	return _pi(EXT.innermost_div.style.width)+4;
};
Image_ToolTip_EXT.prototype.get_note_h=function(){
	var EL=this.EL;
	var EXT=this;
	return _pi(EXT.innermost_div.style.height)+4;
};
Image_ToolTip_EXT.prototype.get_note_x=function(){
	var EL=this.EL;
	var EXT=this;
	return _pi(EL.style.left)-1;
};
Image_ToolTip_EXT.prototype.get_note_y=function(){
	var EL=this.EL;
	var EXT=this;
	return _pi(EL.style.top)-1;
};




Image_ToolTip_EXT.prototype.onmouseover=function(){
	var EL=this.parentNode;
	var EXT=EL.EXT;

	EXT.isOver=1;
	EXT.change_display();
	EXT.papa.EXT.start_showing_one(EL);
};

Image_ToolTip_EXT.prototype.onmouseout=function(){
	var EL=this.parentNode;
	var EXT=EL.EXT;
	if(EL.id=="photo_note_temp"){
		return;
	}
	EXT.hide_timmy=setTimeout("_ge('"+EL.id+"').EXT.take_another_little_piece_of_my_heart('Image_ToolTip_EXT.prototype.onmouseout');",200);
};

Image_ToolTip_EXT.prototype.take_another_little_piece_of_my_heart=function(){
	var EL=this.EL;
	var EXT=this;

	EXT.isOver=0;
	EXT.change_display();
	EXT.papa.EXT.stop_showing_one();
};


Image_ToolTip_EXT.prototype.change_display=function(){
	var EL=this.EL;
	var EXT=this;
	// EXT.box_div.childNodes[0].style.borderStyle="solid";
	// EXT.box_div.childNodes[0].childNodes[0].style.borderStyle="solid";
	// EXT.box_div.style.left=EXT.box_div.style.top="0px";
	// EXT.box_div.style.borderWidth="0";

	if(EXT.isOver)
	{
		// EXT.box_div.style.left=EXT.box_div.style.top="-1px";
		// EXT.box_div.style.borderWidth="1px";
	}
	else
	{
		
	}
};


