var WhatIsWindow = new Class({
	options:{title:'',width:250,text1:'',text2:'',founded:'',headquarters:'',stocksymbol:'',onClose:Class.empty},
	initialize:function(options){
		this.setOptions(options);
		this.closeWindow(); // por si ya habia una ventana abierta
		this.wIframeFixer = new Element('iframe', {
			'id' : 'wIframeFixer',
			'src' : "javascript:'';",
			'frameBorder' : '0',
			"styles":{
				"width":"100px",
				"background-color":"transparent",
				"border":"none",
				"position":"absolute",
				"filter":"alpha(opacity=10)",
				"opacity":".10",
				"z-index":"19998"
			}
		});
		this.wIframeFixer.injectInside(document.body);
		this.wShadow = new Element('div', {
			'id' : 'modalShadow',
			"styles":{
				"z-index":"19999"
			}
		});
		this.wShadow.injectInside(document.body);
		this.onClose = options.onClose;
		this.openWindow();
	},
	setShadowSize:function(){
		var coords = this.wCoords;
		this.wShadow.setStyles({
				"width" :coords.width.toInt()-2,
				"height":coords.height.toInt()-2
			});
		this.wIframeFixer.setStyles({
				"width" :coords.width.toInt()+3,
				"height":coords.height.toInt()+3
			});
	},
	setWindowPos:function(iNewWidth){
		var contentHeight=$('content').getStyle('height');
		if(iNewWidth){
			$("windowContent").setStyle("width",iNewWidth+'px');
		}
		if($("windowContent")){
			this.windowW.setStyle("width",$("windowContent").getStyle("width"));
		}
		var newTop = (window.getScrollTop() +((document.documentElement.clientHeight/2) - (contentHeight.toInt() / 2)));
		if(newTop < 0) newTop = 5;
		this.windowW.setStyles({
			"left" :(window.getScrollLeft() + ((window.getWidth() / 2) - (this.windowW.getStyle("width").toInt() / 2))) + "px",
			"top": newTop + "px"
		});
		this.wCoords = this.windowW.getCoordinates();
		var coords = this.wCoords;
		this.wShadow.setStyles({
			"top":coords.top.toInt()+5,
			"left":coords.left.toInt()+5
		});
		this.wIframeFixer.setStyles({
			"top":coords.top.toInt(),
			"left":coords.left.toInt()
		});
	},
	openWindow:function(){
		this.stopTimer = false;
		var wLoading = new Element('div', {
			'id' : 'windowLoading'
		});
		wLoading.setHTML('&nbsp;');
		var wWrap = new Element('div', {
			'id' : 'windowWrapper',
			"styles":{
				"background":"#f0f0f0",
				"padding":"20px",
				"text-align":"left",
				"border":"1px solid #ccc",
				"z-index":"20000",
				"width":"444px",
				"height":"300px"
			}
		});
		wWrap.setHTML('<div style="text-align:right;margin-top:-7px;"><img id="J_newModalClose" src ="/img/cpanel/settings/updated_close.gif" style="cursor:pointer;color:#color:#707070" title="Close"/></div>'+
			'<div style="text-align:center;"><b style="font-size:18px;">'+this.options.title+'</b></div>'+
			'<div id="WindowWhatIs">'+
			'<div style="padding-top:23px;"><span style="float:left;padding-right:18px;"><img id="is1" src="/img/global/ico_is1.gif" border=0></span><div style="margin:0">'+this.options.text1+'</div></div>'+
			'<div style="padding-top:35px;clear:both;"><div style="width:352px;float:left;clear:left;">'+this.options.text2+'</div><span style="float:right;margin-top:-11px;"><img id="is2" src="/img/global/ico_is2.gif" border=0></span></div>'+
			'<div style="clear:both;padding-top:6px;">'+
			'<ul id="WhatisList">'+
			'<li>'+this.options.founded+'</li>'+
			'<li>'+this.options.headquarters+'</li>'+
			'<li>'+this.options.stocksymbol+'<a href="/terms/about" id="popmore">More about sitesearch</a></span></li>'+
			'</ul>'+
			'</div>'+
			'</div>'
		);
		wWrap.injectInside(document.body);
		this.windowW = wWrap;
		this.windowAdjust();
		$('J_newModalClose').addEvent('click',function(){
			this.closeWindow();
		}.bind(this));
		window.addEvent("resize",function(){this.setWindowPos();}.bind(this));
	},
	closeWindow:function(){
		if($('modalShadow')){$('modalShadow').remove();}
		if($('windowWrapper')){$('windowWrapper').remove();}
		if($('wIframeFixer')){$('wIframeFixer').remove();}
		if(this.onClose){this.onClose();}
	},
	windowAdjust:function(iNewWidth){
		if(iNewWidth){this.setWindowPos(iNewWidth);}else{this.setWindowPos();}
		this.setShadowSize();
	}
});
WhatIsWindow.implement(new Options);
window.addEvent('domready', function(e){
	$$('a.showPopup').each(function(element){
		element.addEvent("click",function(e){
			showPopup(element, e);
		}.bindWithEvent(this));
	});
});
function showPopup(element,e){// 
	var WhatIsWindowModal = new WhatIsWindow({
		title:"What is sitesearch?",
		width: 515,
		text1:"<span style='font-weight:bold;'>SITESEARCH</span> is a place where you can share links from your favorite sites across the web. Users can save the most interesting links and recommend links so they appear on the front page for everyone to view.",
		text2:"<span style='font-weight:bold;'>SITESEARCH</span> also lets you keep in touch with your friends, upload your photos and videos, search the web, write your own articles, submit directory links to our directory and much more.",
		founded:"Founded: 2006",
		headquarters:"Headquarters: Nevada",
		stocksymbol:"Stock Symbol: STPC"
	});
}
