
var s_account="intouchhumira,intouchabbottglobal";




var Shadowbox = {
	presets: {
		overlayClass: 'vpp-overlay',
		windowClass: 'vpp-win',
		loadingClass: 'vpp-loading',
		bottomOffset: 60
	},
	
	init: function() {
		if (this.isOpen) this.trash()
		this.doc = document
		this.ssize = this.doc.getScrollSize()
		
		this.isOpen = false
		this.isLoading = true
		this.brandingGSS = 0
		
		this.build()
		this.toggleOverlay(true)
		this.toggleListeners(true)
		
		this.toggleLoading(true)
		this.request = new Request({
			url: (applicationRoot) ? applicationRoot+'/Psoriasis/Vpp/vppcontent.aspx' : 'vppcontent.aspx',
			method: 'get'
		})
		this.request.addEvents({
			onSuccess: function(txt, xml) {								
				this.applyContent(txt)
			}.bind(this),
			
			onFailure: function(error) {
				this.hide()
				this.trash()
			}.bind(this)			
		})
		this.request.send()
		
	},
	
	build: function() {
		this.overlay = new Element('div', {
			'class': this.presets.overlayClass,
			styles: {display: 'none'},
			opacity: 0.7		
		})
		this.win = new Element('div', {
			'class': this.presets.windowClass,
			styles: {display: 'none'}					
		})		
		$(document.body).adopt(this.overlay, this.win)
				
		return this				
	},	
	
	applyContent: function(content) {
		var wincontent = content.substitute({
			closebtn: 'javascript:Shadowbox.hide();',
			flashholder: '<div id="vppFlashHolder"></div>'
		})
		this.toggleLoading()
		if (this.win) this.win.set('html', wincontent); this.placeFlash()
		
		this.brandElements = {}
		this.brandElements.common = new Array()		
		this.brandElements.common.combine($$('.isiToggle')).combine($$('.isiLinks')).combine($$('.vppIsiWrap'))
		this.brandElements.gss = $$('.gssToggle')		
		
		this.resize()
	},
	
	resize: function() {
		if (!this.isOpen) return
		
		var doc = $(document).getSize(), win = this.win.getSize(), ssize = $(document).getScrollSize()
		
		this.overlay.setStyles({
			width: (doc.x).toInt() + 'px',
			height: ((this.ssize.y > win.y) ? this.ssize.y : win.y).toInt() + this.presets.bottomOffset + 'px'
		})
		this.win.setStyles({
			left: ((doc.x - win.x) / 2).toInt() + 'px',
			top: 55 + 'px'
		})

	},	
	
	toggleLoading: function(state) {
		var fn = (state) ? 'addClass' : 'removeClass'
		
		if (this.overlay) this.overlay[fn](this.presets.loadingClass)
	},	
	
	toggleOverlay: function(state) {
		this.isOpen = state		
		var display = (state) ? '' : 'none'
		
		this.overlay.setStyle('display', display)
		this.win.setStyle('display', display)
		
		if (state) this.resize()
	},
	
	hide: function(e) {
		var stoppable = ($type(e) == 'event');
		if (stoppable) e.stop();	
					
		this.toggleListeners()
		this.toggleOverlay()
		
		this.trash()
		this.isOpen = false

	},
	
	toggleListeners: function(state) {
		var fn = (state) ? 'addEvent':'removeEvent'
		$(document).getWindow()[fn]('resize', this.resize.bind(this))
		//this.overlay[fn]('click', this.hide.bind(this))
	},
	
	trash: function() {
		this.overlay.destroy()
		this.win.destroy()
		
		this.overlay 		= null
		this.win	 		= null
		this.brandElements 	= null
		this.brandingGSS    = 0		
	},
	
	placeFlash: function() {
		var so = new SWFObject( applicationRoot + "/Psoriasis/VPP/base.swf", "base", "760", "565", "8", "");
			so.addParam("scaleMode","noscale");
			so.addParam("base", applicationRoot + "/Psoriasis/VPP/");	
			so.addParam("align","TL");
			so.addParam("wmode","transparent");
			so.addParam("allowScriptAccess","sameDomain");
			so.addParam("accountName", "intouchhumira");
			so.addParam("","/Psoriasis/VPP/report.aspx");	
			so.write('vppFlashHolder');	
	},
	
	showBranding: function(state) {
		var fn = (state) ? 'show' : 'hide'
		this.brandElements.common.each(function(el) {
			el[fn]()
		})
		if (this.brandingGSS == 3) {
		    this.brandElements.gss.each(function(el) {
			    el[fn]()
		    })		
		}
		else {
		    this.brandElements.gss.each(function(el) {
			    el.hide()
		    })		
		}
		
		this.resize()
		this.brandingGSS = this.brandingGSS + 1
	}	
	
}



function showVPP() {
	Shadowbox.init()
}
function hideVPP() {
	Shadowbox.hide()
}

function toggleBranding(state) {
	try {Shadowbox.showBranding(state);} catch(e) {}	
}


