$().ready(function() {

	// Activate showcase plugin
	$("#showcase-widget").showcase({
		speed: 5000,
		transitionTime: 1500,
		controls: true,
		autoPlay: true	
	});
	
	/*
	// House of Discipline Overlay
	*/
	var bodyWidth = $("body").width();
	var hodWidth = 600;
	var hodHeight = 530;
	var hodY = 100;
	var shadowSpread = 12;
	
	// Bind click events to House of Discipline logo
	$("#house-of-discipline").click(function(event) {
	
		// Remember click coordinates
		var pageX = event.pageX;
		var pageY = event.pageY;
		
		// Append (invisible) #hod-overlay
		$("<div id='hod-overlay'></div>").appendTo("body");
		
		// Init css styles for #hod-overlay
		$("#hod-overlay").css({
			zIndex: 100,
			position: 'absolute',
			top: 0,
			left: 0,
			width: '100%',
			height: '100%',
			opacity: 0,
			backgroundColor: '#000000'
		});
		
		// Append (invisible) #hod-shadow
		$("<div id='hod-shadow' class='ui-corner-all'></div>").appendTo("body");
		
		// Init css for #hod-shadow
		$("#hod-shadow").css({
			zIndex: 101,
			opacity: 0,
			backgroundColor: '#000000',
			position: 'absolute',
			width: function() {
				return ( hodWidth + (shadowSpread*2) );
			},
			height: function() {
				return ( hodHeight + (shadowSpread*2) );
			},
			top: function() {
				return ( hodY - shadowSpread);
			},
			left: function() {
				return ( (bodyWidth/2) - (hodWidth/2) - (shadowSpread) );
			}
		});
				
		// Append (invisible) #hod
		$("<div id='hod' class='ui-corner-all'><button id='hod-close'>Close</button></div>").appendTo("body");
		
		// Init css styles for #hod
		$("#hod").css({
			zIndex: 102,
			opacity: 0,
			width: 0,
			height: 0,
			position: 'absolute',
			top: event.pageY,
			left: event.pageX,
			backgroundColor: '#ffffff'
		});
		
		// Init #hod-close button
		$("#hod-close").css({
			position: 'absolute',
			top: '6px',
			right: '6px'
		});
		$("#hod-close").button({
			text: false,
			icons: {
				primary: "ui-icon-close"
			}
		});
		$("#hod-close").click(function(){
			// Fade #hod
			$("#hod").effect("puff", 1000, function(){
				$("#hod").remove();
			});
			// Remove #hod-shadow
			$("#hod-shadow").remove();
			// Animate #hod-overlay
			$("#hod-overlay").animate(
				{
					opacity: 0,
					backgroundColor: '#ffffff'
				},
				2000,
				function() {
					$("#hod-overlay").remove();
				}
			);
			
		});
		
		// Fetch content for "HOD" div
		$.get( "/hod/index.html", function(data) {
			$("#hod").append(data);
		});
		
		// Animate overlay
		$("#hod-overlay").animate(
			{
				opacity: 0.95,
				backgroundColor: "#bd9408"
			},
			1000,
			function() {
				// animation complete
			}
		);
		
		// Animate #hod
		var hodLeft = (bodyWidth/2) - (hodWidth/2)
		$("#hod").animate(
			{
				top: hodY,
				left: hodLeft,
				width: hodWidth,
				height: hodHeight,
				opacity: 1
			},
			1000,
			function() {
				// Animate #hod-shadow
				$("#hod-shadow").animate(
					{
						opacity: 0.3
					},
					100
				);
			}
		);
		
	});
	
	/*
	// END: House of Discipline Overlay
	*/
	
});
