;(function($) {	
	var init = function() {	
			$('.media').hide();
			$.activate_tab($('.games_tab[type=tab_1]'));
			$('.game[tab=tab_1]').delay(50).slideDown(100);
			$('.media_header_display').css('cursor','pointer');
			$('.media_header_display').addClass('closed');
			$('.games_tab').click(function(e){
				$('.game').slideUp(100);
				$('.media_display').hide();
				e.preventDefault();
				var _tab_obj_ = $(this);
				var containerType = _tab_obj_.attr('container');
				var _brandingColor =  _tab_obj_.attr('branding_color');
				$('.sc-content').html("");
				$.activate_tab(_tab_obj_);
				$('.'+containerType).delay(300).slideDown(100, function(){
					var _container_type_ = $(this);
					var _type = _container_type_.attr('type')
					if(_type==='media') {
						$('.media_header_display[type=Video]').removeClass('closed');
						$('.Video').load("/en/media/list/"+encodeURIComponent($('.Video').attr('game_id'))+"/"+_brandingColor+"/Video", function(data){
							if(data=='') {$(this).html($.nocontent_message);}
						}).delay(300).slideDown(200);
					} 
					if(_type==='downloads') {
						//handled by the game itself, is a field in the data type
					}
					if(_type==='forum') {$.load_community_window(_container_type_);}
					if(_type==='ladders') {
						//_container_type_.html($.nocontent_message); 
						//handled by the game itself, is a field in the data type
					}

				});
			});
			$('.media_header_display').click(function(e){
				e.preventDefault();
				$('.media_header_display').addClass('closed');
				$(this).removeClass('closed');
				$('.media_display').slideUp(200);
				var mediaType = $(this).attr('type');
				var _brandingColor =  $(this).attr('branding_color');
				var game_id= $(this).attr('game_id');
				$('.'+mediaType).load("/en/media/list/" + encodeURIComponent(game_id) + "/"+_brandingColor+"/" + mediaType.replace("_", "%20")).delay(300).slideDown(200);
			
			});
			$('.games_media_item').live('click', function(e){
				e.preventDefault();
				var _game_media_item = $(this);
				if(_game_media_item.attr('media_type')==='Video') {$.load_video_viewer(_game_media_item.attr('media_title'),_game_media_item.attr('media_width'),_game_media_item.attr('media_height'),_game_media_item.attr('media_brightcove_key'));} else {
					if(_game_media_item.attr('media_item_file')==='') {
						// not media file, lets link to external url
						window.open(_game_media_item.attr('media_item_url'));
					} else {
						//load up the div
						$.load_image_viewer(_game_media_item.attr('media_title'),_game_media_item.attr('media_width'),_game_media_item.attr('media_height'),_game_media_item.attr('media_item_file'));					
					}
				}
			});
	};
	$(init);
	
})(jQuery);
