$E = YAHOO.util.Event;
$D = YAHOO.util.Dom;
$ = $D.get;

YAHOO.namespace('info_panel');
YAHOO.info_panel = function()
{
	
    var link;
    
    var panelId = "info-panel";
    // var imageId = "primary_image_id";
    
    var localPanel = new YAHOO.widget.Panel(panelId, {
					modal: true,			
			    	fixedcenter: false,
					width:"250px",  
					constraintoviewport: false,  
					underlay:"shadow",  
					close:true,
					y:0,
					x:5,
					visible: false,  
					draggable: false,
					zindex: 200,
					effect: {effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3 }
               } 
            );
      
      return {
        panel : localPanel,
        
        init : function() {
        	
            var infoLinks = $D.getElementsByClassName('info-bubble');
			$E.on(infoLinks,'click', YAHOO.info_panel.show);
                        
            var generatedHtml = "<div id=\"loader\">Loading</div>";
            YAHOO.info_panel.panel.setBody(generatedHtml); 
            YAHOO.info_panel.panel.setHeader('<a id="hide-lightbox" href="#">close</a>');
            //YAHOO.info_panel.panel.setHeader("<p>header html</p>");
            YAHOO.info_panel.panel.setFooter('&nbsp;');
            YAHOO.info_panel.panel.render(document.body);
            $E.on('hide-lightbox', 'click', YAHOO.info_panel.hide);
            
        },
        
        show : function(e) {
            $E.stopEvent(e);
            var url = this;
            YAHOO.info_panel.panel.configContext
			// format of id is "i-xxx" where xxx is the content_id of the choice record            
            var infoId = url.id.substr(2,url.id.length);
			var regex = /^\d+$/;
			if(regex.test(infoId)) {
				var infoContentId = parseInt(url.id.substr(2,url.id.length));		
			} else {
				var infoContentId = url.id.substr(2,url.id.length);
			}
            
            YAHOO.info_panel.panel.cfg.setProperty("context", [url.id,'tr','tl']);
            YAHOO.info_panel.panel.setBody(info[infoContentId]);
            YAHOO.info_panel.panel.show();
            
        },      
              
        hide : function(e) {
            $E.stopEvent(e);
            YAHOO.info_panel.panel.setBody('&nbsp;');
            YAHOO.info_panel.panel.hide();
        }
      }
            
}();


YAHOO.util.Event.onDOMReady(YAHOO.info_panel.init,'',YAHOO.info_panel);