/**
 *  @package yahoo.search.answers
 *	@author  walter punsapy
 **/
YAHOO.namespace('search.answers');
YAHOO.search.answers = {
	application : {
		config : {
			IS_SEARCH_AHEAD_ENABLED : true,
			IS_SPELLCHECK_ENABLED   : true,
			IS_SPELLCHECK_RUNNING   : false //not used yet
		},
		name : "Yahoo! Answers",
		version : "",
		locale : 'en_US',
		ua : navigator.userAgent.toLowerCase(),
		
		logger : function() {
		    var _logger;
		    var _configs = { 
			    height: "22em", // Height of container 
			    footerEnabled: true, // Don't show filters/pause/resume/clear UI 
			    verboseOutput: true,
			    logReaderEnabled: true // Pause right away (should be true all the time)
			};
		    return {
		        init: function() {
		            _logger = new YAHOO.widget.LogReader('y-ks-error-log',_configs);
		            _logger.setTitle("");
		        },
		
		        hide: function() {
		            _logger.hide();
		        },
		        
		        show: function() {
		            _logger.show();
		        }
		    }
		}()
	},
	
	search_ahead : {
		TIMEOUT_HANDLE_IN_MILLISECONDS : 750,
		NTH_WORD_TRIGGER : 3,
		SEARCH_AHEAD_SUGGESTED_QUESTIONS : "suggestionsQuestions",
		
		timeout_handle : null,
		request_handler : "/common/util/ks-yfed-search-handler.php"
	},
    cache : {
        data : {
        },
        setData : function(key, value){
            this.data[key] = value;
        },
        getData : function(key){
            return this.data[key];
        }
    },    
	util : {
		ERROR_NOTICE : { key : "8", value : "notice" },
		ERROR_INFO :   { key : "4", value : "info"   },
		ERROR_WARN :   { key : "2", value : "warn"   },
		ERROR_ERROR :  { key : "1", value : "error"  },
		
		forms : {
			toggleCheckboxFamily : function(pThisElement,pForm,pElementName) {
				var _isChecked = (pThisElement.checked);
				var _form = pForm;
				var _form_eles = _form.elements;
				var _form_eles_length = _form.elements.length;
				for (var _f=0; _f < _form_eles_length; _f++) {
					if (_form_eles[_f].name =  pElementName) {
						_form_eles[_f].checked = _isChecked;
					}
				}
			}
		},
		
		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 {
					YAHOO.util.Connect.asyncRequest(_formType, pUrl, pCallback); 
				}
				catch(e) {
					//TODO
				}
			}			
		}
	}
}


var oAnswers =				YAHOO.search.answers;
var oCache = 		        oAnswers.cache;
var oLogger = 				oAnswers.application.logger;

 
/* @requires KS_Util (instance name: Util)
 * @returns array
 */
function KS_infoLayer(pId,pDivId,pDivAuxId,pNotepad,pOffsetTop,pIncentiveEvents,pX,pY) {
    this.id=pId;
    this.window_url=location.href.toLowerCase();
    this.isD=(this.window_url.indexOf("5555")!=-1 || this.window_url.indexOf("6666")!=-1 || this.window_url.indexOf("7777")!=-1); 
    this.e=document.getElementById(pDivId);
    this.aux_e=document.getElementById(pDivAuxId);
    this.notepad=document.getElementById(pNotepad);
    this.offsetX=pX || 0;
    this.offsetY=pY || 0;
    this.move_handler=null;
    this.parentOffsetY=parseInt(pOffsetTop) || 0;
    this.incentive_events=pIncentiveEvents || [];
    this.notification_count=0;
    this.TIME_DELAY=0.7;
    this.ELEMENT_WIDTH=300;
    this.ELEMENT_HEIGHT=this.parentOffsetY; //minimum height of the element
    this.TIMEOUT_IN_SECONDS=10;
    //this.STATES=new Array('');
}

KS_infoLayer.prototype.timeoutAndDisappear=function(){
    var self=this;
    setTimeout(function(){ self.moveUp() },(self.TIMEOUT_IN_SECONDS * 1000));
}

KS_infoLayer.prototype.doCorrectPos=function() {
    // var someXY = this.setInitialPos();
}

/* @returns void 
    set home coordinates */
KS_infoLayer.prototype.setCoordinates=function(pXY) {
    this.setPos(this.getPos(this.e));
    this.setPos(this.getPos(this.aux_e));
}

