/**
 *  @package yahoo.search.answers
 *	@author walter punsapy
 **/
jOnline.namespace('search.answers');
jOnline.search.answers = {
     cache : {
        data : {
        },
        setData : function(key, value){
            this.data[key] = value;
        },
        getData : function(key){
            return this.data[key];
        }
    },
	util : {
		isNull : function(pEle) {
			//
		},
		oSearchOptionMenu : {
			_oMenu : null,
			isOpen : false,
			_FORM_ELEMENT_ID : "ks-inline-search",
			_ELEMENT_OPTIONS_ID : "ks-inline-search-options",
			_ELEMENT_CLICK_FOR_OPTIONS_ID : "ks-inline-search-click-for-options",
			init : function(pIntl,pNodeToAppendTo) {
				var _intl = pIntl || "us";
				var _node_to_attach_to = pNodeToAppendTo || document.body;
				var _aMenuItemData = [
					{ text: "jOnline! Search", config: { url:"javascript:void(0);" }, elementId : "option-jOnline-search", icoClassName : "ico-jOnline" },
	                { text: "Wikipedia", config: { url:"javascript:void(0);" }, elementId : "option-wikipedia-search", icoClassName : "ico-wikipedia" }
				];
				var oMenuItem = null;
				var nMenuItems = _aMenuItemData.length;
				try {
					_oMenu = new jOnline.widget.Menu(jOnline.search.answers.util.oSearchOptionMenu._ELEMENT_OPTIONS_ID);
					for (var i=0; i<nMenuItems; i++) {
		            	oMenuItem = new jOnline.widget.MenuItem(_aMenuItemData[i].text,_aMenuItemData[i].config);
		            	oMenuItem.element.id = _aMenuItemData[i].elementId;
		            	oMenuItem.clickEvent.subscribe(jOnline.search.answers.util.oSearchOptionMenu.toggle,_aMenuItemData[i].icoClassName);
						_oMenu.addItem(oMenuItem);
					}
					_oMenu.render(_node_to_attach_to);
					jOnline.util.Event.addListener(
						jOnline.search.answers.util.oSearchOptionMenu._ELEMENT_CLICK_FOR_OPTIONS_ID,
						"click",
						function(){ jOnline.search.answers.util.oSearchOptionMenu.open(); }
					);
				}
				catch(e) {

				}
				finally {
					oMenuItem = null;
					_aMenuItemData = null;
					_node_to_attach_to = null;
				}
			},
			toggle : function(pType, pArguments, pClassName) { //subscribe event always returns Event, Event Arguments and additional args[]
				var _ele = document.getElementById(jOnline.search.answers.util.oSearchOptionMenu._ELEMENT_CLICK_FOR_OPTIONS_ID); //options-selector
				var _form = document.getElementById(jOnline.search.answers.util.oSearchOptionMenu._FORM_ELEMENT_ID);
				try {
					if (null != _ele && "undefined" != _ele) {
						_ele.className = "options-selector " + pClassName;
					}
					var _ele_hidden_id = pClassName + "-search-value";
					var _ele_hidden = document.getElementById(_ele_hidden_id);
					if (null != _ele_hidden && "undefined" != _ele_hidden && null != _form && "undefined" != _form) {
						_form.action = _ele_hidden.value;
					}
				}
				catch(e) { }
				finally {
					_ele = null;
					_form = null;
				}
			},
			open : function() {
				try {
					_oMenu.show();
					setTimeout(function() { jOnline.util.Event.addListener(document.body, "click", function(){ jOnline.search.answers.util.oSearchOptionMenu.close(); }) },600);
				}
				catch(e) { }
			},
			close : function() {
				try {
					_oMenu.hide();
					var bRemoved = jOnline.util.Event.purgeElement(document.body, false, "click");
				}
				catch(e) { }
				finally { }
			},
			openTargetWindow : function() {
				var _form_id = jOnline.search.answers.util.oSearchOptionMenu._FORM_ELEMENT_ID;
				var _form_obj = document.getElementById(_form_id);
    			var _window_name = _form_id + (new Date().getTime().toString());
    			_form_obj.target = _window_name;
    			try {
    				window.open('', _window_name, 'width=750,height=450,resizable=1,scrollbars=1,location=yes,menubar,status, scrollbar, directories, toolbar');
				}
				catch(e) {

				}
				finally {
					_form_id = null;
					_form_obj = null;
					_window_name = null;
				}
			}
		},
		setCursor : function(pStr) {
			document.body.style.cursor = pStr;
		},
		setDocumentTitle : function(pStr) {
			document.title = pStr;
		},
		isNull : function(pEle) {
		    return (null==pEle || "undefined"==pEle || ""==pEle);
		},

		ERROR_NOTICE : { key : "8", value : "notice" },
		ERROR_INFO :   { key : "4", value : "info"   },
		ERROR_WARN :   { key : "2", value : "warn"   },
		ERROR_ERROR :  { key : "1", value : "error"  },

		debug : function(pStr,pLevel) {
			jOnline.search.answers.debug(pStr,pLevel);
		},

		$ : function() {
			var elements=[];
			for (var i=0; i < arguments.length; i++) {
				var e = arguments[i];
				if (typeof e == 'string') e = document.getElementById(e);
				if (arguments.length == 1) return e;
				elements.push(e);
			}
			return elements;
		},

		Ajax : {
			connection : null,
			getInstance : function() { // DEP: ygConn 1.1.3
				if (!ygConn) return null;
				if (null == this.connection) {
					this.connection = ygConn.getObject();
				}
				return this.connection;
			},
			// use YUI Connection Manager 2.0
			request : function(pUrl, pCallback, pFormMethodType) {
				var _formType = pFormMethodType || 'GET';
				try {
					jOnline.util.Connect.asyncRequest(_formType, pUrl, pCallback);
				}
				catch(e) {
					//TODO
				}
			}
		}
	},
	debug : function(pStr,pLevel) {
		if (Util) Util.debug(pStr,pLevel); // TODO: must be rewritten
	},
	eggs : {
		CONTRA_CODE_INIT : "rbaS"
	},
	translations: {
		SPELLCHECKER_ERROR : 'Oops, o corretor ortográfico está com problemas, tente novamente.'
	}
}

