/* -- BEGIN SPHERE JS -- */      

// site id for bookmarket
var SPHERE_SITE_ID = "";
	SPHERE_SITE_ID = "ssi";

//MediaPixel Removed

// Omniture 
/*
  The core url used by all methods to make calls to the remote omniture code.
  the 'action' arg will be the name of a method to be called by eval in the 
  sphereomni_api js code.
*/

function getSphereOmnitureRemoteActionUrl(action){
		return "http://www.surphace.com/partner/omniture/sphereomni_api.php?siteid=ssi&evt="+action+"&omid="+Math.ceil(Math.random()*100000000);
    }

function getSphereOmnitureQueueActionUrl(action){
		return "http://www.surphace.com/partner/omniture/sphereomni_queue.php?evt="+action+"&siteid=ssi";
    }

Sphere = {}
Sphere.addStylesheet = function(stylesheet_href) {
	var stylesheet = document.createElement("link");
	stylesheet.rel = "stylesheet";
	stylesheet.type = "text/css";
	   stylesheet.href = stylesheet_href;
	stylesheet.media = "all";
	document.lastChild.firstChild.appendChild(stylesheet);
}
Sphere.Browser = new function() {
	var ua, s, i;

	this.isIE    = false;
	this.isNS    = false;
	this.version = null;

	ua = navigator.userAgent;

	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
	  this.isIE = true;
	  this.version = parseFloat(ua.substr(i + s.length));
	  return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
	  this.isNS = true;
	  this.version = parseFloat(ua.substr(i + s.length));
	  return;
	}

	// Treat any other "Gecko" browser as NS 6.1.

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
	  this.isNS = true;
	  this.version = 6.1;
	  return;
	}	
}
Sphere.Tracker = new function() {
    this.track = function ( ele, site, area, quadtitle,sphereid,metadata) {
    	    if( !ele.href ) return;   
    	    
      	      		
      		/* 
      		 -- the following may or may not be present, so check and init if necessary 
      		 -- sphereid is used by ssi and represents site id by proxy
      		 -- metadata should be in the form of a pipe-delimited string
      		    e.g.  k=v|b=y
      		*/
        try{
          	if(!quadtitle){ quadtitle = '';}
          }catch(anErr){
          	quadtitle = '';
          }
          
           try{
          	if(!sphereid){ sphereid = '';}
          }catch(anErr){
          	sphereid = '';
          }
          
          try{
          	if(!metadata){ metadata = '';}
              
          }catch(anErr){
          	metadata = '';
          }

          // put document referrer metadata in it's own try/catch block so that it is set even if metadata isn't init'd
          try{
            if (document.referrer != ''){
                 metadata += "|referrer=" + document.referrer;
            }
           }catch(anErr){
           }
          
         sphereom = new SphereOmniture();
         sphereom.click(ele.href, area, site, quadtitle,sphereid,metadata);
	
	    

    }
}



Sphere.Inline = new function() {

    var content;

    this.processContent = function (content) {
        if( !content || !content.content || content.content=="") return;
        // append content and omniture frame
        // ********************************
        document.getElementById(content.location).innerHTML = content.content+ "<div style='visibility:hidden;display:none'><iframe name='sphereomnitureframe' id='sphereomnitureframe' src='http://www.surphace.com/partner/omniture/sphereomni_api.php?siteid=ssi&evt=fireSphereOmInitAction&omid=809305' frameborder='0' style='width:10px;height:10px;' ></iframe></div>" ;
        
               // omniture init
        // deprecated.  now called when content loads
	    //sphereom = new SphereOmniture();
	    //sphereom.init();
	        }

			Sphere.addStylesheet("http://cdn11.surphace.com/widgets/sphereit/css?siteid=ssi");
		this.search = function(s4id, local) {
			var url = escape(local || location.href);
			document.write("<script src='http://www.surphace.com/widgets/sphereit/content?siteid=ssi_inline&s4id=" + s4id + "&url=" + url + "'></script>");
		}
				
}



// Omniture object
//********************************
OMNITURE_INIT = false;
OMNI_POPUP_INIT = false;
OMNI_AOL_POPUP_INIT = false;
 

function SphereOmniture(){
       this.omniobj = null;

        

}

