GAL.namespace('search.answers');
GAL.search.answers = {
	application : {
		logger : function() {
		    var _logger;
		}()
	},
	
    cache : {
        data : {
        },
        setData : function(key, value){
            this.data[key] = value;
        },
        getData : function(key){
            return this.data[key];
        }
    },
	spellcheck : {
		SpellController : {},	
		data : {}		
	},
	util : {},
	translations: {}
}
var oAnswers =				GAL.search.answers;
var oCache = 		        oAnswers.cache;
var oProfile = 		        oAnswers.profile;
var oRelationships = 		oAnswers.relationships;
var oLogger = 				oAnswers.application.logger;
var SpellController = 		oAnswers.spellcheck.SpellController;
var Speller = 				oAnswers.spellcheck.data.Speller;
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();
}
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;
}
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='';
    this.DISPLAY_WIDGET_ALERT='';
    this.DISPLAY_WIDGET_1= '';
    this.DISPLAY_WIDGET_2= '';
    this.current_widget_display=this.DISPLAY_WIDGET_1;
    this.DISPLAY_WIDGET_NOTIFICATION_STATES=new Array( );
}
KS_Util.prototype.isNull=function(pEle){
    return (null==pEle || "undefined"==pEle || ""==pEle);
}
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;
}
function Selection(textareaElement) {
    this.element = textareaElement;
}
GAL.search.answers.cache.setData('boaItemCount', 5);
GAL.search.answers.cache.setData('currBoaIndex', 0);
GAL.search.answers.cache.setData('boaTimerState', 1);
GAL.search.answers.cache.setData('boaAnimating', false);
function displayFeaturedItem(index, forward) {
	currBoaIndex = GAL.search.answers.cache.getData('currBoaIndex');
	animating = GAL.search.answers.cache.getData('boaAnimating');
	if(index != currBoaIndex && !animating) {
		GAL.search.answers.cache.setData('boaAnimating', true);
		if(forward == null) {
			forward = (index - currBoaIndex > 0);
		}
display_text(index);
		boaContent = Util.gObj("boa-content");
		currItem = Util.gObj("fc-"+currBoaIndex);
		newItem = Util.gObj("fc-"+index);

		GAL.util.Dom.setStyle(newItem, 'position', 'absolute');

		startPos = 460;
		if(!forward) {
			startPos *= -1;
		}
		GAL.util.Dom.setStyle(newItem, 'left', startPos+'px');
		GAL.util.Dom.setStyle(newItem, 'display', 'block');

		if(boaContent && currItem && newItem) {

			var finishFade = function() {
				var el = this.getEl();
				GAL.util.Dom.setStyle(el, 'display', 'none');
				GAL.util.Dom.setStyle(el, 'opacity', 1);
				GAL.search.answers.cache.setData('boaAnimating', false);
			}

			GAL.util.Dom.setStyle(currItem, 'opacity', 1);
			GAL.util.Dom.setStyle(currItem, 'background-color', '#fff');
			var fadeAnim = new GAL.util.Anim(currItem, { opacity: { to: 0 }}, 0.6, GAL.util.Easing.easeOut);
			fadeAnim.onComplete.subscribe(finishFade); 
			fadeAnim.animate();
			var flyAnim = new GAL.util.Anim(newItem, { left: { from: startPos, to: 0 } }, 0.5, GAL.util.Easing.easeBoth); 
			flyAnim.animate(); 

			GAL.search.answers.cache.setData('currBoaIndex', index);
			itemCount = GAL.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 = GAL.search.answers.cache.getData('currBoaIndex');
	itemCount = GAL.search.answers.cache.getData('boaItemCount');
	if(currBoaIndex > 0) {
		displayFeaturedItem(currBoaIndex - 1, false);
	} else {
		displayFeaturedItem(itemCount - 1, false);
	}
}
function nextFeaturedItem() {
	currBoaIndex = GAL.search.answers.cache.getData('currBoaIndex');
	itemCount = GAL.search.answers.cache.getData('boaItemCount');
	if(currBoaIndex < itemCount - 1) {
		displayFeaturedItem(currBoaIndex + 1, true);
	} else {
		displayFeaturedItem(0, true);
	}
}
function startBoaTimer() {
	stopBoaTimer();
	timer = setTimeout("nextFeaturedItem()", 15000);
	GAL.search.answers.cache.setData('boaTimer', timer);
	GAL.search.answers.cache.setData('boaTimerState', 1);
}
function stopBoaTimer() {
	timer = GAL.search.answers.cache.getData('boaTimer');
	if(timer) {
		clearTimeout(timer);
	}
	GAL.search.answers.cache.setData('boaTimerState', 0);
}
function resetBoaTimer() {
	boaTimerState = GAL.search.answers.cache.getData('boaTimerState');
	if(boaTimerState) {
		stopBoaTimer();
		startBoaTimer();
	}
}

function display_text(currnt_index)
{
	//alert("txt-"+currnt_index +"");
    var text_=document.getElementById("txt-"+currnt_index +"");
	for(i=0;i<5;i++)
	{
		document.getElementById("txt-"+ i +"").style.display ="none";
		
	}
	text_.style.display ="block";
}