/* @returns array */
KS_infoLayer.prototype.getPos=function(pEle){ return ygPos.getPos(pEle || this.e);}

/* @returns void
    store the x,y position of the element */
KS_infoLayer.prototype.setPos=function(pXY){ this.offsetX=pXY[0]; this.offsetY=pXY[1]; }
    
/* @returns void */    
KS_infoLayer.prototype.init=function(){
    var g = Util.gObj('y-ks-info-static-user-layer');
    //this.setCoordinates();
    
    if (this.incentive_events.length > 0) {
        var s = this.parseAndAggregateEvents();
        if (s.length > 0) {
            this.insertText(s);
            // Util.gObj('y-ks-info-layer-menu-layer-notify-count').innerHTML = " ("+ this.notification_count.toString() +")";
            this.moveDown();
            this.timeoutAndDisappear();
            
        }
        this.resetCounter();
    }
}

KS_infoLayer.prototype.resetCounter=function() { this.notification_count=0; }

KS_infoLayer.prototype.show=function() {
    this.e.style.visibility='visible';
    this.aux_e.style.visibility='hidden';
}

KS_infoLayer.prototype.hide=function() {
    this.e.style.visibility='hidden';
    this.aux_e.style.visibility='visible';
}

KS_infoLayer.prototype.getPointsFromLoggingIn=function() {
    var c_events = this.incentive_events.length;
    var count = 0;
    for (var cpe=0; cpe < c_events; cpe++) {
        if (parseInt(this.incentive_events[cpe].getOid())==2) count++; //the number 2 is a hack
    }
    if (count > 0) this.notification_count++;
    return count;
}

KS_infoLayer.prototype.wrapHTMLToIncentiveEvent=function(pObj,pIsFirst) {    
    s =  '<div class="incentive_event" style="'+((!pIsFirst)?"border-top:1px solid #ccc;":"")+'">';
    s += '<div class="display-point-total">' +pObj.getPoints()+ '</div>';
    s += '<strong>'+((this.isD)?"["+pObj.getOid().toString()+"] ":"")+this.STATES[pObj.getOid()]+ '</strong><br/>';
    s += '<em>(' +pObj.getTime()+ ' ago)</em><br/>';
    s += ("0"!=pObj.getQid()) ? '<p align="right"><a href="/question/index?qid='+pObj.getQid() +'">View Question</a></p>' : '';
    s += '</div>';
    return s;
}

KS_infoLayer.prototype.wrapHTMLToAggregatedIncentiveEvents=function(pCount) {    
    s =  '<div class="incentive_event">';
    //s += '<div class="display-point-total">'+pCount+'</div>';
    s += '<strong>You\'ve earned ' +parseInt(pCount)+ ' point'+ ((pCount==1) ? "" : "s") +'</strong><br/>';
    s += '</div>';
    return s;
}

KS_infoLayer.prototype.parseAndAggregateEvents=function(){
    var s='';                
    var isFirst=true;
    var count=0;
    var c_events = this.incentive_events.length;
    for (var ce=0; ce < c_events; ce++) {
        var obj = this.incentive_events[ce];
        if (parseInt(obj.getOid()) == 23) {
            if (ce == 0) { // it's the first and most recent event
                var tmpUrl = "/my/my?link=question&more=y";
                s += '<div class="new"><strong>Some of <a href="' + tmpUrl + '">your questions</a> need attention!</strong></div>';
                break;
            }
            else {
                continue;
            }
        }
        if (parseInt(obj.getOid())== 1 && !obj.isBruteForceAction()); //filter out the activation
        count += parseInt(obj.getPoints());
        this.notification_count++;
    }
    if (count > 0) s += this.wrapHTMLToAggregatedIncentiveEvents(count);
    return s;
}

KS_infoLayer.prototype.parseAndFormatIncentiveEvents=function(){
    var s='';
    var c_login=this.getPointsFromLoggingIn();
    if (c_login > 0) s+='<div class="incentive_event">You\'ve earned <strong>'+c_login.toString() +'</strong> points from logging in!</div>';
    var c_events = this.incentive_events.length;
    for (var ce=0; ce < c_events; ce++) {
        var isFirst = (ce==0);
        var obj = this.incentive_events[ce];
        if (parseInt(obj.getOid())== 1 && !obj.isBruteForceAction()) continue; //filter out activation events
        s += this.wrapHTMLToIncentiveEvent(obj,isFirst);
        this.notification_count++;
    }
    return s;
}