function _initSphereOm(){
       //alert("init: "+this.omniobj);
      if(OMNITURE_INIT){ return;  } else { OMNITURE_INIT = true; }
     
      theURL = getSphereOmnitureRemoteActionUrl("fireSphereOmInitAction");
      getSphereRemoteFrame().src = theURL;
      wait(200);
      
           
  
}


function _initSphereOmPopup(){
           if(OMNI_POPUP_INIT){ return false;  } else { OMNI_POPUP_INIT = true; }
      
      theURL = getSphereOmnitureRemoteActionUrl("fireSphereOmInitPopupAction");
      getSphereRemoteFrame().src = theURL;
      wait(200);
      
            
}

function _clickSphereOm(lnk,quad,context,quadtitle,sphereid,metadata){
      appendPopup = '';
     if(new String(context).indexOf("_popup") > -1){ appendPopup = "_popup"; }
         
          try{
          	if(!quadtitle){ quadtitle = '';}
          }catch(anErr){
          	quadtitle = '';
          }
          
	theURL = getSphereOmnitureQueueActionUrl("fireSphereOmClickAction");
    theURL += appendPopup+"&quad="+quad+"&fquadname="+quadtitle+"&context="+context+"&lnk="+escape(lnk)+"&loc="+escape(window.location)+"&sphereid="+sphereid+"&metadata="+escape(metadata);
      //  getSphereRemoteFrame().src = theURL;
    omImg = new Image();
    omImg.src = theURL;
 
    }

function _trackSphereOm(quad,context,quadtitle,sphereid,metadata){
   
    
  	
 	 try{
          	if(!quadtitle){ quadtitle = '';}
          }catch(anErr){
          	quadtitle = '';
          }
          
    theURL = getSphereOmnitureQueueActionUrl("fireSphereOmTrackAction");
    theURL += "&quad="+quad+"&fquadname="+quadtitle+"&context="+context+"&loc="+escape(window.location)+"&sphereid="+sphereid+"&metadata="+escape(metadata);
      //  getSphereRemoteFrame().src = theURL;
    omImg = new Image();
    omImg.src = theURL;

	
	
}

function _trackAOLPopup(quad, context){

  	 if(OMNI_AOL_POPUP_INIT){ return false;  } else { OMNI_AOL_POPUP_INIT = true; }
	
    
      theURL = getSphereOmnitureRemoteActionUrl("fireSphereOmTrackAction");
      theURL += "&quad="+quad+"&context="+context;
      getSphereRemoteFrame().src = theURL;
      wait(400);
      
          
		
}

function  _trackAolOm(lnk,lnkType,lnkName,lnkPos){
       
    theURL = getSphereOmnitureRemoteActionUrl("fireSphereOmTrackAction");
    theURL += "&lnk="+escape(lnk)+"&lnkType="+lnkType+"&lnkName="+lnkName+"&lnkPos="+lnkPos;
    getSphereRemoteFrame().src = theURL;
    wait(200);
    
     
 }
 
function _initAolOm(){
         theURL = getSphereOmnitureRemoteActionUrl("fireSphereOmInitAolAction");
      getSphereRemoteFrame().src = theURL;
      wait(200);
       
}
 


SphereOmniture.prototype.init          = _initSphereOm;
SphereOmniture.prototype.popup         = _initSphereOmPopup;
SphereOmniture.prototype.initaol       = _initAolOm;
SphereOmniture.prototype.track         = _trackSphereOm;
SphereOmniture.prototype.click         = _clickSphereOm;
SphereOmniture.prototype.trackaol      = _trackAolOm;
SphereOmniture.prototype.trackAOLPopup = _trackAOLPopup;


/*****************************
  SphereOm Remote object api
   -- This was put in place to isolate the omniture.js code,
      which causes conflicts with our partner's omniture implementations.
      It creates an IMG with an exposed set of pass-thru functions that
      access the omniture code.
******************************/

function getSphereRemoteFrame(){
		
	iele = document.getElementById("sphereomnitureframe");
	return iele;
	}



//***************** END OBJ *******************

// added this method so that gadget would call search after data had loaded.
//-----------------------------------
function loadGadgetView(permlnk){
	if(Sphere.Inline){
		//alert("found an inline");
		Sphere.Inline.search("sphereInline", permlnk);
	} else {
		//alert("no inline");
	}
}


/* -- END SPHERE JS -- */      