/* Util object that we use to do stuff
 ***************************************************** */

function KS_Util(pId,pBrowserObj,pIsDebug,pKid,pKNickname){
    this.id=pId;
    this.kid=(!this.isNull(pKid)) ? pKid : null;
    this.nick=(!this.isNull(pKNickname)) ? pKNickname : null;
    this.ua=(!this.isNull(pBrowserObj)) ? pBrowserObj : new yg_Browser();
    this.DATATYPE_OBJECT="object";
    this.OFFSET_BODY_HEIGHT=100;
    this.EXCEPTION_STRING="EXCEPTION";

    this.IS_JAVASCRIPT_DEBUG=pIsDebug||false;
}

KS_Util.prototype.highlightWords = function(pStr,pResponseText) {
    this.highlight_tag = "strong";
    var tmpStr = String.trim(pStr);
    var tmpArr = tmpStr.split(' ');
    if (tmpArr.length > 0) {
        for (var ii=0; ii< tmpArr.length; ii++) {
            var p = new RegExp (tmpArr[ii],'ig');
            pResponseText = pResponseText.replace(p,"<" + this.highlight_tag + ">"+tmpArr[ii]+"</" + this.highlight_tag + ">");
        }
    }
    return pResponseText;
}


/**
 *  @returns boolean
 *  @description returns whether the string has 'n' words, delimiting by space
 */
KS_Util.prototype.isNthWord = function(pStr) {
    var tmpStr = String.trim(pStr);
    if (tmpStr.length > 0) {
        var tmpArr = tmpStr.split(' ');
        if ((tmpArr.length > (NTH_WORD_INDEX - 1)) && "" != tmpArr[NTH_WORD_INDEX - 1]) return true;
    }
    return false;
}

