$(function() {
	$('.footer-victory').click(function(){
		$('#victory-overlay').fadeIn('fast',function(){$('#victory-box').fadeIn('fast');});
	});
	$('.header-victory').click(function(){
		$('#victory-overlay').fadeIn('fast',function(){$('#victory-box').fadeIn('fast');});
	});
	$('#victory-boxclose').click(function(){
		$('#victory-box').fadeOut('fast',function(){$('#victory-overlay').fadeOut('fast');});
	});
});


;(function($) {	
	var loadingMessage = "Loading content ...";
	var noContentgMessage = "No Content";
	var init = function() {	
		var _locale_list = $('.locale_list');
		var _games_sub_menu = $('.games_sub_menu');
		_games_sub_menu.hide();
		//$('.promo').load("/en/promos/list/"+$('.promo').attr('game_id'));
		_locale_list.load("/en/locales/list");
		//load up menu for games
		$('.games_menu').mouseenter(function(){
			if(_games_sub_menu.is(':hidden')) {_games_sub_menu.fadeIn(100);}	
		});
		_games_sub_menu.mouseleave(function(){
			if(_games_sub_menu.is(':visible')) {_games_sub_menu.fadeOut(200);}	
		});
		$('.games_sub_menu_close').click(function(e){
			e.preventDefault();
			_games_sub_menu.fadeOut(200);
		});
		$('.current_locale').click(function(e){
			e.preventDefault();
			if(_locale_list.is(':hidden')) {_locale_list.slideDown();} else {_locale_list.slideUp();}	
		});
		$('.current_locale').mouseenter(function(e){
			e.preventDefault();
			if(_locale_list.is(':hidden')) {_locale_list.slideDown();} else {_locale_list.slideUp();}	
		});
		_locale_list.mouseleave(function(){_locale_list.slideUp();});
		//load up sub games lists
		var _games_menu_list = $('.games_menu_list');
		_games_menu_list.each(function(index) {
			$(this).load("/en" + $(this).attr('games_list_url'));
		});
		$('.no-action-href').click(function(e){e.preventDefault();});
	};
	var activate_tab = function(_tab){
		//reset all active tabs
		var _type = _tab.attr('type'),
			_location = _tab.attr('location');
		$('.parent_li').removeClass('active');
		$('.first').removeClass('first-on');
		$('.spacer').removeClass('spacer-on spacer-on2');
		$('.end-spacer').removeClass('end-spacer-on');

		//activate middle portion
		$('.'+_type).addClass('active');

		//active left side portion
		if(_location=='first') {$('.'+_type+'_start').addClass('first-on');} else if (_location=='spacer') {$('.'+_type+'_start').addClass('spacer-on');} else if (_location=='end') {$('.'+_type+'_start').addClass('spacer-on');}
		//active right side portion
		if(_location=='first') {$('.'+_type+'_end').addClass('spacer-on2');} else if(_location=='end') {$('.'+_type+'_end').addClass('end-spacer-on');} else if (_location=='spacer') {$('.'+_type+'_end').addClass('spacer-on2');}
		
	};
	var load_video_viewer = function(_title,_width,_height,_brightcove_key){
		//we assume that there is a brightcove id for the video, if not then we are stuck inside a blocker
		var _width_ = (parseInt(_width)=='' || 'NaN') ? 675 : (parseInt(_width)+25),
			_height_ = (parseInt(_height_)=='' || 'NaN') ? 450 : (parseInt(_height_)+50);
					$( "#media_dialog:ui-dialog" ).dialog( "destroy" );
					$( "#media_dialog" ).dialog({
						modal: true,
						draggable: true,
						resizable: true,
						title: _title,
						width: 'auto',
						height: 'auto',
						position: [(($(window).width()/2)-(_width_/2)),150]
					});
					$("#media_dialog").load("/en/media/video_player/"+_brightcove_key+"/"+parseInt(_width_)+"/"+parseInt(_height_));
	};
	var load_image_viewer = function(_title,_width,_height,_file){
		//load up the div
		var _width_ = (parseInt(_width)=='' || 'NaN') ? 675 : (parseInt(_width)+25),
			_height_ = (parseInt(_height_)=='' || 'NaN') ? 450 : (parseInt(_height_)+50);
		$( "#media_dialog:ui-dialog" ).dialog( "destroy" );
		$( "#media_dialog" ).dialog({
			modal: true,	
			draggable: true,
			resizable: true,			
			title: _title,
			width: 'auto',
			height: 'auto',
			position: [(($(window).width()/2)-(_width_/2)),150]
		});
		$("#media_dialog").html("<img width='"+_width_+"' height='"+_height_+"' src='"+_file+"' />");		

	};
	var load_community_window = function(_community_obj_) {
		_community_obj_.load("/en/community/index/"+_community_obj_.attr('count')+"/"+_community_obj_.attr('forumids'), function(data) {
			if(data=='') {_community_obj_.html($.nocontent_message);}}).delay(300).slideDown(200);
	};
	var load_twitter_window = function(_community_obj_) {
		_community_obj_.load("/en/community/twitter", function(data) {
			if(data=='') {_community_obj_.html($.nocontent_message);}}).delay(300).slideDown(200);
	};
	var load_facebook_window = function(_community_obj_) {
		_community_obj_.load("/en/community/facebook", function(data) {
			if(data=='') {_community_obj_.html($.nocontent_message);}}).delay(300).slideDown(200);
	};

	$.extend({
		activate_tab : activate_tab,
		loading_message : loadingMessage, 
		nocontent_message : noContentgMessage, 
		load_video_viewer : load_video_viewer, 
		load_image_viewer : load_image_viewer, 
		load_community_window : load_community_window,
		load_twitter_window : load_twitter_window,
		load_facebook_window : load_facebook_window
	});
	
	$(init);
	
})(jQuery);


