HELP_POPUP = null;

var HelpPopup = new Class({
	options: {
		poptitle:'Header goes here :)',
		htmlsource:null,
		popcont:null,
		popwidth:200,
		pad:7,
		bgwidth:800,
		bgheight:786,
		offsetleft:0		
	},
	initialize: function(options){
		if(options){
			this.setOptions(options);
		}
		this.popwraper=null;
		this.iframe=null;
		this.popbody=null;
		this.poptitle=null;
		this.imgclose=null;
		this.popleft=null;
		this.poptop=null;
		this.popright=null;
		this.popbottom=null;		
		this.popleftwrap=null;		
		this.poptopwrap=null;
		this.poprightwrap=null;
		this.popbottomwrap=null;
		this.poparrow=null;
		this.poparrowwrap=null;
		this.pngfilter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/page/images/popup.png"),sizingMethod="crop"';
		this.popbg='url(/page/images/popup.png)';
		document.addEvent('click',this.documentClose.bindWithEvent(this));
	},
	start: function(ele, options){
		ele = $(ele);
		if(ele){
			ele.setStyle("cursor", "pointer");
			ele.removeEvents("click");
			ele.addEvent('click', this.create.bindWithEvent(this, options));
		}
	},
	create: function(e, options){
		if($('arrow')){$('arrow').remove();this.poparrowwrap=null;this.poparrow=null}
		if(options.offsetleft){
			this.options.offsetleft = options.offsetleft;
		}else{
			this.options.offsetleft = 0;
		}
		this.options.htmlsource = null;
		this.options.popcont = null;
		if(options){
			this.setOptions(options);
		}
		this.element = e.target;
		this.createwraper();
		this.createbody();	
		this.createshape("popleft","popleftwrap",'left','_left','bg_left');
		this.createshape("poptop","poptopwrap",'top','_top','bg_top');
		this.createshape("popright","poprightwrap",'right','_right','bg_right');
		this.createshape("popbottom","popbottomwrap",'bottom','_bottom','bg_bottom');
		this.popwraper.setStyle('top',this.element.getTop()-this.popbody.offsetHeight-2*this.options.pad);		
		this.popwraper.setStyle("z-index", 100);					
		var bwidth=(window.ie)?(document.documentElement.offsetWidth-21):getWidth();
		this.ofBrowserWidth=this.popwraper.getLeft()+this.popwraper.offsetWidth-bwidth;
		var currentpopLeft=this.popwraper.getLeft();
		var newpopLeft=(currentpopLeft-this.ofBrowserWidth);
		if(this.popwraper.getTop()<0){		
			this.popwraper.setStyle('top',this.element.getTop()+2*this.options.pad);
			this.createshape("poparrow","poparrowwrap",'arrowtop','_arrowtop','bg_arrowtop');
			if(this.poparrowwrap)this.poparrowwrap.setProperty('id','arrow');
			else this.poparrow.setProperty('id','arrow');
			if(this.ofBrowserWidth>0){
				this.popwraper.setStyle("left", newpopLeft);					
				$('arrow').setStyle('left',this.ofBrowserWidth);
				var differ=getScrollWidth()-getWidth();
				if(differ>0&&(window.webkit||window.opera)){
					this.popwraper.setStyle("left", newpopLeft-differ);					
					$('arrow').setStyle('left',this.ofBrowserWidth+differ);
				}
			}	
		}
		else{
			this.createshape("poparrow","poparrowwrap",'arrow','_arrow','bg_arrow');
			if(this.poparrowwrap)this.poparrowwrap.setProperty('id','arrow');
			else this.poparrow.setProperty('id','arrow');
			if(this.ofBrowserWidth>0){
				this.popwraper.setStyle("left", newpopLeft);
				$('arrow').setStyle('left',this.ofBrowserWidth);
			}
		}
		if(window.ie&&this.popwraper) this.createiframefor(this.popwraper);
		this.popwraper.setStyle("visibility", "visible");
		if(this.iframe) this.iframe.setStyle("visibility", "visible");
	},
	documentClose: function(e){	
		e = new Event(e);
		var target = $(e.target);
		if(target != this.element){
			while(target.getProperty("id") != "popwraper"){
				if(target.tagName == "HTML" || target.getParent()==null){
					break;
				}
				target = target.getParent();
			}
			if(target.getProperty("id") == "popwraper"){
				return;
			}			
			this.close();	
		}
	},
	close: function(e){
		if(this.popwraper) this.popwraper.setStyle("visibility", "hidden");
		if(this.iframe) this.iframe.setStyle("visibility", "hidden");
	},
	createwraper: function(){
		if(!this.popwraper) {
			this.popwraper=new Element('div');
			this.popwraper.setProperty("id","popwraper");
			this.popwraper.injectInside(document.body);
		}
		this.popwraper.setStyles({
			position:'absolute',
			left:this.element.getLeft() + this.options.offsetleft,
			'z-index':10,
			'font-size':'11px',
			width:this.options.popwidth
		});
		
	},
	createiframefor: function(ele){
		if(!this.iframe) {
			this.iframe=new Element('iframe');
			this.iframe.setProperty("src", "javascript:''");
			this.iframe.injectInside(document.body);
		}
		this.iframe.setStyles(ele.getStyles('left','top'))
		this.iframe.setStyles({
			position:'absolute',
			'z-index':ele.getStyle('z-index')-1,
			width:ele.offsetWidth,
			height:this.popbody.offsetHeight+2*this.options.pad,
			opacity:0.01
		});
		
	},
	createbody: function(){
		if(!this.popbody){
			this.popbody=new Element('div');
			this.popbody.setProperty('id','popbody');
			this.popbody.injectInside(this.popwraper);
		}
		this.popbody.setStyles({
			width:this.options.popwidth-2*this.options.pad,
			top:this.options.pad,
			left:this.options.pad,
			background:'#f8f8e2',
			position:'absolute'	
		});
		if(!this.popcont){
			this.popcont=new Element('div');
			this.popcont.setProperty('id','popcont');
			this.popcont.injectInside(this.popbody);
		}		
		this.popcont.empty();
		if(this.options.htmlsource){		
			var tempcontent = $(this.options.htmlsource).clone();
			tempcontent.setStyle("display","");
			tempcontent.injectInside(this.popcont);
		}else if(this.options.popcont){
			this.popcont.setHTML(this.options.popcont);
		}
		this.popcont.setStyles({
			background:'#ffffff',
			margin:2,
			padding:3,
			border:'1px solid #b3b3a6'
		})
		if(!this.poptitle){
			this.poptitle=new Element('div')
			this.poptitle.setProperty('id','poptitle');
			this.poptitle.injectTop(this.popbody);			
		}
		this.poptitle.empty();
		this.poptitle.setText(this.options.poptitle);
		this.poptitle.setStyles({
			'margin-left':1,
			'font-weight':'bold'
		})
		this.imgclose=new Element('div');				
		this.imgclose.setStyles({
			background:this.popbg+' no-repeat -17px bottom',
			width:12,
			height:12,
			float:'right',
			cursor:'pointer'
		});
		this.imgclose.injectTop(this.poptitle);
		this.imgclose.addEvent('click', this.close.bindWithEvent(this));
	},
	createshape: function(ele,elewrap,style,_style,bgstyle){	
		if(!eval("this."+ele)) {
			var theID = ele;
			eval("this."+ele +"=new Element('div')");
			ele = eval("this."+ele);
			ele.setProperty("id", theID);
			if(!window.ie){
				ele.injectInside(this.popwraper);
			}
		}else{
			ele = eval("this."+ele);
		}
		ele.setStyles(this.setstyles(style));
		ele.setStyles({position:'absolute'});
		if(window.ie){
			if(!eval("this."+elewrap)) {
				eval("this."+elewrap +"=new Element('div')");
				elewrap = eval("this."+elewrap);
				elewrap.injectInside(this.popwraper);
				ele.injectInside(elewrap);
			}else{
				elewrap = eval("this."+elewrap);
			}
			//if(!elewrap) elewrap=new Element('div');
			elewrap.setStyles(this.setstyles(style));
			elewrap.setStyles({position:'absolute',overflow:'hidden'});
			ele.setStyles(this.setstyles(_style));
			ele.setStyles({position:'relative',filter:this.pngfilter});
			
		}
		else {
			ele.setStyles({'background-image': this.popbg,'background-repeat':'no-repeat'})
			ele.setStyles(this.setstyles(bgstyle));
		}	
	},	
	setstyles: function(ele){		
		switch(ele){
			
			case 'left': 
				return {
					'width':this.options.pad,
					'height':this.popbody.offsetHeight+this.options.pad,
					left:0,
					top:0
				};
				break;
			case '_left':
				return{
					left:0,
					top:0
				};
				break;	
			case 'bg_left':
				return{
					'background-position': '0 0'
				};
				break;
			
			
			case 'top':
				return{
					width:this.options.popwidth-this.options.pad,
					height:this.options.pad,
					left:this.options.pad,
					top:0
				};
				break;
			case '_top':
				return{
					left:-this.options.bgwidth+this.popbody.offsetWidth+this.options.pad,
					top:0
				};
				break;
			case 'bg_top':
				return{
					'background-position': (this.popwraper.offsetWidth-this.options.bgwidth-this.options.pad)+'px 0'
				};
				break;	
				
				
			case 'right':
				return{
					width:this.options.pad,
					height:this.popbody.offsetHeight+this.options.pad,
					left:this.options.popwidth-this.options.pad,
					top:this.options.pad
				};
				break;
			case '_right':
				return{
					left:this.options.pad-this.options.bgwidth,
					top:this.options.pad+this.popbody.offsetHeight-this.options.bgheight
				};
				break;	
			case 'bg_right':
				return{
					'background-position': (this.options.pad-this.options.bgwidth)+'px '+(this.options.pad+this.popbody.offsetHeight-this.options.bgheight)+'px'
				};
				break;
				
				
			case 'bottom':
				return{
					width:this.options.popwidth-this.options.pad,
					height:this.options.pad,
					left:0,
					top:this.popbody.offsetHeight+this.options.pad
				};
				break;
			case '_bottom':
				return{
					left:0,
					top:this.options.pad-this.options.bgheight
				};
				break;	
			case 'bg_bottom':
				return{
					'background-position': '0 '+(this.options.pad-this.options.bgheight)+'px'
				};
				break;	
				
				
			case 'arrow':
				return{
					width:16,
					height:13,
					left:0,
					top:this.popbody.offsetHeight+2*this.options.pad-3,
					'z-index':12
				};
				break;	
			case '_arrow':
				return{
					left:0,
					top:-this.options.bgheight
				};
				break;	
			case 'bg_arrow':
				return{
					'background-position': '0 '+(-this.options.bgheight)+'px'
				};
				break;
			
			case 'arrowtop':
				return{
					width:16,
					height:13,
					left:0,
					top:-12,
					'z-index':12
				};
				break;	
			case '_arrowtop':
				return{
					left:-32,
					top:-this.options.bgheight
				};
				break;	
			case 'bg_arrowtop':
				return{
					'background-position': '-32px '+(-this.options.bgheight)+'px'
				};
				break;	
			}
	}
});

