
function displayBubble( ev, eId , wid, hei ){

	bubbleObj = $(eId);
	
	mouseX = (Event.pointerX(ev) + 20);
	mouseY = (Event.pointerY(ev) - 10);
	
	
	bubbleObj.style.left = mouseX+"px";
	bubbleObj.style.top = mouseY+"px";
	bubbleObj.style.width = wid;
	if( hei ){ bubbleObj.style.height = hei; }
	
	bubbleObj.style.visibility = "visible";
	
	//Disable all the select inputs
	//selObjs = new Form.getInputs("former1");
}

function killBubble( oid ){
	$(oid).style.visibility = "hidden";
}

showDoc = new Function("window.location = '/search.php?mode=view&action=view&id='+showDocId;");




/***************************************************/
/* Sponsor settings / functions */

sponsorCurrent = -1;
sponsorList = new Object();
sponsorTimer = false;
sponsorAjaxRequest = false;
sponsorData = new Object();

//Setup
function sponsorInit( ) {
	
	//Check to see if we have a container
	sponsorObj = $("sponsorCard");
	sponsorImg = $("sponsorImage");
	if( ! sponsorObj ) { return true; }
	if( ! sponsorImg ) { return true; }
	
	//check to see if we have any sponsors
	if( ! sponsorList[0] ) {return true; }
	
	//Assign actions
	sponsorObj.onmousedown = function() { sponsorDialogInit(); }
	
	//start sponsor
	sponsorNext();
	
	return true;
}


/***************************************************/
// show a new sponsor card
function sponsorNext() {
	
	//Determine our next card to show
	nextItem = ( typeof(sponsorList[(sponsorCurrent+1)]) != "object" ) ? 0 : (sponsorCurrent + 1);
	
	//save to global
	sponsorCurrent = nextItem;
	
	sponsorCache();
	
	return true;
	
}

/***************************************************/
function sponsorCache( ) {
	
	//Check to see if this id is already cached 
	if ( sponsorList[sponsorCurrent].cached == true ) {
		//Set height
		$("sponsorCard").style.height = sponsorList[sponsorCurrent].img.height+"px";
		$("sponsorImage").src = sponsorList[sponsorCurrent].img.src;
		$("sponsorImage").onload = function(){ sponsorShowCard(); }
		return true;
	}
	
	//Cache and load this sponsor
	//file=2.jpg&mode=thumb&thumb_mode=resize&thumb_height=300&thumb_width=210
	
	//Create new cache item
	sponsorList[sponsorCurrent].img = new Image();
	sponsorList[sponsorCurrent].img.onload = function(){ sponsorCacheDone(); }
	sponsorList[sponsorCurrent].img.src = sponsorImageUrl+"?file="+sponsorList[sponsorCurrent].id+"&mode=thumb&thumb_mode=resize&thumb_height=300&thumb_width=200";
	
	//return
	return true;
	
}



/***************************************************/
function sponsorCacheDone() {
	
	//Set as cached
	sponsorList[sponsorCurrent].cached = true;
	
	
	//set the image src for our page image
	//$("sponsorImage").onLoad = function(){ sponsorShowCard(); }
	//Set height
	$("sponsorCard").style.height = sponsorList[sponsorCurrent].img.height+"px";
	$("sponsorImage").src = sponsorList[sponsorCurrent].img.src;
	
	sponsorShowCard();
	
	return true;
}



/***************************************************/
//Finally show the business card with some animations
function sponsorShowCard() {
	//Effect.toggle("sponsorCard", "BLIND");
	//Effect.BlindDown("sponsorCard", {duration:0.5});
	
	//If there is only 1 sponsor.. set no timeout function
	if( sponsorList[1] ) {
		//start up timer for close
		effectOpts = "afterFinish:sponsorStartClose";
	} else{
		effectOpts = "";
	}

			
	//Close Card
	//eval("Effect.BlindDown('sponsorCard', {"+effectOpts+"});");
	//eval("new Effect.Grow('sponsorCard', {"+effectOpts+"});");
	eval("new Effect.Appear('sponsorCard', {"+effectOpts+"});");

}

/***************************************************/
// close the sponsor card
function sponsorCloseCard() {
	
	clearTimeout(sponsorTimer);
	
	if( ! $("sponsorCard") ) {
		return true;
	}
	
	
	//Assign done effect function
	effectFinishFunc = new Function("sponsorNext()");

	effectOpts = "afterFinish:effectFinishFunc";
			
	//Close Card
	//eval("new Effect.Fade('sponsorCard', {"+effectOpts+"});");
	//eval("new Effect.BlindUp('sponsorCard', {"+effectOpts+"});");
	//eval("new Effect.SlideUp('sponsorCard', {"+effectOpts+"});");
	eval("new Effect.Fade('sponsorCard', {"+effectOpts+"});");
	//eval("new Effect.DropOut('sponsorCard', {"+effectOpts+"});");

}


/***************************************************/
// start the close timer for the card
function sponsorStartClose() {

	//Kill timer just in case
	clearTimeout(sponsorTimer);
	
	sponsorTimer = window.setTimeout("sponsorCloseCard();", sponsorDisplayTime);	
}





/***************************************************/
// Show a sponsor details in dialog
function sponsorDialogInit() {
	
	//Close it if it is open
	//sponsorDialogClose();
	Element.hide("sponsorDialog");
	
	//Get the current global sponsor
	sponsorId = sponsorList[sponsorCurrent].id;
	
	//Make AJAX request
	sponsorAjaxRequest = new Ajax.Updater("", sponsorDialogDataUrl+"?id="+sponsorId, {
		onFailure: new Function("alert('Failed loading sponsor data');"),
		onComplete: new Function("sponsorAjaxRequest.transport.responseText.evalScripts();"),
		requestHeaders : ["Connection", "keep-alive"], // Change the connection header to a keep-alive
		evalScripts:true, 
		asynchronous:true
	});
	
	//populate dialog
}


/***************************************************/
// dialog data has been loaded
function sponsorDialogLoaded() {

	
	$("sponsorDialog").style.height = "300px";
	$("sponsorDialog").style.height = "auto";

	//Populate the dialog with the Ajax data
	Element.update("sponsorDialogName", sponsorData.name);
	Element.update("sponsorDialogEmail", sponsorData.email);
	Element.update("sponsorDialogDesc", sponsorData.desc);
	Element.update("sponsorDialogAddress", sponsorData.address);
	Element.update("sponsorDialogPhone", sponsorData.phone);
	Element.update("sponsorDialogUrl", sponsorData.url);

	$("sponsorDialogEmail").href = "mailto:"+sponsorData.email+"";
	$("sponsorDialogUrl").href = sponsorData.url;
	
	//Set the dialog image stuff
	$("sponsorDialogImage").onload = function(){ sponsorDialogShow(); }
	$("sponsorDialogImage").src = sponsorImageUrl+"?file="+sponsorData.id+"&mode=thumb&thumb_mode=resize&thumb_height=500&thumb_width=430";


}


/***************************************************/
// Finally show the populated dialog once the image has loaded
function sponsorDialogShow(){
	Effect.toggle("sponsorDialog", "BLIND");
}


/***************************************************/
// Finally show the populated dialog once the image has loaded
function sponsorDialogClose(){
	
	//Hide the dialog
	Element.hide("sponsorDialog");
	
	$("sponsorDialogImage").onload = "";
	$("sponsorDialogImage").src = "";
	
}

