Sphere = {}
Sphere.Tracker = new function() {
    this.track = function ( ele, site, area ) {
        if( !ele.href ) return;
        var trackimg = new Image();
        trackimg.src = 'http://www.sphere.com/widgets/sphereit/tracker?site='+site+'&area='+area+'&href='+ele.href;
    }
}
Sphere.Widget = new function() {

var cnnBlogSectionID = ( typeof cnnSectID != "undefined" ) ? cnnSectID : 'cnninline';
    
    var CONTENT_URL = 'http://www.sphere.com/widgets/sphereit/content?siteid='+cnnBlogSectionID;
    if(document.characterSet) CONTENT_URL += ('&cset='+escape(document.characterSet));
    CONTENT_URL += '&url=';
    var widget; var widgetContent; var widgetLoading;
    var content;
    var contentLoaded = false;
    
    this.search = function( source) {
        if( !content || (source && content.source!=source ) ) {
             requestContent( source );
             if( widget ){ widget.parentNode.removeChild(widget); content=null; widget=null; }
        }
        if( !widget ) draw();
        
        return false;
    }
    
    this.close = function() {
        if( widget ) widget.style.display ='none';
    }

    this.processContent = function (incomingContent) {
        content = incomingContent;
        if( !widgetContent ) return;
        widgetContent.innerHTML = content.content;
        if (!contentLoaded) {
			CNN_displayBlogContent(widgetLoading,widgetContent); //hides the loading message, displays fetched html
		}
		
		contentLoaded = true;
    }

		    function requestContent( local ) {
			window.setTimeout(function() {
	        var script = document.createElement('script');
			var auxVars_str = ( typeof auxVars != "undefined" ) ? auxVars : '';
	            script.src = CONTENT_URL + escape(local || location.href);
				if(auxVars_str) { script.src += '&auxVars=' + auxVars_str; }
	           document.body.appendChild(script);
				},2000);
	    }
	    
    
        
    function draw() {
      	widgetContent = document.getElementById('cnnBlogContainerContent');
        widgetLoading = document.getElementById('cnnBlogsLoad');
		if( content ) Sphere.Widget.processContent( content );
    }
		
    
} 

