$(document).ready(function() {

	/* Change the big screen / small screen button to use javascript instead of reloading the page
	 * To prevent users from losing their session if the want to change to small screen mode
	 */

	var setBigScreen = function() {
		$("#bigscreen").hide();
		$("#smallscreen").show();
		$("#D_F_GameSection").css("height", "95%");	
		
		// If D_F_HudNotification dom element has been created fix it's position
		if ($("#D_F_HudNotification").size() > 0) {
			Disney.Friends.UI.HudNotification.reposition();
		}
	}
	var setSmallScreen = function() {
		$("#smallscreen").hide();
		$("#bigscreen").show();
		$("#D_F_GameSection").css("height", "480px");		

		// If D_F_HudNotification dom element has been created fix it's position
		if ($("#D_F_HudNotification").size() > 0) {
			Disney.Friends.UI.HudNotification.reposition();
		}
	}

	$("#bigscreen a").click(function() {
		setBigScreen();
		return false;
	});	
	$("#smallscreen a").click(function() {
		setSmallScreen();
		return false;
	});	
	
	/* Force clean up of the flash object during logoff or if the user closes the window */
	var flashCleanupNeeded = true;
	$('a').click(function() {
		// only handle logoff when the link will leave the page.
		if ($(this).attr("href").search(/#/) < 0) {
			var cpMovie = document.getElementById("club_penguin");
			cpMovie.handleLogOff($(this).attr("href"));
			flashCleanupNeeded = false;
			return false;
		}
	});
	$(window).unload(function() { 
		if (flashCleanupNeeded) {
			var cpMovie = document.getElementById("club_penguin");
			cpMovie.handleWindowUnload();
		}
	});
	
	if (window.location.href.search(/smallscreen/) >= 0 ) {
		setSmallScreen();
	} else {
		setBigScreen();	
	}
	$("#club_penguin").css("height", "100%");		
});
