/*
	cardtipex.js - card-reading-specific tooltip extensions for wz_tooltip.js
	
	for now this just has helper debug functions to learn how to use these hooks

	Extension eventhandlers currently supported:
	OnLoadConfig 
	OnCreateContentString 
	OnSubDivsCreated
	OnShow
	OnMoveBefore,
	OnMoveAfter
	OnHideInit
	OnHide
	OnKill
	
	and w'ere gonna hook 'em all as a test !
	and our first test verifies all the hooks are in place and work!
*/


function cardTipTest()
{
	alert("cardTipTest()!");
}

var cardTipEx = new tt_Extension();

cardTipEx.OnLoadConfig = function()
{	
//	updateDivs();// too soon to call 
}

var prizeFlag = [false,false];

cardTipEx.OnCreateContentString = function()
{
	for (i = 0; i < prizeFlag.length; i++)
	{
		if (prizeFlag[i] != false)
		{
			claimPrize(i);
			prizeFlag[i] = false;
		}
	}
//	updateDivs();
}

var scrollBarInComment = false;
var updateIframeSize = false;
var updateCustInterpsPopUp = false;

cardTipEx.OnSubDivsCreated = function()
{
	updateDivs();
}

/* 
	I think here is where we can modify the innerHTML of the tooltip to add the comment input form, comments, buttons, etc 
	after the tip has been created with empty divs for those objects 
	
	Actually the only one we need to modify is the comments div - if the height of the comments div exceeds the maximum size
	we're gonna allow, we need to change the div style element to autoscroll with the correct max dimensions. Otherwise
	we can leave it alone to display as-is.
*/	
function setTtScrollFocus()
{	
	document.getElementById("cOMMENTS").focus();
}

var ctrlId = "ifrm";
var idivId = "idiv";
var ciTitle = "ifrmTtl";
var ciTxt = "ifrmTxt";

function setTtIframeSize()
{
//	alert("bsdf bsdf bsdf");
	var hite = document.getElementById(ctrlId).contentWindow.document.body.scrollHeight;
	var wydth = document.getElementById(ctrlId).contentWindow.document.body.scrollWidth;
	
	
	if (setScrollIfExceeds(400, ctrlId))
	{
//		alert("There is no God but Allah and Mohammed is His prophet!");
		document.getElementById(ctrlId).height = 400;
	}
	else
		document.getElementById(ctrlId).height = hite;
	document.getElementById(ctrlId).width = wydth; 
//	document.getElementById(idivId).height = hite;
//	document.getElementById(idivId).width = wydth; 	
}
function setCustInterpsPopUpFocus(ciTxt)
{
	document.getElementById(ciTxt).focus();
//	alert("ciTxt = " + ciTxt);
}

function setCustInterpsPopUp()
{
//	alert("asdf asdf asdf");
//	var titlehite = document.getElementById(ciTitle).contentWindow.document.body.scrollHeight;
//	var titlewydth = document.getElementById(ciTitle).contentWindow.document.body.scrollWidth;
//	document.getElementById(ciTitle).height = titlehite;
//	document.getElementById(ciTitle).width = titlewydth; 
	
	var texthite = document.getElementById(ciTxt).contentWindow.document.body.scrollHeight;
	var textwydth = document.getElementById(ciTxt).contentWindow.document.body.scrollWidth;
	
//	alert("texthite = " + texthite + ", textwidth = " + textwydth + "old hite = " + document.getElementById(ciTxt).height + ", old width = " + document.getElementById(ciTxt).width);
//	document.getElementById(ciTitle).width = textwydth;

	if (texthite > 300)
	{
//		alert("texthite = " + texthite);
//		alert("Education is essential to ensure continuing new cadres of comrades conversant in the dialectic");
		size = '' + 300 + 'px';
		document.getElementById(ciTxt).style.overflow='auto';
		document.getElementById(ciTxt).style.height=size;
//		document.getElementById(ciTxt).height = 400;
		setTimeout('setCustInterpsPopUpFocus(ciTxt)', 100);
	}
	else
		document.getElementById(ciTxt).height = texthite;
	document.getElementById(ciTxt).width = textwydth; 
//	document.getElementById(ctrlId).style.height=texthite;
//	document.getElementById(ctrlId).style.width=textwydth;


//	alert("divs reset, titlehite = " + titlehite + ", titlewidth = " + titlewydth + ", texthite = " + texthite + ", textwidth = " + textwydth);
}

cardTipEx.OnShow = function()
{
	if (scrollBarInComment)
	{
		setTimeout('setTtScrollFocus()', 50);
		scrollBarInComment = false;
	}
	if (updateIframeSize)
	{
		setTimeout('setTtIframeSize()', 500);
		updateIframeSize = false;
	}
	if (updateCustInterpsPopUp)
	{
		setTimeout('setCustInterpsPopUp()', 500);
		updateCustInterpsPopUp = false;
	}
		
/*	updateDivs(); too late to call */
}

/* I think these are mouse move events, not tip move events */
cardTipEx.OnMoveBefore = function()
{
}

cardTipEx.OnMoveAfter = function()
{
}

cardTipEx.OnHideInit = function()
{
}

cardTipEx.OnHide = function()
{
}

cardTipEx.OnKill = function()
{
}


