
TMB.namespace('search.countryQuestion');
TMB.search.countryQuestion = {

	
    cache : {
        data : {
        },
        setData : function(key, value){
            this.data[key] = value;
        },
        getData : function(key){
            return this.data[key];
        }  
    },	
	translations: {}
}

function KS_UtilCountrtQuestion(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.isViewingSelf = pIsViewingSelf||false;
    this.IS_JAVASCRIPT_DEBUG=pIsDebug||false;
    
}
KS_UtilCountrtQuestion.prototype.getKid = function() {
	return this.kid;	
}


KS_UtilCountrtQuestion.prototype.getIsViewingSelf = function() {
	return this.isViewingSelf;	
}

KS_UtilCountrtQuestion.prototype.setIsViewingSelf = function(pBool) {
	this.isViewingSelf = pBool;	
}



KS_UtilCountrtQuestion.prototype.isNull=function(pEle){
    return (null==pEle || "undefined"==pEle || ""==pEle);
}

KS_UtilCountrtQuestion.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_UtilCountrtQuestion.prototype.init=function() {

      hasWindowLoaded = true;
}

//find and replace
String.replace=function(find,replace){return this.split(find).join(replace);}

//escape for xml file
String.escapeForXML=function(){return this.replace('&','&amp;').replace('"','&quot;').replace('<','&lt;').replace('>','&gt;');}

//escape xml to non destructive html
String.escapeForDisplay=function(){return this.replace('<','&lt;');}

TMB.search.countryQuestion.cache.setData('currBoaIndex', 0);
TMB.search.countryQuestion.cache.setData('boaTimerState', 1);
TMB.search.countryQuestion.cache.setData('boaAnimating', false);

function displayFeaturedItem1(index, forward) {

	currBoaIndex = TMB.search.countryQuestion.cache.getData('currBoaIndex');
	animating = TMB.search.countryQuestion.cache.getData('boaAnimating');
	if(index != currBoaIndex && !animating) {
		TMB.search.countryQuestion.cache.setData('boaAnimating', true);
		if(forward == null) {
			forward = (index - currBoaIndex > 0);
		}

		boaContent = Util.gObj("boa-content1");
		
		currItem = Util.gObj("fc1-"+currBoaIndex);
		newItem = Util.gObj("fc1-"+index);

		TMB.util.Dom.setStyle(newItem, 'position', 'absolute');

		startPos = 460;
		if(!forward) {
			startPos *= -1;
		}
		TMB.util.Dom.setStyle(newItem, 'left', startPos+'px');
		TMB.util.Dom.setStyle(newItem, 'display', 'block');

		if(boaContent && currItem && newItem) {

			var finishFade = function() {
				var el = this.getEl();
				TMB.util.Dom.setStyle(el, 'display', 'none');
				TMB.util.Dom.setStyle(el, 'opacity', 1);
				TMB.search.countryQuestion.cache.setData('boaAnimating', false);
			}

			TMB.util.Dom.setStyle(currItem, 'opacity', 1);
			TMB.util.Dom.setStyle(currItem, 'background-color', '#fff');
			var fadeAnim = new TMB.util.Anim(currItem, { opacity: { to: 0 }}, 0.6, TMB.util.Easing.easeOut);
			fadeAnim.onComplete.subscribe(finishFade); 
			fadeAnim.animate();
			var flyAnim = new TMB.util.Anim(newItem, { left: { from: startPos, to: 0 } }, 0.5, TMB.util.Easing.easeBoth); 
			flyAnim.animate(); 

			TMB.search.countryQuestion.cache.setData('currBoaIndex', index);
			itemCount = TMB.search.countryQuestion.cache.getData('boaItemCount1');
			for(i = 0 ; i < itemCount ; i++) {
				p = Util.gObj("bp-"+i);
				if(p!=null){
					if(i != index) {
						p.className = '';
					} else {
						p.className = 'active';
					}
				}
			}
			updateBoaAttributes1(index);
			resetBoaTimer1();
		}
	}
}

function updateBoaAttributes1(index) {
	var newTitle = Util.gObj("fc-title1-"+index);
	if(newTitle) {
		var title = Util.gObj("boa-title1");
		title.innerHTML = newTitle.value;
	}
}

function previousFeaturedItem1() {

	currBoaIndex = TMB.search.countryQuestion.cache.getData('currBoaIndex');
	itemCount = TMB.search.countryQuestion.cache.getData('boaItemCount1');
	
	if(currBoaIndex > 0) {
		displayFeaturedItem1(currBoaIndex - 1, false);
	} else {
		displayFeaturedItem1(itemCount - 1, false);
	}
	document.getElementById('boa-top1').style.display="none";
}

function nextFeaturedItem1() {
	currBoaIndex = TMB.search.countryQuestion.cache.getData('currBoaIndex');
	itemCount = TMB.search.countryQuestion.cache.getData('boaItemCount1');
	if(currBoaIndex < itemCount - 1) {
		displayFeaturedItem1(currBoaIndex + 1, true);
	} else {
	
		displayFeaturedItem1(0, true);
	}
		document.getElementById('boa-top1').style.display="none";
}

function startBoaTimer1() {
	stopBoaTimer1();
	timer = setTimeout("nextFeaturedItem1()", 10000);
	TMB.search.countryQuestion.cache.setData('boaTimer', timer);
	TMB.search.countryQuestion.cache.setData('boaTimerState', 1);
}

function stopBoaTimer1() {
	timer = TMB.search.countryQuestion.cache.getData('boaTimer');
	if(timer) {
		clearTimeout(timer);
	}
	TMB.search.countryQuestion.cache.setData('boaTimerState', 0);
}

function resetBoaTimer1() {
	boaTimerState = TMB.search.countryQuestion.cache.getData('boaTimerState');
	if(boaTimerState) {
		stopBoaTimer1();
		startBoaTimer1();
	}
}

function toggleBoaTimer1() {
	boaTimerState = TMB.search.countryQuestion.cache.getData('boaTimerState');
	button = Util.gObj('ctrl-pause1');
	if(boaTimerState) {
		button.className = "play";
		stopBoaTimer1();
	} else {
		button.className = "pause";
		startBoaTimer1();
	}
}
