﻿
wep.setFeedDomainProtocol = function (){
    if(document.location.href.slice(0,6) == 'https:'){
        if(this.feedDomainTBN.slice(0,5) == 'http:') this.feedDomainTBN = 'https:' + this.feedDomainTBN.slice(5);
        if(this.feedDomainFNP.slice(0,5) == 'http:') this.feedDomainFNP = 'https:' + this.feedDomainFNP.slice(5);
    }
}

wep.setFeedDomainProtocol();
wep.buttonServerUrl = wep.feedDomainTBN + '/tbn/' + wep.siteId + '/' + wep.locale.replace('_', '/') + '/';

wep.tryCount = 0;
wep.numButtons = 0;

wep.getButtonJsonData = function(){
  var jsrOb = new jsr.JsonScriptRequest(this.buttonServerUrl);      
  jsrOb.buildScriptTag();
  jsrOb.addScriptTag();
}

wep.getButtonData = function(){
    if(document.body == null) {
        if(this.tryCount<100)setTimeout('this.getButtonData()',100);
        this.tryCount++;
    }
    else this.getButtonJsonData();
}
 
wep.topbar = function(data){
   if(data!=null){
	var item;
    var labelText;
    var altText;
    var buttonId;
    var buttonType;
    var buttonHTML = '';
    var buttonDiv = document.getElementById('wep_buttons');
    var topBarSpacerUrl = data.feed[0].icon;
    
    if(data.feed[0].isSearchEnabled == 'True')
        document.getElementById('wep_searchArea').style.display = 'block';

    this.numButtons = data.feed[0].entry.length;
    
	for (var I = 0 ; I < data.feed[0].entry.length ; I++) {
		item = data.feed[0].entry[I];

		buttonId = item.id;
		labelText = item.title;
		altText = item.summary;
		buttonType = item.type;

        this.btnAry[I] = new Array(1);
        this.btnAry[I][0] = buttonId;
        this.btnAry[I][1] = buttonType;
		
		buttonHTML += '<div class="wep_button" id="wep_button' + I + '" onclick="'
		if(this.omn.track){
            buttonHTML += 'var weps=s_gi(\'' + this.omn.trackingAccount + '\');' +
                'weps.linkTrackVars=\'prop1,prop2,prop3,prop4,prop5,prop44\';' +
                'weps.prop1=\'' + this.omn.siteUrl + '\';' +
                'weps.prop2=\'' + this.omn.country + '\';' +
                'weps.prop3=\'' + this.omn.language + '\';' +
                'weps.prop4=\'' + this.omn.brand + '\';' +
                'weps.prop5=\'' + this.omn.audience + '\';' +
                'weps.prop44=\'' + buttonId + '\';' +
                'weps.tl(this, \'o\', \'WEP Button\');'
        }
		buttonHTML += 'try{wep.showmenu(\'' + buttonId + '\',' + I + ',\'' + buttonType + '\')}catch(e){};' +
		    '" title="' + altText + '" onmouseover="try{wep.hoverButton(' + I + ')}catch(e){}" onmouseout="try{wep.outButton(' + I + ')}catch(e){}">' + labelText + '</div>';
	}
	wep.numButtons = I;
	buttonDiv.innerHTML = buttonHTML;
  }
}

wep.hoverButton = function(buttonId){
    var button = document.getElementById('wep_button' + buttonId);
    if(!wep.hasClass(button, 'wep_buttonSelected')){
        button.className = 'wep_buttonHover';
    }
}
wep.outButton = function(buttonId){
    var button = document.getElementById('wep_button' + buttonId);
    if(!wep.hasClass(button, 'wep_buttonSelected')){
        button.className = 'wep_button';
    }
}
wep.hasClass = function (object, className){
    if(object){
        if(object.getAttribute('class')==className || object.getAttribute('className')==className)
            return true;
    }
    return false;
}   