/* @returns void
 */
KS_infoLayer.prototype.moveUp=function() {
    var h=(this.e.offsetHeight > this.ELEMENT_HEIGHT) ? (-1*(this.e.offsetHeight-this.ELEMENT_HEIGHT)) : 0;
    var self=this;
    var tmpele = Util.gObj('y-ks-info-static-user-layer');
    var someXY = this.getPos(tmpele);

    this.move([someXY[0], h]);
    setTimeout( function() { self.hide() }, 1000 );
    return false;
}

KS_infoLayer.prototype.setInitialPos=function() {
    var tmpele = Util.gObj('y-ks-info-static-user-layer');
    var someXY = this.getPos(tmpele);
    this.setPos(someXY);
    return someXY;
}

/* @returns void
 */
KS_infoLayer.prototype.moveDown=function() {
    var someXY = this.setInitialPos();
    this.show();
    this.move([parseInt(someXY[0]), this.parentOffsetY]);
    Util.debug("setting to: " + parseInt(someXY[0]) + " " + this.parentOffsetY.toString());
    return false;
}


KS_infoLayer.prototype.move=function(pCoord){
    if (null==this.move_handler) {
        this.move_handler=new ygAnim_Move(this.e,this.TIME_DELAY,pCoord);
        this.move_handler.animate();
        this.setCoordinates();
        this.move_handler=null;
    }
}

/* 
 * @returns void
 *   insert text
 */
KS_infoLayer.prototype.insertText=function(pStr) { this.notepad.innerHTML=pStr; }

/* @returns void
 */
KS_infoLayer.prototype.appendText=function(pStr) {
    var t=this.notepad.innerHTML;
    this.notepad.innerHTML=t+pStr+"<br/>";
}

KS_infoLayer.prototype.getWidth=function(){ return this.e.style.width; }
KS_infoLayer.prototype.setIncentiveEventsArray=function(pObj){ this.incentive_events=pObj; }
KS_infoLayer.prototype.getIncentiveEventsArray=function(){ return this.incentive_events; }

/*  @returns void
 *  - add new incentive event to the menu
 */
KS_infoLayer.prototype.addIncentiveEvent=function(pObj) {
    if (typeof pObj == "object") { 
        this.incentive_events[this.incentive_events.length]=pObj;
        this.appendText(this.wrapHTMLToIncentiveEvent(pObj));
    }
    else if (arguments.length >= 5) { //pass in strings to create a new event
        this.incentive_events[this.incentive_events.length]=new KS_Incentive_Event(pKid,pOid,pPoints,pTime,pQid);
        this.appendText(this.wrapHTMLToIncentiveEvent(pObj));
    }
    return;
}

function KS_Incentive_Event(pKid,pOid,pPoints,pTime,pQid,pBruteForceAction){
    this.kid=pKid;
    this.oid=pOid;
    this.points=pPoints;
    this.time=pTime;
    this.qid=pQid;
    this.brute_force=pBruteForceAction || false;
}

KS_Incentive_Event.prototype.getKid=function() { return this.kid; }
KS_Incentive_Event.prototype.setKid=function(pStr) { this.kid=pStr; }
KS_Incentive_Event.prototype.getOid=function() { return this.oid; }
KS_Incentive_Event.prototype.setOid=function(pStr) { this.oid=pStr; }
KS_Incentive_Event.prototype.getPoints=function() { return this.points; }
KS_Incentive_Event.prototype.setPoints=function(pStr) { this.points=pStr; }
KS_Incentive_Event.prototype.getTime=function() { return this.time; }
KS_Incentive_Event.prototype.setTime=function(pStr) { this.time=pStr; }
KS_Incentive_Event.prototype.getQid=function() { return this.qid; }
KS_Incentive_Event.prototype.setQid=function(pStr) { this.qid=pStr; }
KS_Incentive_Event.prototype.isBruteForceAction=function() { return this.brute_force; }


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

