loadScript('http://js.localpages.com/tagcloud/js/jquery-1.3.2.min.js', loadNextScript);
//

function loadScript(url, callback){
    var head = document.getElementsByTagName("head")[0];
    addLater = false;
    if(!head){
	head = document.createElement("head");
	addLater = true;
    }
    var script = document.createElement("script");
	script.src = url;
    script.type = "text/javascript";
    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){			
            callback();
        };
    }
 	head.appendChild(script);
    if(addLater){
		document.documentElement.appendChild(head);
    }
}
function loadNextScript(){
	loadScript('http://js.localpages.com/tagcloud/js/jquery.xhr.js', function(){});
	loadScript('http://js.localpages.com/tagcloud/js/flXHR.js', function() {});
	setTimeout( function() {loadScript('http://js.localpages.com/tagcloud/js/jquery.proxy.js', function(){})}, 200);
	setTimeout( function() {loadScript('http://js.localpages.com/tagcloud/js/jquery.qtip.js', makeTags)},500);
}
function makeTags(){
    var pageData = document.body.innerHTML;
    var jcount=0;    document.body.innerHTML = pageData;
    setTimeout("LoadAjax();",100);
}
var keyword_array = new Array();
function LoadAjax(){
	LoadCSS();
	jQuery.flXHRproxy.registerOptions("http://js.localpages.com/",{xmlResponseText:false});
	jQuery.ajaxSetup({transport:'flXHRproxy'});
   $('#tagcloud a').each(function()
   {
	   	linkid = $(this).attr('count');
		keyword = $(this).attr('value');
		keyword_array[linkid] = keyword;

		// Setup the tooltip with the content
		$(this).qtip(
		{
			content: {text: ''},
position: {
corner: {
  target: 'bottomLeft',
  tooltip: 'topLeft'
}
},
show: {
solo: true
},
hide: {
when: 'inactive',
delay: 6000,
effect: {
type: 'fade',
length: 300
}
},		
api: {
  beforeShow: function(e){setTransparent(e); return true; },
  onShow: function(e){ adjustForPosition(e); return true; },
  onHide: function(e){ clearContent(e); return true; }
},
style: 'mystyle'
   		});
	});
}
var gid;
function clearContent(obj){
    if(typeof(obj) == "object"){
        var eid = obj.target.id + "";
        if(eid){
            var tobj = $("#" + eid);
            tobj.qtip('api').updateContent('<div id="filler_'+eid+'"></div>');
        }
    }
}
function setTransparent(obj){
    if(typeof(obj) == "object"){
        var eid = obj.target.id + "";
        if(eid){
            var tobj = $("#" + eid);
            var cont = tobj.qtip('api').elements.tooltip;
            var divs = cont[0].getElementsByTagName("div");
            for(var idx in divs){
                cObj = divs[idx];
                if(cObj.className == "qtip-contentWrapper"){
                    cObj.style.backgroundColor = "transparent";
                    break;
                }
            }
        }
    }
}
function adjustForPosition(obj){
    var eid = obj.target.id;
    var tobj = $("#" + eid);
    var cont = tobj.qtip('api').elements.tooltip;
    var divs = cont[0].getElementsByTagName("div");
    for(var idx in divs){
        cObj = divs[idx];
        if(cObj.className == "qtip-contentWrapper"){
            cObj.style.backgroundColor = "transparent";
            break;
        }
    }
    lobj = document.getElementById(eid);
    tx = 0;
    ty = 0;
    tObj = lobj;
    do {
        tx += tObj.offsetLeft;
        ty += tObj.offsetTop;
    } while (tObj = tObj.offsetParent);
    th = tobj.outerHeight();
    tw = tobj.outerWidth();
    sl = f_scrollLeft();
    st = f_scrollTop();
    sw = f_clientWidth();
    sh = f_clientHeight();
    roomLeft = (tx + tw) - sl;
    roomRight = (sw  + sl) - tx;
    roomTop = ty - st;
    roomBottom = (sh + st) - (ty + th);
    var hpos = "left";
    var vpos = "bot";
    var tpos = "top";
    var ttip = "bottom";
    if(roomLeft > roomRight){
        hpos = "right";
    }
    var loading_margin = 8;
    var top_margin = 'margin-top: 154px;'
    if(roomBottom > roomTop){
        vpos = "top";
        loading_margin = 18;
        top_margin = "";
        tpos = "bottom";
        ttip = "top";
    }
    tobj.qtip('api').options.position.corner.tooltip = ttip + hpos;
    tobj.qtip('api').options.position.corner.target  = tpos + hpos;
    link_id = eid.substr(4);
    keyword = keyword_array[link_id];
    tobj.qtip('api').updateContent('<div style="width:328px; height:40px;background-image: url(http://inline.localpages.com/images/localpages_bar_' + vpos + hpos + '.gif);background-repeat: no-repeat;' + top_margin + '" id="wait_' + linkid + '"><div style="float:left; width: 117px; height: 12px; margin: ' + loading_margin + 'px 0px 0px 100px; background-image: url(http://inline.localpages.com/images/loading.gif); background-repeat: no-repeat;"></div> <a href="http://www.localpages.com/" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #ffab31; float: right; margin: ' + (loading_margin-1) + 'px 12px 0px 0px; outline: none;">Advertise with Us</a> </div>',false);
    tobj.qtip('api').updatePosition();
    var il_url = 'http://js.localpages.com/banner.php?id=PT8pOg&search='+keyword+'&ip=38.107.191.115&subid=[ncl]&ua=CCBot%2F1.0+%28%2Bhttp%3A%2F%2Fwww.commoncrawl.org%2Fbot.html%29&type=inline&style=1&link='+linkid+'&vp='+vpos+'&hp='+hpos;
    tobj.qtip('api').loadContent(il_url,"","GET");
    return true;
}
function LoadCSS(){
    $.fn.qtip.styles.mystyle = { // Last part is the name of the style
   width: 338,
   height: 194,
   border: {
      width: 0,
      radius: 0
   },
   'background-color': 'transparent'
	}
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement && !document.body ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function handleError() { 
	window.parent.location=location 
} 