KS_Util.prototype.isNull=function(pEle){
    return (null==pEle || "undefined"==pEle || ""==pEle);
}

 /**
  * @function gObj - returns a reference to an element
  * @param pObj - string or object
  * @returns - reference to the document node or NULL
  */
KS_Util.prototype.gObj=function(pObj){
    var tmp=null;
    if (document.getElementById) {
        tmp = (typeof pObj==this.DATATYPE_OBJECT) ? pObj : document.getElementById(pObj);
    }
    else if (document.all) {
        tmp = (typeof pObj==this.DATATYPE_OBJECT) ? pObj : document.all[pObj];
    }
    if (!this.isNull(tmp)) {
        return tmp;
    }
    return null;
}

KS_Util.prototype.setDocumentTitle=function(pStr) {
    var tmpTitle=document.title;
    document.title = tmpTitle + " - " + pStr;
}

KS_Util.prototype.debug=function(pStr,pLevel) {
    //if (this.IS_JAVASCRIPT_DEBUG && "string" == typeof pStr) {
    	/*
        var d = this.gObj(this.DEBUG_CONSOLE);
        var parent_function = arguments.caller;
        var current_function = arguments.callee;
        if (pStr.indexOf(this.EXCEPTION_STRING) != -1) pStr = "<span style=\"background-color:red;color:#f9f8f4;\">" + pStr + "</span>";
        if (null!=d) {
            var tmpStr = d.innerHTML;
            d.innerHTML = tmpStr + ((tmpStr.length > 5) ? "<br/>" : "") + "&gt; " + pStr;
        }
        */
        if (null==pLevel || ""==pLevel || !typeof pLevel=="string") pLevel = "info";
        try {
	        jOnline.log(pStr,pLevel);
    	}
    	catch(e) {
    		//alert("error: " + e.message);
    	}
    //}
}

KS_Util.prototype.writeWidgetMessage=function(pPt) {
	var s="";
	if (pPt < 0) s +='<span style="">Alerta</span>';
	else if (pPt == 0) s +='<span style="">Alerta</span>';
	else if (pPt > 0) s +='<span style="color:#52be0a">Obrigado!</span>';
	else s +='<span style="">Alerta</span>';
	return s;
}


