$(document).ready(function(){
	
	enableTooltips();
	
	$("#client_list").find("img").fadeTo("0", 0.5).hover(function(e) {
		$(this).fadeTo("slow", 1);
		$("#btc").find("span.top").html(this.tooltip);
		$("#btc").show();
		Locate(e);
	
	},function(e) {
		$(this).fadeTo("0", 0.5)
		$("#btc").hide();
		
	
	}).each(function(i){Prepare(this);});
						
	if(typeof sIFR == "function" && !sIFR.UA.bIsIEMac){
		sIFR.setup();
		sIFR.replaceElement(named({sSelector:"body h2", sFlashSrc:"swf/mic_bold.swf", sColor:"#FFFFFF", sLinkColor:"#CCCC66", sBgColor:"#000000", sHoverColor:"#FFFFFF", nPaddingTop:0, nPaddingBottom:0, sCase:"upper", sWmode: "transparent", sFlashVars:"textalign=left&offsetleft=0"}));
	};						
});


/** bubble tool tips functions dsiplays title atribute on any element with class help-btn **/
function enableTooltips(){
	/*var links,i,h;
	links=$("#client_list").find("img");
	links.each(function(i){Prepare(this);});*/
}
/**
 * strips title attribute from help links and attches as a var to de isplayed in bubble tool tip
 * and sets mouse over/out events to hide show tool tip
 * 
 * @param {Object} el = dom element
 */
function Prepare(el){
	var tooltip,t,b,s,l;
	t=el.getAttribute("alt");
	if(t==null || t.length==0) {}else{ 
	el.removeAttribute("alt");
	tooltip=t;
	el.tooltip=tooltip;
	/*el.onmouseover=showTooltip;
	el.onmouseout=hideTooltip;*/
	el.onmousemove=Locate;
	/*el.mousemove(function(e) {
		Locate(e);
	});*/
}
}
/**
 * shows bubble tooltip and inserts title to display
 * 
 * @param {Object} e = dom element
 */
function showTooltip(e){
	$("#btc").find("span.top").html(this.tooltip);
	$("#btc").show();
	Locate(e);
}
/**
 * hides buble tooltip
 * 
 * @param {Object} e = dom element
 */
function hideTooltip(e){
	//$("#btc").find("span.top").html("");
	$("#btc").hide();
}
/**
 * Positions tooltip at mouse point
 * 
 * @param {Object} e = dom element (postitions tooltip at mouse piont)
 */
function Locate(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	if(e.pageX || e.pageY){
   		 posx=e.pageX; posy=e.pageY;
	} else if(e.clientX || e.clientY){
    		var doc_el = document.documentElement;
		var el_left = doc_el.scrollLeft;
		var el_top = doc_el.scrollTop;
		if(el_top){
			posx=e.clientX+el_left; posy=e.clientY+el_top; 
		} else{ 
			posx=e.clientX+document.body.scrollLeft; posy=e.clientY+document.body.scrollTop; 
		}	
   	 }
	var main_el = document.getElementById("btc");
	main_el.style.top=(posy+22)+"px";
	main_el.style.left=(posx-112)+"px";
}
/** end bubble tool tips functions **/
/** (g) postition overlay **/ 
/**
 * 
 * postitions overley in central postion on the viewport
 * 
 * @param {string} el_id = element id with hash (eg #options)
 * @param {num} TB_WIDTH = overlay width
 * @param {num} TB_HEIGHT = overlay height
 */
function TB_position(obj_id) {
	var TB_HEIGHT =$(obj_id).get(0).offsetHeight;
	var TB_WIDTH = $(obj_id).get(0).offsetWidth;
	
	var pagesize = getPageSize();
  	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
	var arrayPageScroll = getPageScrollTop();
	$(obj_id).css({width:TB_WIDTH+"px",left: (((pagesize[0] - TB_WIDTH)/2))+"px", top: (arrayPageScroll[1] + ((pagesize[1]-TB_HEIGHT)/2))+"px" });

	$("#overlay").css("height",yScroll +"px");
}

