HH.World = {};


HH.World._game_config = {
	1: {
		swf: '/static/flash/games/main.swf'
	},
	2: {
		swf: '/static/flash/games/game_2/hh29_nohi.swf'
	},
	3: {
		swf: '/static/flash/games/HorridHenry2.swf'
	},
	4: {
		swf: '/static/flash/games/halloween.swf',
		width: 550,
		height: 450
	},
	5: {
		swf: '/static/flash/games/spidergrabpreloader.swf',
		width: 720,
		height: 400
	},
	6: {
		swf: '/static/flash/games/christmas09.swf',
		width: 700,
		height: 450
	}
};


HH.World.init = function() {
	Common.log('HH.World.init() called');
	jQuery('#main').before('<div id="world_container"></div>');
	jQuery('#world_container').addClass('flash').height('464px').html('<div id="world_content"><div id="world"><div id="world_flash"></div></div></div>');
	jQuery('#world_content').height('460px');
	HH.flash({
		id: 'world_flash',
		src: '/static/flash/world/holder.swf',
		width: '100%',
		height: 460,
		express_install: '/static/flash/express_install.swf',
		flash_vars: {
			lang: Cube.lang.currentLanguage(),
			is_ie: jQuery.browser.msie
		},
		transparent: true
	});
	jQuery('body').append('<div id="fancybox_hidden" style="display: none;"><a class="overlay-flash iframe" id="fancy_clicker" href="#"></a></div>');
};


HH.World.game = function(n) {
	Common.log('HH.World.game(' + n + ') called');
	if (!HH.World._game_config[n]) {
		return;
	}
	if (jQuery.browser.msie) {
		jQuery('#flash_world_flash').css('visibility', 'hidden');
	}

	// Defaults
	var width  = 620;
	var height = 520;

	// Overrides
	if (HH.World._game_config[n]['width']) {
		width = HH.World._game_config[n]['width'];
	}
	if (HH.World._game_config[n]['height']) {
		height = HH.World._game_config[n]['height'];
	}

	var url = '/static/flash/games/game-' + n;
	jQuery('#fancy_clicker').attr('href', url);
	jQuery('a#fancy_clicker').fancybox({
		padding: 0,
		imageScale: false,
		frameWidth: width,
		frameHeight: height,
		hideOnContentClick: false,
		overlayOpacity: 0.9,
		overlayShow: true,
		callbackOnClose: function() {
			HH.World.fancyboxClosed();
		},
		centerOnScroll: true
	});
	jQuery('#fancy_clicker').trigger('click').unbind('click');
};


HH.World.fancyboxClosed = function() {
	Common.log('HH.World.fancyboxClosed() called');
	if (!jQuery.browser.msie) {
		var flashObj = document.getElementById('flash_world_flash');
		if (flashObj && (typeof(flashObj.fancyboxClosed) !== 'undefined')) {
			flashObj.fancyboxClosed();
		}
	} else {
		jQuery('#flash_world_flash').css('visibility', 'visible');
	}
};


HH.World.loadExternalGame = function(n) {
	Common.log('HH.World.loadExternalGame() called');
	if (!HH.World._game_config[n]) {
		return;
	}

	// Defaults
	var width  = 620;
	var height = 520;

	// Overrides
	if (HH.World._game_config[n]['width']) {
		width = HH.World._game_config[n]['width'];
	}
	if (HH.World._game_config[n]['height']) {
		height = HH.World._game_config[n]['height'];
	}
	jQuery('#container')
		.width(width + 'px')
		.height(height + 'px');
	HH.flash({
		id: 'flash',
		src: HH.World._game_config[n].swf,
		width: width,
		height: height,
		express_install: '/static/flash/express_install.swf',
		callback: function() {
			return;
		}
	});
};