/*
	Copyright Code Computerlove Ltd 2009
	Build: 1.1.0.22
	Date: 10/09/2009 11:48:10
*/

(function($j){
	
	var ModalNegYOffset = 300;
	var ModalNegXOffset = -159;
	
	Code.registerNamespace('Website.Pages');
	
	Website.Pages.Home = Code.Class.extend({
		
		init: function(){},

		jOverlay: null,
		jOverlayClicker: null,
		jModal: null,
		
		documentReady: function(){
			
			$j('.flashVideo').click(function(){
				Website.Pages.Home.showFlashVideo();
				Website.Pages.Home.loadPageContent(Code.resolveUrl('~/Overlays/WorldClassRegion.html'));
				Website.Pages.Home.windowResize();
				return false;
			 });
			 
			$j('a.js-roadmap-link').click(function(){
				Website.Components.RoadMap.show();
				return false;
			});
		},
		
		showFlashVideo: function(){

			if (Website.Pages.Home.jOverlay == null){
				Website.Pages.Home.jOverlay = $j('<div id="Overlay" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></div>');
				
				
				// Create the Clicker layer
				Website.Pages.Home.jOverlayClicker = $j('<div id="OverlayClicker" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></div>');
				Website.Pages.Home.jOverlayClicker
					.appendTo(Website.Pages.Home.jOverlay)
					.click(function(){
						Website.Pages.Home.hideFlashVideo();
					});
					
				Website.Pages.Home.jOverlay
				.bgiframe()
				.hide()
				.css('opacity', .5)
				.appendTo('body');
			}
			
			
			Website.Pages.Home.jOverlay.show();
			$j('#Overlay').click(function(){
				$j('.close').click(function(){
					Website.Pages.Home.hideFlashVideo();
					return false;
				});													
			});
			
			if (Website.Pages.Home.jModal == null){
				// Add new Modal window to the DOM
				var o = $j('#ContentPrimary').offset();
				var ModalPosX = (o.left - ModalNegXOffset);
				var ModalPosY = (o.top - ModalNegYOffset);
				Website.Pages.Home.jModal = $j('<div id="Modal" style="display: none; position: absolute; left:'+ModalPosX+'px; top: '+ModalPosY+'px; z-index:5000;"></div>');
				Website.Pages.Home.jModal.appendTo('body');
			}
			
			Website.Pages.Home.jModal.fadeIn();
		},
		
		hideFlashVideo: function(){
			// Removes Modal from the DOM
			$j(Website.Pages.Home.jModal).fadeOut('fast',function(){
				$j('#Modal').hide();
			});
			
			// Removes the overlay from the DOM
			$j(Website.Pages.Home.jOverlay).fadeOut('fast',function(){
					Website.Pages.Home.jOverlay.hide();
					$j('#Overlay').hide();
			});
		},
		
		loadPageContent: function(requestedUrl){
			$j.ajax({
				type: "GET",
				url: requestedUrl,
				dataType: "html",
				success: function(data, textStatus){
					// Sets the HTML of the Modal to that of the external URL
					Website.Pages.Home.jModal.html(data);
					
					// Adds the bottom to the modal
					$j('.modal', Website.Pages.Home.jModal).append('<div class="bottom"></div>');
					
					// Attaches the close function
					$j('.close').click(function(){
						Website.Pages.Home.hideFlashVideo();
						return false;
					});		
				}			
			});
		},
		
		generateFlashContent: function(){
		
			$j('#FlashVideo').flash(
				{ src: Code.resolveUrl('~/_Client/Flash/WorldClassRegion.swf'),
					width: 637,
					height: 385,
					allowFullScreen: "true",
					bgcolor: '#000000',
					wmode: "opaque" },
				{ version: 9 }
			);
			
		},
		
		windowResize: function(){
			$j(window).resize(function(){
				var o = $j('#ContentPrimary').offset(); 
				var ModalPosX = (o.left - ModalNegXOffset); 
				var ModalPosY = (o.top - ModalNegYOffset);
				$j('#Modal').css({'left': ModalPosX, 'top': ModalPosY});
			});
		}
		
	});
	
	Website.Pages.Home = new Website.Pages.Home();

	$j().ready(function(){
		Website.Pages.Home.documentReady();
	});
	
})(jQuery);