HelpPopup.implement(new Options);

function getHelpPopupInstance(){
	if(HELP_POPUP == null){
      HELP_POPUP = new HelpPopup();
    }
    return HELP_POPUP;
}

ABOUT_BOX = null;

var AboutBox = new Class({
	options: {
		title:'About The Admissions Profile',
		htmlcont:'Some text goes her that talks about the admmissions profile and explains what it is and why it can be useful and informative for the user to complete his or her own profile as soon as possible.',
		width:230,
		offsetx:2,
		offsety:3
	},
	initialize: function(options){
		if(options){
			this.setOptions(options);
		}
		this.divpopup=null;
		this.shadow=null;
		this.coveriframe=null;
		document.addEvent('click',this.hide.bindWithEvent(this));
	},
	
	start: function(ele,options){
		ele = $(ele);
		if(ele){
			ele.setStyle("cursor", "pointer");
			ele.removeEvents("click");
			$(ele).addEvent('click', this.display.bindWithEvent(this, options));
		}
		
	},
	create: function(e){
		this.element = e.target;	
		if(!this.divpopup){
			this.divpopup=new Element('div');
			this.divpopup.setProperty("id", "aboutBox");
			this.divpopup.addClass('aboutbox');			
			this.divpopup.injectInside(document.body);
			this.shadow=new Element('div');
			this.shadow.injectInside(document.body);			
		}	
		this.divpopup.setStyle('visibility','visible');
		this.shadow.setStyle('visibility','visible');		
		if(window.ie){
			if(!this.coveriframe){
				this.coveriframe=new Element("iframe");		
				this.coveriframe.setProperty("src", "javascript:''");	
				this.coveriframe.injectInside(document.body);
			}		
			this.coveriframe.setStyle('visibility','visible');			
		}
		
	},
	hide: function(e){
		if(e.target != this.element){
			if(e.target.getProperty && 
				(e.target.getProperty("id") == "aboutBox"
				  ||e.target.getProperty("id") == "aboutTitle"
				  ||e.target.getProperty("id") == "aboutContent")){
				return;
			}
			if(this.divpopup) this.divpopup.setStyle('visibility','hidden');
			if(window.ie && this.coveriframe) this.coveriframe.setStyle('visibility','hidden');
			if(this.shadow) this.shadow.setStyle('visibility','hidden');
		}		
	},	
	display: function(e,options){
		if(options){
			this.setOptions(options);
		}
		this.create(e);
		this.createtitle(this.options.title).injectInside(this.divpopup);		
		this.createcontent(this.options.htmlcont).injectInside(this.divpopup);
		if(this.element.getLeft()>=this.options.width) this.leftpos=this.element.getLeft()+this.element.offsetWidth-this.options.width-10;
		else this.leftpos=this.element.getLeft();			
		this.toppos=this.element.getTop()+this.element.offsetHeight;
		this.divpopup.setStyles({
				width:this.options.width,
				left:this.leftpos+this.options.offsetx,
				top:this.toppos+this.options.offsety,
				"visibility": "visible"
		});	
		if(window.ie && this.coveriframe){
			this.coveriframe.setStyles({
				width:this.options.width,
				height:this.divpopup.clientHeight,
				left:this.leftpos+this.options.offsetx,
				top:this.toppos+this.options.offsety,
				opacity:0.1,
				'z-index':11,
				'position':'absolute',
				"visibility": "visible"
			});
		}
		this.shadow.setStyle('visibility','visible');					
		this.shadow.setStyles({
			height:this.divpopup.clientHeight,
			width:this.divpopup.clientWidth,
			left:this.leftpos+4+this.options.offsetx,
			top:this.toppos+4+this.options.offsety,
			'background-color': '#999',
			position:'absolute',
			opacity:0.8
		});			
	},
	createtitle: function(data){
		if(!this.title){
			this.title = new Element('div');
			this.title.setProperty("id", "aboutTitle");
			this.title.addClass('abouttitle');
		}	
		this.title.empty();	
		this.title.setText(this.options.title);
		this.closebtn=new Element('img');
		this.closebtn.setProperty('src','../page/images/admissions/aboutclose.gif');
		this.closebtn.addEvent('click',this.hide.bindWithEvent(this))
		this.closebtn.injectTop(this.title)		
		return this.title;
	},
	createcontent: function(html){
		if(!this.htmlcont){
			this.htmlcont = new Element('div');
			this.htmlcont.setProperty("id", "aboutContent");
			this.htmlcont.addClass('aboutcont')
		}		
		this.htmlcont.setHTML(this.options.htmlcont);
		return this.htmlcont;
	}
	
});
AboutBox.implement(new Options);

function getAboutBoxInstance(){
	if(ABOUT_BOX == null){
      ABOUT_BOX = new AboutBox();
    }
    return ABOUT_BOX;
}