var IOptims = Class.create({
    initialize: function initialize(opt_type) {
	    this.iOpt_iframe  = new Element('iframe', {id:'iOpt_frame',name:'iOpt_frame',width:"420",height:"225",frameborder:"0",scrolling:"no",marginheight:"0",marginwidth:"0",src:"http://www.inroads.us/iopt/"});	
	
		this.container    = new Element('div', {id:'iOpt_cont', style:'display:none'});
		this.header       = new Element('div', {id:'iOpt_header'});
		this.content      = new Element('div', {id:'iOpt_content'});
		this.opt_img_div  = new Element('div', {id:'iOpt_img'});
		this.header_text  = new Element('div', {className:'iOpt_header_text'});
		this.header_close = new Element('div', {className:'iOpt_header_close'});	
		this.footer       = new Element('div', {id:'iOpt_footer'});	
		
		this.close_img    = new Element('img', {src:'http://www.inroads.us/iopt/images/map_close.gif',title:"Close"});
		this.inroads      = new Element('img', {src:'http://www.inroads.us/iopt/images/inroads-map.gif',title:"Inroads, LLC",style:"vertical-align:top"});
		this.position_right = false;
		
	    this.anchor_ele   = '';
	    this.inject();
    },
    inject: function inject() {
    	this.header_text.insert("Optimized by Inroads");
		this.header_close.insert(this.close_img); 
		this.header.insert(this.header_close); 	
		this.header.insert(this.header_text); 
		this.header.insert(this.header_text); 
        
		this.content.insert(this.iOpt_iframe);
		
		this.footer.insert(this.inroads);
		
		this.container.insert(this.header); 
		this.container.insert(this.content); 	
		this.container.insert(this.footer);
    	
		dbody.insert(this.container); 
		this.close_img.observe('click',this.hide);
    },
    show: function show(e) {
       ele = Event.element(e);
       
       this.anchor_ele = ele;
       position = Element.cumulativeOffset(ele);
       
       if(this.position_right) {
	       this.container.style.top = (position.top-this.container.getHeight()-5)+"px";
	       this.container.style.left = (position.left-3)+"px";
       }
       else
       {
	       this.container.style.top = (position.top-this.container.getHeight())+"px";
	       this.container.style.left = (position.left-this.container.getWidth()+ele.getWidth())+"px";
       }
       
       this.container.show();
    },
    reposition: function reposition(e) {
        ele = this.container;

        position = Element.cumulativeOffset($('IOpt'));
        if(this.position_right) {
	        ele.style.top = (position.top-this.container.getHeight()-5)+"px";
	        ele.style.left = (position.left-3)+"px";
        }
        else
        {
	        ele.style.top = (position.top-this.container.getHeight()-10)+"px";
	        ele.style.left = (position.left-ele.getWidth()+$('IOpt').getWidth())+"px";
        }
     },
    hide: function hide(e)
    {
       $('iOpt_cont').hide();
    }    
});

