var Popup = new Class({
	options: {
		title:[],
		href:[],
		htmlcont:'',
		offsetx:2,
		offsety:3,
		shadowoffset:4,
		overflown: []
	},
	initialize: function(ele, options){
		if(options){
			this.setOptions(options);
		}
		this.element=$(ele);
		this.divpopup=null;
		this.coveriframe=null;
		this.shadow=null;
		this.bound = {			
			"mouseover": this.display.bindWithEvent(this),
			"mouseout": this.hide.bindWithEvent(this)
		};
	},
	
	start: function(){
		this.element.addEvent('mouseover', this.bound.mouseover);
		//this.element.addEvent('mouseout', this.bound.mouseout);
	},
	
	getDivPopup: function(){
		var tooltips = $$('.rollovertooltip');
		if(tooltips.length > 0){
			this.divpopup = tooltips[0];
		}
		var rollovershadows = $$('.rollovershadow');
		if(rollovershadows.length > 0){
			this.shadow = rollovershadows[0];
		}		
		
		var coveriframes = $$('.rollovertooltipframe');
		if(coveriframes.length >0){
			this.coveriframe = coveriframes[0];
		}
	},
	
	create: function(e){
		var event = new Event(e);	
		this.getDivPopup();
		if(!this.divpopup){			
			this.divpopup=new Element('div');
			this.divpopup.addClass('rollovertooltip');				
			this.divpopup.injectInside(document.body);
			//this.divpopup.addEvent('mouseover',this.bound.mouseover)
			//this.divpopup.addEvent('mouseout', this.bound.mouseout);
			
			this.shadow=new Element('div');
			this.shadow.addClass('rollovershadow');
			this.shadow.injectInside(document.body);
		}		

		
		this.leftpos=this.element.getLeft(this.options.overflown);
		
		this.toppos=this.element.getTop(this.options.overflown)+this.element.offsetHeight;
		
		this.divpopup.empty();	
		this.generateHTML(this.options).injectInside(this.divpopup);		
		this.divpopup.setStyles({
			/*width:this.options.width,*/
			left:this.leftpos+this.options.offsetx,
			top:this.toppos+this.options.offsety
		});	
		
		this.shadow.setStyles({
			height:this.divpopup.clientHeight,
			width:this.divpopup.clientWidth,
			left:this.leftpos+ this.options.shadowoffset +this.options.offsetx,
			top:this.toppos+ this.options.shadowoffset +this.options.offsety,
			'background-color': '#999',
			position:'absolute',
			opacity:0.8
		});

		if(window.ie){
			if(!this.coveriframe){	
				this.coveriframe=new Element("iframe");	
				this.coveriframe.addClass('rollovertooltipframe');	
				this.coveriframe.setProperty("src", "javascript:''");
				this.coveriframe.injectInside(document.body);								
			}
			this.coveriframe.setStyles({
				width:this.divpopup.clientWidth,
				height:this.divpopup.clientHeight,
				left:this.leftpos+this.options.offsetx,
				top:this.toppos+this.options.offsety,
				opacity:0.1,
				'z-index':99,
				'position':'absolute',
				'background-color':'#fff'
			});
		}
	},
	hide: function(){
		this.divpopup.setStyle('visibility','hidden');
		if(this.coveriframe){
			this.coveriframe.setStyle('visibility','hidden');		
		}
		this.shadow.setStyle('visibility','hidden');
	},	
	display: function(e){
		try{
			this.create(e);
		}catch(ex){
			return;
		}
		this.divpopup.setStyle('visibility','visible');
		if(this.coveriframe){
			this.coveriframe.setStyle('visibility','visible');		
		}
		this.shadow.setStyle('visibility','visible');
		
		var tempCapture = null;
		if(this.element.setCapture){
			this.element.setCapture();
			tempCapture = this.element;
		}else if(window.captureEvents){
			window.captureEvents(Event.MOUSEOUT);
			tempCapture = window;
		}
		
		var release = function(){
			if(this.element.releaseCapture){
				this.element.releaseCapture();
			}else if(window.releaseEvents){
				window.releaseEvents(Event.MOUSEOUT);
			}
			this.hide();
			tempCapture.removeEvents('mouseout');
		}
		tempCapture.addEvent('mouseout', release.bind(this));
	},
	generateHTML: function(data){
	}
	
});

Popup.implement(new Options);

var DesPopup = Popup.extend({
	start: function(){
		var data = this.element.getProperty("rel");
		if(data && data.trim() != ""){
			this.parent();
		}
	},
	generateHTML: function(data){
		var htmlcont = new Element('div');		
		data = this.element.getProperty("rel");
		htmlcont.setHTML(data);
		return htmlcont;
	}
});