function KS_Util(pId,pBrowserObj,pIsDebug,pKid,pKNickname,pURL,pIsViewingSelf){
    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.REQUEST_URI = pURL;
    this.DATATYPE_OBJECT="object";
    this.OFFSET_BODY_HEIGHT=100;
    this.EXCEPTION_STRING="EXCEPTION";
    this.isViewingSelf = pIsViewingSelf||false;
    
    this.IS_JAVASCRIPT_DEBUG=pIsDebug||false;
    this.DEBUG_CONSOLE='y-ks-error-log';
    //this.DISPLAY_WIDGET_STAR='<img src="http://us.i1.yimg.com/us.yimg.com/i/us/sch/gr/pointsstar.gif" border="0" alt="star"/>';
    //this.DISPLAY_WIDGET_ALERT='http://us.i1.yimg.com/us.yimg.com/i/us/sch/gr/alrt12_1.gif';
    this.DISPLAY_WIDGET_1= 'y-ks-header-user-profile-widget-msg-1';
    this.DISPLAY_WIDGET_2= 'y-ks-header-user-profile-widget-msg-2';
    this.current_widget_display=this.DISPLAY_WIDGET_1;
    //this.DISPLAY_WIDGET_NOTIFICATION_STATES=new Array('');
}
KS_Util.prototype.getKid = function() {
	return this.kid;	
}
KS_Util.prototype.getRequestParameter =function(parameterName) {
	var queryString = window.top.location.search.substring(1)
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		var begin = queryString.indexOf ( parameterName );
		var end;
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape(queryString.substring(begin,end));
		}
		// Return "null" if no parameter has been found
		return null;
	}
}

KS_Util.prototype.getIsViewingSelf = function() {
	return this.isViewingSelf;	
}

KS_Util.prototype.setIsViewingSelf = function(pBool) {
	this.isViewingSelf = pBool;	
}

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.writeWidgetMessage=function(pPt) {
	var s="";
	if (pPt < 0) s +='<span style="">Alert</span>';
	else if (pPt == 0) s +='<span style="">Alert</span>';
	else if (pPt > 0) s +='<span style="color:#52be0a">Thanks!</span>';
	else s +='<span style="">Alert</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">Hi <a href="/my/my">' + this.nick + '</a>! Check your <a href="/my/my?link=question&more=y">questions</a> for a best answer</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="http://us.i1.yimg.com/us.yimg.com/i/us/sch/gr2/medal.gif" vspace="12" style="border:none;" alt="award medal" /></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>Some of <a href="' + tmpUrl + '">your questions</a> need attention!</strong></span></td>';
        }
        else {
	       	s += '<td style="width:60px; height:50px; vertical-align:middle; text-align:center;"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/sch/gr2/medal.gif" vspace="12" style="border:none;" alt="award medal" /></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) ? "point" : "points";
				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%;">Whoa!</strong><br/>';
                	s += "You\'ve earned <strong>"+ count + "</strong> points!";
                	s +=' </span>';//need the space for aesthetic reasons
                } else {
					s += '<strong style="margin-top:12px; font-size:115%;">Alert</strong><br/>';
					var _num = (count * -1);
                	s += "You\'re down <strong>" + _num + "</strong> points!";
                	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">Tell Me More</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 YAHOO.util.Anim(pEle, { opacity: { to: 1, from : 0 } }, 1.9, YAHOO.util.Easing.easeNone);
	 }
	 else { //hidden
   	 	oAnim = new YAHOO.util.Anim(pEle, { opacity: { to: 0, from : 1 } }, 1.9, YAHOO.util.Easing.easeNone);
	 }
	 // YAHOO.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();
    if(this.getKid() != undefined) {
        this.initMCE();
    }
    hasWindowLoaded = true;
}



YAHOO.search.answers.cache.setData('boaItemCount', 7);
YAHOO.search.answers.cache.setData('currBoaIndex', 0);
YAHOO.search.answers.cache.setData('boaTimerState', 1);
YAHOO.search.answers.cache.setData('boaAnimating', false);
function displayFeaturedItem(index, forward) {
	currBoaIndex = YAHOO.search.answers.cache.getData('currBoaIndex');
	animating = YAHOO.search.answers.cache.getData('boaAnimating');
	if(index != currBoaIndex && !animating) {
		YAHOO.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);

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

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

		if(boaContent && currItem && newItem) {

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

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

			YAHOO.search.answers.cache.setData('currBoaIndex', index);
			itemCount = YAHOO.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 = YAHOO.search.answers.cache.getData('currBoaIndex');
	itemCount = YAHOO.search.answers.cache.getData('boaItemCount');
	if(currBoaIndex > 0) {
		displayFeaturedItem(currBoaIndex - 1, false);
	} else {
		displayFeaturedItem(itemCount - 1, false);
	}
}

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

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

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

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

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