KS_Util.prototype.doAggregateIncentiveEvents=function(pIncentiveArray) {
	var _ele = this.gObj(this.current_widget_display);
	if (null == _ele || ""==_ele || "undefined"==_ele) return;
    var incentiveArray = pIncentiveArray;
    var c_events = incentiveArray.length;
    var s='';
    var isDisplayed = true;
    var hasNoSystemEvents = false;
    if (c_events <= 0) {
        /*
        if (!this.isNull(this.kid)) {
            hasNoSystemEvents = true;
            var random = Math.floor(Math.random() * 10);
            Util.debug("random number: " + random);
            if (random == 3 && null != this.nick) {
                s += '<span class="alert">Oi <a href="/my/my">' + this.nick + '</a>! Verifique suas <a href="/my/my?link=question&more=y">perguntas</a> para escolher a melhor resposta</span>';
            }
            else {
                isDisplayed = false;
            }
        }
        */
    }
    else {
        // begin parsing system events
       	s += '<table style="height:50px;" cellpadding="0" cellspacing="0" border="0"><tr>';
        // for EVENT #23, tell em this message
        if (parseInt(incentiveArray[0].getOid()) == 23) {
			s += '<td style="width:60px; height:50px; vertical-align:middle; text-align:center;"><img src="/img/medal.gif" vspace="12" style="border:none;" /></td>';
        	// alert user of questions that need attn
            var tmpUrl = "/my/my?link=question&more=y";
            s += '<td style="height:50px; vertical-align:middle; text-align:center;"><span class="new"><strong>Algumas das <a href="' + tmpUrl + '">suas perguntas</a> precisam de atenção!</strong></span></td>';
        }
        else {
	       	s += '<td style="width:60px; height:50px; vertical-align:middle; text-align:center;"><img src="/img/medal.gif" vspace="12" style="border:none;" /></td>';

            if (1 == c_events) {
            	var obj = incentiveArray[0];
	            s += '<td style="height:50px; vertical-align:middle;"><strong style="margin-top:12px; font-size:115%;">'+this.writeWidgetMessage(parseInt(obj.getPoints()))+'</strong><br/>';
                //s += 'You\'ve earned '+ obj.getPoints() +' point'+( (parseInt(obj.getPoints()) > 0) ? "s" : "") +' for ';
                var msgStr = this.DISPLAY_WIDGET_NOTIFICATION_STATES[parseInt(obj.getOid())];
				//strip out any point info in the string, lame
				msgStr = msgStr.replace(msgStr.substring(msgStr.lastIndexOf("("), msgStr.length), "");
				s += msgStr;
				//append the correct point data to the string
				pointStr = (parseInt(obj.getPoints()) == 1) ? "ponto" : "pontos";
				pointStr = " (" + obj.getPoints() + "&nbsp;" + pointStr + ")";
				s += pointStr;
            }
            else { // multiple points
                var count=0;
                s += '<td style="height:50px; vertical-align:middle;">';
                for (var ce=0; ce < c_events; ce++) {
                    var obj = incentiveArray[ce];
                    if (parseInt(obj.getOid()) == 23) continue;
                    this.debug('Util.doAggregateIncentiveEvents() in loop, print string ' + s);
                    var obj = incentiveArray[ce];
                    count += parseInt(obj.getPoints());
                }
                if (count >= 0) {
					s += '<strong style="margin-top:12px; font-size:115%;">Nossa!</strong><br/>';
                	s += "Você ganhou <strong>"+ count + "</strong> pontos!";
                	s +=' </span>';//need the space for aesthetic reasons
                } else {
					s += '<strong style="margin-top:12px; font-size:115%;">Alerta</strong><br/>';
					var _num = (count * -1);
                	s += "Você perdeu <strong>" + _num + "</strong> pontos!";
                	s +=' </span>';//need the space for aesthetic reasons
                }
            }
            s += '</td>';
        }
        s+= '</tr></table>';
    }
    // s+= (c_events > 1 && !hasNoSystemEvents && isDisplayed) ? '<br/><span style="padding-left:18px;"><a href="/info/scoring_system.php">Saiba mais</a></span>' : '';

    var self=this;
    if (isDisplayed && s.length > 0) {
        self.doReplaceWidgetDisplay(s);
        setTimeout(function(){ self.doReplaceWidgetDisplay(null) } , 10000);
    }
}

// toggle btwn 1 + 2
KS_Util.prototype.doReplaceWidgetDisplay=function(pMsg) {
    this.fadeElement(this.gObj(this.current_widget_display),false);
    this.current_widget_display=(this.DISPLAY_WIDGET_1==this.current_widget_display) ? this.DISPLAY_WIDGET_2 : this.DISPLAY_WIDGET_1;
    this.fadeElement(this.gObj(this.current_widget_display),true,pMsg);
    var z = parseInt(this.gObj(this.current_widget_display).style.zIndex);
    this.gObj(this.current_widget_display).style.zIndex=(z+2);
}

KS_Util.prototype.fadeElement=function(pEle,pFadeVisible,pMsg) {
     var ele = Util.gObj(pEle);
     if (null!=pMsg && ""!=pMsg) ele.innerHTML = pMsg;
     var oAnim=null;
     if (pFadeVisible) {
   	 	oAnim = new jOnline.util.Anim(pEle, { opacity: { to: 1, from : 0 } }, 1.9, jOnline.util.Easing.easeNone);
	 }
	 else { //hidden
   	 	oAnim = new jOnline.util.Anim(pEle, { opacity: { to: 0, from : 1 } }, 1.9, jOnline.util.Easing.easeNone);
	 }
	 // jOnline.util.Event.on(document, 'click', oAnim.animate, anim, true);

     //if (pFadeVisible) oAnim.onStart = function() {
     ele.style.visibility = 'visible';
     oAnim.animate();
     return false;
}

