// -----------------------------------------------------------------------------------
//
//	Ticket Overlay Box v1
//     by Stephen Scholtz
//	2008-07-18 - Ripped off from code by Lokesh Dhakar - http://www.lokeshdhakar.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//	This code is VERY specific to my usage for the Soulpepper website.  It is not meant for release to the
//	public for use. Don't just plug this code into your site and then expect it to work. :P
//
// -----------------------------------------------------------------------------------

// VERY IMPORTANT
// The following files *must* be included above this file in order for flashvideobox to work:
// - extend-element.js
// - page-size-functions.js
// - show-hide-flash.js
// - show-hide-select.js
// These are in addition to the prototype and scriptaculous libraries

var TickOverlay = Class.create();


// CONFIG
// Overlay fade in time
var tickOverlayDuration = 0.2;
// TickOverlay message box internal contents
var tickOverlayMsg = "<img src=\"/images/performances/logo_handoff_sp.gif\" alt=\"Soulpepper\" id=\"handoff_logo\" />";
		tickOverlayMsg += "<p>You are now being connected to the Young Centre online box office to continue your purchase.</p>\n";
		tickOverlayMsg += "<p><a href='javascript:myTickOverlay.end()' id=\"handoff_cancel\">&lt;&lt; Return to Soulpepper</a> <a href=\"javascript:myTickOverlay.go()\" id=\"handoff_confirm\"><img src=\"/images/performances/but_handoff_continue.gif\" alt=\"Continue\" /></a></p>\n";
// Link that the overlay should eventually go to
var TickOverlayLink;

TickOverlay.prototype = {
	// Initialize function
	// Tags all the anchors inside the performance calendar with tick overlay starter, and creates
	// overlay and holder code
	initialize: function() {
		if (!document.getElementsByTagName){ return; }
		
		// Get all links inside the performance calendars, and arm them with the overlay start() code
		$$(".performance_calendar ul li a").each( function(anch) {
			anch.onclick = function() {
				myTickOverlay.start(anch);
				return false;
			}
		});
		
		// Creation of the overlay div
		var body = document.getElementsByTagName("body").item(0);
		var tickOverlay = document.createElement("div");
		tickOverlay.setAttribute('id','tickOverlay');
		tickOverlay.style.display = 'none';
		tickOverlay.onclick = function() { myTickOverlay.end(); }
		body.appendChild(tickOverlay);
		
		// Creation of 
		var tickHolder = document.createElement("div");
		tickHolder.setAttribute('id','tickHolder');
		tickHolder.style.display = 'none';
		// close Ticket Message if shadow overlay clicked; needed 'cuz this stretches the width of the page
		tickHolder.onclick = function(e) {
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'tickHolder') {
				myTickOverlay.end();
			}
		};
		body.appendChild(tickHolder);
		
		var tickMessageHolder = document.createElement("div");
		tickMessageHolder.setAttribute('id','tickMessageHolder');
		tickHolder.appendChild(tickMessageHolder);
		
		// Set the internal contents of the holder to the var
		$('tickMessageHolder').innerHTML = tickOverlayMsg;
		
	}, // end initialize()
	
	start: function(anch) {
		
		hideSelectBoxes();
		hideFlash();
		
		// Set global var to whatever the href is that I just clicked on
		TickOverlayLink = anch.href;
		
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('tickOverlay', arrayPageSize[1]);
		
		new Effect.Appear('tickOverlay', { duration: tickOverlayDuration, from: 0.0, to: 0.8 });
		
		// calculate top offset for the ticket window and display
		var arrayPageScroll = getPageScroll();
		// center message box on page
		var messageTop = arrayPageScroll[1] + (arrayPageSize[3]/2 - $('tickHolder').getHeight()/2);

		Element.setTop('tickHolder', messageTop);
		Element.show('tickHolder');
	}, // end start()

	go: function() {
		document.location.href = TickOverlayLink;
		return false;
	}, // end go()
	
	end: function() {
		Element.hide('tickHolder');
		new Effect.Fade('tickOverlay', { duration: tickOverlayDuration, afterFinish: function(){ showSelectBoxes(); showFlash();} });
	} // end end()
}

function initTickOverlay() { myTickOverlay = new TickOverlay(); }
Event.observe(window, 'load', initTickOverlay, false);