/**
 * @function gObj - set display style
 * @param pObj - string or object
 */
KS_Util.prototype.sDisplay=function(pObj,pBool) {
    this.gObj(pObj).style.display = (pBool) ? "block" : "none";
}

/** redirect the user to a fully qualified URL
  * @param pUrl - URL
  */
KS_Util.prototype.sendRedirect=function(pUrl) {
    parent.location.href = pUrl;
}

KS_Util.prototype.setWindowStatus=function(pStr) {
    if (pStr) window.status = pStr;
}

KS_Util.prototype.doFocusOnLoginBox=function() {
    var f=document.login_form;
    if (f) {
       if (f.username && f.username.value=="") f.username.focus();
       else if (f.passwd && f.passwd.value=="") f.passwd.focus();
    }
    return;
}

KS_Util.prototype.openTargetWindow = function(form, features, windowName) {
    if (!windowName) windowName = 'formTarget' + (new Date().getTime().toString());
    form.target = windowName;
    window.open ('', windowName, features);
}


KS_Util.prototype.fixFooter=function() {
	var l = this.gObj("left");
	var m = this.gObj("middle");
	var r = this.gObj("right");
	if (null == m) m = this.gObj('middle-center'); //if different layout
	if (null == m) m = this.gObj('just-middle'); //if different layout
    if (null == m) m = this.gObj('just-middle'); //if different layout again
	if (null != l && null != m && null != r) {
		var maxH = l.offsetHeight;
		if(r.offsetHeight > maxH) maxH = r.offsetHeight;
		if(maxH > m.offsetHeight) m.style.height = (maxH + this.OFFSET_BODY_HEIGHT)+"px";
    }
    else if (null != l && null != m && null==r) {
		var maxH = l.offsetHeight;
		if(maxH > m.offsetHeight) m.style.height = (maxH + this.OFFSET_BODY_HEIGHT)+"px";
    }
}

KS_Util.prototype.init=function() {
    //this.fixFooter();
    if (this.IS_JAVASCRIPT_DEBUG) {
        this.gObj(this.DEBUG_CONSOLE).style.visibility="visible";
        this.gObj(this.DEBUG_CONSOLE).style.display="block";
    }
    //if (!this.isNull(gPageTitle)) this.setDocumentTitle(gPageTitle);
    this.doAggregateIncentiveEvents(aIncentiveArray);
    this.doFocusOnLoginBox();
    hasWindowLoaded = true;
}

KS_Util.prototype.getRadioValue = function(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(!radioLength || radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for (var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return null;
}

KS_Util.prototype.highlightElement = function (id, fps, duration, from, to)
{
	Fat.fade_element(id,fps,duration,from,to);
}

/** Use this to add an event to an object unobtrusively
 *  @param - obj: Object to add event to (i.e. window)
 *  @param - evType: Event type (i.e. 'load')
 *  @param - fn:Function to be called when event occurs
 */
KS_Util.prototype.addEvent = function (obj, evType, fn){
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    }
    else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
    else {
        return false;
    }
}

/** Use this for displaying validation info to the user on the client side.
  * This function assumes that the form label and place for more information
  * are called inputIdLabel and inputIdHelp respectively.
  *
  * @param inputId: id of the input being evaluated
  * @param helpString: string to display for the user
  * @param show: boolean, show or hide the error and help string
  */
KS_Util.prototype.displayErrorInfo = function(inputId, helpString, show) {
    try {
        var helpString = helpString;
        var inputLabel = this.gObj(inputId+"Label"); //Main info label, will turn red
        var inputHelp = this.gObj(inputId+"Help"); //Place to put additional information in red
        var inputContainer = this.gObj(inputId+"Container"); //Place to put additional information in red
        if(show) {
                this.debug("error message to be displayed, input ID: " + inputId);
                if(inputLabel != null && inputLabel.className.indexOf("error") < 0) {
                        this.debug("Label to be set as error: "+inputLabel.id);
                        inputLabel.className = inputLabel.className + " error";
                }
                if(inputHelp != null) {
                        this.debug("Help content to be set as error: "+inputHelp.id);
                        inputHelp.className = inputHelp.className + " error";
                        inputHelp.innerHTML = helpString;
                }
		if(inputContainer != null) {
			this.debug("Changing container style: "+inputContainer.id);
			inputContainer.className = inputContainer.className + " error-container";
		}
        } else {
                this.debug("no errors, let's reinstate the element, input ID: " + inputId);
                if(inputLabel != null) {
                        inputLabel.className = inputLabel.className.replace("error", "");
                }
                if(inputHelp != null) {
                        inputHelp.className = inputHelp.className.replace("error", "");
                        inputHelp.innerHTML = "";
                }
                if(inputContainer != null) {
                        inputContainer.className = inputContainer.className.replace("error-container", "");
                }
        }
    }
    catch(e) {
        this.debug(e.message);
    }
    return;
}


/**
 * Perform an asynchronous call to the server using the ygConn library
 * Requires ygConnect library to be included on page.
 * @url : The url of the server side script where the action is to take place
 * @method: GET or POST. Default is GET.
 * @cF  : Callback Function - Called upon server side script completion
 * @argArr : An array of arguments to be passed to the callback function
 * @respIsXml : Boolean indicating a plain-text(false) or XML response(true).
 * @form : String indicating name of form to POST to server.  If none, set to null.
 */
KS_Util.prototype.ajaxCall = function (url, method, cF, argArr, respIsXml, form) {
	if(ygConn) {
		var obj = ygConn.getObject();
		var m = method;
		if(m == null || (m != "POST" && m!= "GET")) { m = "GET" };
		if(form != null && form.length > 0) {
			ygConn.http.setForm(form);
			m = "POST";
		}

		if(cF == null) {
			cF = this.defaultAjaxHandler;
		}
		ygConn.http.asyncRequest(obj, m, url, respIsXml, cF, argArr, null);
	}
}

/**
 * Default AJAX response handler.  Just inserts html into div identified in first parameter.
 * (This should probably never be used, but might be convenient in some cases.)
 */
KS_Util.prototype.defaultAjaxHandler = function() {
	rsp  = arguments[0]; //Response text/html | or error
	tid  = arguments[1]; //Transaction id
	args = arguments[2]; //Arguments, if any, created during initial ajax call

	//Was there an error?  (true if arguments[1] and arguments[2] are null)
	if(tid == null && args == null) {
			return false;
	}

	//args[0] is the id of the element where rsp.responseText will be inserted into
	if(args != null && args[0] != null) {
		dest = this.gObj(args[0]);
		if(dest != null) {
				dest.innerHTML = rsp.responseText;
		}
	}
}

KS_Util.prototype.evalJson = function(jsonString) {
	return eval('(' + jsonString + ')');
}

var oAnswers = jOnline.search.answers;

jOnline.search.answers.cache.setData('boaItemCount', 5);
jOnline.search.answers.cache.setData('currBoaIndex', 0);
jOnline.search.answers.cache.setData('boaTimerState', 1);
jOnline.search.answers.cache.setData('boaAnimating', false);
function displayFeaturedItem(index, forward) {
	currBoaIndex = jOnline.search.answers.cache.getData('currBoaIndex');
	animating = jOnline.search.answers.cache.getData('boaAnimating');
	if(index != currBoaIndex && !animating) {
		jOnline.search.answers.cache.setData('boaAnimating', true);
		if(forward == null) {
			forward = (index - currBoaIndex > 0);
		}

		boaContent = Util.gObj("boa-content");
		currItem = Util.gObj("fc-"+currBoaIndex);
		newItem = Util.gObj("fc-"+index);

		jOnline.util.Dom.setStyle(newItem, 'position', 'absolute');

		startPos = 460;
		if(!forward) {
			startPos *= -1;
		}
		jOnline.util.Dom.setStyle(newItem, 'left', startPos+'px');
		jOnline.util.Dom.setStyle(newItem, 'display', 'block');

		if(boaContent && currItem && newItem) {

			var finishFade = function() {
				var el = this.getEl();
				jOnline.util.Dom.setStyle(el, 'display', 'none');
				jOnline.util.Dom.setStyle(el, 'opacity', 1);
				jOnline.search.answers.cache.setData('boaAnimating', false);
			}

			jOnline.util.Dom.setStyle(currItem, 'opacity', 1);
			jOnline.util.Dom.setStyle(currItem, 'background-color', '#191919');
			var fadeAnim = new jOnline.util.Anim(currItem, { opacity: { to: 0 }}, 0.6, jOnline.util.Easing.easeOut);
			fadeAnim.onComplete.subscribe(finishFade);
			fadeAnim.animate();
			var flyAnim = new jOnline.util.Anim(newItem, { left: { from: startPos, to: 0 } }, 0.5, jOnline.util.Easing.easeBoth);
			flyAnim.animate();

			jOnline.search.answers.cache.setData('currBoaIndex', index);
			itemCount = jOnline.search.answers.cache.getData('boaItemCount');
			for(i = 0 ; i < itemCount ; i++) {
				p = Util.gObj("bp-"+i);
				if(i != index) {
					p.className = '';
				} else {
					p.className = 'active';
				}
			}
			updateBoaAttributes(index);
			resetBoaTimer();
		}
	}
}

function updateBoaAttributes(index) {
	var newTitle = Util.gObj("fc-title-"+index);
	if(newTitle) {
		var title = Util.gObj("boa-title");
		title.innerHTML = newTitle.value;
	}
}

function previousFeaturedItem() {
	currBoaIndex = jOnline.search.answers.cache.getData('currBoaIndex');
	itemCount = jOnline.search.answers.cache.getData('boaItemCount');
	if(currBoaIndex > 0) {
		displayFeaturedItem(currBoaIndex - 1, false);
	} else {
		displayFeaturedItem(itemCount - 1, false);
	}
}

function nextFeaturedItem() {
	currBoaIndex = jOnline.search.answers.cache.getData('currBoaIndex');
	itemCount = jOnline.search.answers.cache.getData('boaItemCount');
	if(currBoaIndex < itemCount - 1) {
		displayFeaturedItem(currBoaIndex + 1, true);
	} else {
		displayFeaturedItem(0, true);
	}
}

function startBoaTimer() {
	stopBoaTimer();
	timer = setTimeout("nextFeaturedItem()", 15000);
	jOnline.search.answers.cache.setData('boaTimer', timer);
	jOnline.search.answers.cache.setData('boaTimerState', 1);
}

function stopBoaTimer() {
	timer = jOnline.search.answers.cache.getData('boaTimer');
	if(timer) {
		clearTimeout(timer);
	}
	jOnline.search.answers.cache.setData('boaTimerState', 0);
}

function resetBoaTimer() {
	boaTimerState = jOnline.search.answers.cache.getData('boaTimerState');
	if(boaTimerState) {
		stopBoaTimer();
		startBoaTimer();
	}
}

function toggleBoaTimer() {
	boaTimerState = jOnline.search.answers.cache.getData('boaTimerState');
	button = Util.gObj('ctrl-pause');
	if(boaTimerState) {
		button.className = "play";
		stopBoaTimer();
	} else {
		button.className = "pause";
		startBoaTimer();
	}
}


