/** PARAMETROS **/
var resultTimeout;
var settings = {
	OPENING_ANIMATIONS_DURATION : 500,
	CLOSING_ANIMATIONS_DURATION : 200,
	OPENING_ANIMATIONS_MODE : "parallel",
	CUSTOM_SCROLLBARS_ENABLED : true
}
function initLabels(language){
    xInnerHtml('seccion1',ieexperience_Content.GetResource("seccion1",language).value);
    xInnerHtml('seccion2',ieexperience_Content.GetResource("seccion2",language).value);
    xInnerHtml('seccion3',ieexperience_Content.GetResource("seccion3",language).value);
    xInnerHtml('seccion4',ieexperience_Content.GetResource("seccion4",language).value);
    xInnerHtml('seccion5',ieexperience_Content.GetResource("seccion5",language).value);

    xInnerHtml('textoseccion1',ieexperience_Content.GetResource("textoseccion1",language).value);
    xInnerHtml('textoseccion2',ieexperience_Content.GetResource("textoseccion2",language).value);
    xInnerHtml('textoseccion3',ieexperience_Content.GetResource("textoseccion3",language).value);
    xInnerHtml('textoseccion4',ieexperience_Content.GetResource("textoseccion4",language).value);
    xInnerHtml('textoseccion5',ieexperience_Content.GetResource("textoseccion5",language).value);
    xInnerHtml('busquedas',ieexperience_Content.GetResource("busquedas",language).value);
    xInnerHtml('selectmediafilter',ieexperience_Content.GetResource("selectkindmediafilter",language).value);
    xInnerHtml('video',ieexperience_Content.GetResource("Video",language).value);
    xInnerHtml('Image',ieexperience_Content.GetResource("Image",language).value);
    xInnerHtml('Audio',ieexperience_Content.GetResource("Audio",language).value);
    xInnerHtml('Docs',ieexperience_Content.GetResource("Docs",language).value);
    xInnerHtml('selecttag',ieexperience_Content.GetResource("selecttag",language).value);
    xInnerHtml('descripcion',ieexperience_Content.GetResource("descripcion",language).value);
    xInnerHtml('link',ieexperience_Content.GetResource("link",language).value);
    xInnerHtml('embed',ieexperience_Content.GetResource("embed",language).value);
    xInnerHtml('sendtofriend',ieexperience_Content.GetResource("sendtofriend",language).value);
    xInnerHtml('tumail',ieexperience_Content.GetResource("tumail",language).value);
    xInnerHtml('maildetuamigo',ieexperience_Content.GetResource("maildetuamigo",language).value);
    xInnerHtml('comentario',ieexperience_Content.GetResource("comentario",language).value);
    xInnerHtml('sabermas',ieexperience_Content.GetResource("sabermas",language).value);
    xInnerHtml('nombre',ieexperience_Content.GetResource("nombre",language).value);
    xInnerHtml('mail',ieexperience_Content.GetResource("mail",language).value);
    xInnerHtml('comentario1',ieexperience_Content.GetResource("comentario",language).value);
    xInnerHtml('anadircomentario',ieexperience_Content.GetResource("añadircomentario",language).value);
    xInnerHtml('nombre1',ieexperience_Content.GetResource("nombre",language).value);
    xInnerHtml('mail1',ieexperience_Content.GetResource("mail",language).value);
    xInnerHtml('comentario2',ieexperience_Content.GetResource("comentario",language).value);
}

function init(){
        var ax;
        var language;
        language = xGetElementById("language").value
        
        var Url = location.href;
        Url = Url.replace(/.*\?(.*?)/,"$1");
        Variables = Url.split ("&");
        Separ = Variables[0].split("=");
        var aux = Separ[0]
        var flag = false;
        if (Separ[0].substr(0,1)=='h'){
            ax=ieexperience_Content.cargarMedia(51,language,true);
        }else{
           for (i = 0; i < Variables.length; i++) {
                Separ = Variables[i].split("=");
                eval ('var '+Separ[0]+'="'+Separ[1]+'"');
            }
            mediaId = idContent
            flag=true
            ax=ieexperience_Content.cargarMedia(idContent,language,false);
        }
            
        
        xGetElementById("id").value=ax.value[1];
        if (flag==false)
            {
            mediaId=ax.value[1];
            }
        //alert(mediaId)
        xInnerHtml('media-player-container',ax.value[0]);
        ax=ieexperience_Content.cargarContenidoDescripcion(mediaId,language);
        xInnerHtml('options-description',ax.value);
        ax=ieexperience_Content.cargarContenidoEmbed(mediaId,language);
        xGetElementById('embed-code').value=ax.value;
        ax=ieexperience_Content.cargarContenidoLink(mediaId);
        xGetElementById('link-code').value=ax.value;
        ax=ieexperience_Content.cargarRelaccionado(mediaId,language);
        xInnerHtml('related-media-container',ax.value);
        ax=ieexperience_Content.cargarComentario(mediaId);
        xInnerHtml('comments-container',ax.value);


        ax=ieexperience_Content.cargarMenu(2,language);
        xInnerHtml('media-list-category-1',ax.value);
        ax=ieexperience_Content.cargarMenu(3,language);
        xInnerHtml('media-list-category-2',ax.value);
        
        ax=ieexperience_Content.cargarMenu(4,language);
        xInnerHtml('media-list-category-3',ax.value);
        ax=ieexperience_Content.cargarMenu(5,language);
        xInnerHtml('media-list-category-4',ax.value);
        ax=ieexperience_Content.cargarMenu(6,language);
        xInnerHtml('media-list-category-5',ax.value);

        ax=ieexperience_Content.cargarComentario(mediaId);
        xInnerHtml('comments-container',ax.value);
        ax=ieexperience_Content.LoadRateContentNumber(mediaId);
        
        xInnerHtml('nvotos',"<p>"+ax.value+" v.</p>");
        ax=ieexperience_Content.Links(2);
        xInnerHtml('buttons-container',ax.value);

}
var mcPage = {

	init : function() {
	
		this.initFooter();	
		this.initSearchForm();
		this.initSearchFormFilters();
		this.initCommentsRelated();
		this.initCategoriesBrowsers();
		this.initPlayerOptions();
		this.initPlayerOptionsForms();
		this.initMediaRatings();
		this.initCategoryBrowser();
		this.initPlayerControls();
		this.initAjaxIndicator();
		this.initHomeButton();
		this.initEnglishButton();
		this.centerContainer();
		
		this.executeOpeningAnimations();
		this.fixMediaItemsWidth();
		
		$("a").click( function() {
			$(this).blur();
		});
		
		$(window).resize ( function() {
			mcPage.centerContainer();
		});
		
	},
	
	initFooter : function() {
	
		$("#footer-toggle").hover (
		
			function() {
				$(this).hide();
				$("#footer").show();
			},
			
			function() {}
		);
		
		$("#footer").hover (
			function() {},
			
			function() {
				$(this).hide();
				$("#footer-toggle").show();
			}
		)
	},
	
	initHomeButton : function() {
	
		$("#lnkHome").click( function() {
		
			mcPage.closeCategoryBrowser( function(){} );
			mcPage.closeSearchResultsBrowser();
			
			mcPage.executeOpeningAnimations();
			return false;
		});
	},
	
	initEnglishButton : function() {
		
		$("#lnkEnglish").click( function() {
		    aux = xGetElementById("language").value
		    if (aux==2){
		        xGetElementById("language").value=1
		        xInnerHtml('lnkEnglish',"español");
		        initLabels("en-gb")
		        init();
		    }else{
		    	xGetElementById("language").value=2
		        xInnerHtml('lnkEnglish',"english");
		        initLabels("es-SP")
                init()
		    }
			return false;
		});
	},
	
	/**
	* Inicializa el comportamiento del formulario de busqueda.
	*/
	initSearchForm : function() {
	
		$("#search-form").submit( function() {
		
		
			// -- SCM --
			// -- EJECUTAR BUSQUEDA DE MEDIA AQUI.
			// -- LLENAR EL ELEMENTO #search-results-list-items CON LOS RESULTADOS
			
		    var texto= xGetElementById("keyword").value;
		    if (texto!=""){
		        var filters= xGetElementById("selected-filters").value;
		        var tags= xGetElementById("selected-tag").value;
		        var content = ieexperience_Content.buscar(texto,filters,tags);
		        xInnerHtml('search-results-list',content.value[0]);
		        //alert("<select name='selected-tag' id='selected-tag'>"+content.value[1]+"</select>");
		        xInnerHtml('sel-Tags', "<select name='selected-tag' id='selected-tag'><option value=''>Seleccione un Tag</option>"+content.value[1]+"</select>");
    		    
		        //alert(ieexperience_Content.buscar(texto,filters,tags).value[1]);
			    var parameters = {};
    			mcPage.openSearchResultsBrowser();			
//			    $("#search-results-list").load( 
//    				"search-results.html",
//				    parameters,
//				    mcPage.searchResultsCallback
//			    );			
			    
			}else{
			    alert("Es necesario que haya una palabra en el criterio de búsqueda")
			}
						
			return false;
		});			
	},
	
	searchResultsCallback : function ( responseText, textStatus, xmlHttpRequest ) {
	
		// console.debug ( responseText );	
	
		// -- MUESTRA LA LISTA DE RESULTADOS
		// -- CIERRA EL NAVEGADOR DE ITEMS DE UNA CATEGORIA EN CASO QUE ESTE ABIERTO						
		var $categoriesBrowser = $("#category-contents-browser");
			
		if ( $categoriesBrowser.data("open") != null ) {
			mcPage.closeCategoryBrowser( mcPage.openSearchResultsBrowser );
		}
		else {			
			mcPage.openSearchResultsBrowser();			
		}
		
		mcPage.fixMediaItemsWidth();
		
		// -- Lista de Media
		var scrollOptions = {			
			items: ".media-carrousel",
			horizontal: true
		};
		
		$("#search-results-container").scrollable( scrollOptions ).scrollable("begin", "fast");	
	},
	
	openSearchResultsBrowser : function() {
	
		$(".media-category-content").each( function(index) {
			$(this).siblings("a:first")
				.removeClass("opened")
				.removeClass("selected")
				.addClass("closed");
		});	
	
		var animationOptions = {
			direction: "right"
		};
		
		$("#search-results-browser")
			.show("slide", animationOptions, 1000 )
			.data("open", true );
	},
	
	closeSearchResultsBrowser : function() {
	
		var animationOptions = {
			direction: "right"
		};
			
		$("#search-results-browser")
			.hide("slide", animationOptions, 200 )
			.removeData("open");
	},
	
	/**
	* Inicializa el comportamiento de los filtros de busqueda.
	*/
	initSearchFormFilters : function() {
	
		$("a.media-filter").click( function() {
			var $this = $(this);
			$this.toggleClass( $this.attr("title").toLowerCase() + "-selected");
			$this.toggleClass("selected");
			
			var enabledFilters = new Array();
			
			$("a.media-filter").each( function() {
			
				var $this = $(this);
				
				if ( $this.hasClass("selected")) {
					enabledFilters.push ( $this.attr("title").toLowerCase() );
				}
			});	
			$("#selected-filters").val(enabledFilters.join("|"));	
		});
	},
	
	/**
	* Inicializa el comportamiento de los botones Comments y Related Media
	*/
	initCommentsRelated : function() {
	
		$(".rc-trigger").hover (
		
			/* mouseover */
			function() {
				var $this = $(this);
				var metadata = $this.metadata();
				
				/* Chequea si el contenedor solicitado está abierto */
				if ( $this.data("open") == null ) {
					$this.addClass("selected");
					
					var openerFunction = "";
					
					if ( metadata.objects == "comments" ) {
						openerFunction = "mcPage.openCommentsContainer();";
					}				
					else {
						openerFunction = "mcPage.openRelatedMediaContainer()";
					}
					
					var timeoutId = setTimeout(openerFunction, 1000 );
					$this.data("hoverTimeoutId", timeoutId );
				}
			},
			
			/* mouseout */
			function() {
				var $this = $(this);
				var metadata = $this.metadata();
				
				if ( $this.data("open") == null ) {
					$this.removeClass("selected");			
				}				
				
				clearTimeout( $this.data("hoverTimeoutId"));
			}		
		);
		
		$(".rc-container").hover (
			
			/* mouseover */
			function() {
				$this = $(this);				
				clearTimeout( $this.data("outTimeoutId"));
			},
			
			/* mouseout */
			function() {
			
				var $this = $(this);
				var closerFunction = "";
				var metadata = $this.metadata();
					
				if ( metadata.objects == "comments" ) {
					closerFunction = "mcPage.closeCommentsContainer();";
				}				
				else {
					closerFunction = "mcPage.closeRelatedMediaContainer()";
				}
					
				var timeoutId = setTimeout(closerFunction, 1000 );
				$this.data("outTimeoutId", timeoutId );
			}
		);
		
		$(".rc-trigger").click( function() {
			return false;
		});
		
		$("#related-media-list tr").livequery("click", function(event) {
		
			alert("click");
		
		})
	},
	
	initCategoriesBrowsers : function() {
		$("li.media, div.media").livequery("click", function() {
		
			$this = $(this);
			
			
			// -- Se ocultan los controles.
			$(".player-control").hide();
			
			var media_controls = "";
			
			// -- Mostrar controles para Pictures
			if ( $this.hasClass("media-picture")) {
				media_controls = "player-controls-pictures";
			};
			
			// -- Mostrar controles para Video
			if ( $this.hasClass("media-video")) {
				media_controls = "player-controls-video";
			};
			
			// -- Mostrar controles para Audio
			if ( $this.hasClass("media-audio")) {
				media_controls = "player-controls-audio";
			};
			
			// -- Mostrar controles para Docs
			if ( $this.hasClass("media-doc")) {
				media_controls = "player-controls-docs";
			};			
			
			$("#" + media_controls ).show();
			
			// -- SCM --
			// -- Realizar la carga del media en este punto.
			
			var mediaId = $this.attr("id");
			
						$this = $(this);
			var mediaId = $this.attr("id");
			xGetElementById("id").value=mediaId;
			var language = xGetElementById("language").value
			//alert("Cargar Media con ID #" + mediaId );
			ax=ieexperience_Content.cargarMedia(mediaId,language,false);
            xGetElementById("id").value=ax.value[1];
            //mediaId=ax.value[1];
            xInnerHtml('media-player-container',ax.value[0]);
            ax=ieexperience_Content.cargarContenidoDescripcion(mediaId,language);
            xInnerHtml('options-description',ax.value);
            ax=ieexperience_Content.cargarContenidoEmbed(mediaId,language);
            xGetElementById('embed-code').value=ax.value;
            ax=ieexperience_Content.cargarContenidoLink(mediaId);
            xGetElementById('link-code').value=ax.value;
            ax=ieexperience_Content.cargarRelaccionado(mediaId,language);
            xInnerHtml('related-media-container',ax.value);
            ax=ieexperience_Content.cargarComentario(mediaId);
            xInnerHtml('comments-container',ax.value);
			xInnerHtml('rating-stars-container',"");    
			var options = {
		        maxvalue : 5,
			    cancel : false,
			    clickCallback : function (rating) {var mediaId = xGetElementById("id").value; var ax = ieexperience_Content.rateContent(mediaId, rating);}
			    
			    
			    //$(this).siblings().find("ratingsClickCallback").value
			};
			ax= ieexperience_Content.LoadRateContentNumber(mediaId)
			xInnerHtml('rating-votes-container',"<p>"+ax.value +"v.</p>");    
			

    		$("#rating-stars-container").rating("#", options );
			
			
			
			return false;
		} )
		
		$("li.media, div.media").livequery("mouseover", function() {
		
			// -- En el evento Over, mostrar la descripcion del media.
		/*	var $this = $(this);
			var id = $this.attr("id");
			var language = xGetElementById("language").value
            var ax=ieexperience_Content.cargarContenidoDescripcion(id,language);
            xInnerHtml('options-description',ax.value);
		*/		
			// -- SCM -- 
			// -- OBTENER EL TEXTO DE LA DESCRIPCION EN ESTE PUNTO.				
			//var descriptionText = "Descripcion para el media " + id;
				
			// -- Se abre el panel de la Descripcion.
		/*	$("#player-options").accordion("activate", 100);
			var language = xGetElementById("language").value
            var ax=ieexperience_Content.cargarContenidoDescripcion(id, language);
            xInnerHtml('options-description',ax.value);
	*/
			//$("#options-description").html( descriptionText );
		});
				
	    $("li.media, div.media").livequery("mouseout", function() {
		
			// -- En el evento Over, mostrar la descripcion del media.
			var $this = $(this);
			var id = xGetElementById("id").value
			var language = xGetElementById("language").value
           //// var ax=ieexperience_Content.cargarContenidoDescripcion(id,language);
           //// xInnerHtml('options-description',ax.value);
				
			// -- SCM -- 
			// -- OBTENER EL TEXTO DE LA DESCRIPCION EN ESTE PUNTO.				
			//var descriptionText = "Descripcion para el media " + id;
				
			// -- Se abre el panel de la Descripcion.
			$("#player-options").accordion("activate", 0 );
			var language = xGetElementById("language").value
            ////var ax=ieexperience_Content.cargarContenidoDescripcion(id, language);
            ////xInnerHtml('options-description',ax.value);
	
			//$("#options-description").html( descriptionText );
		});

			
		$(".media-category").hover (
		
			/* mouseover */
			function() {
			
				var isCategoryOpened = ($(this).siblings().find("a.opened").length > 0);
			
				var $this = $(this);		
				var $header = $this.find("a:first");
				
				if ( !$header.hasClass("opened")) {
					
					$header.removeClass();
					
					if ( isCategoryOpened ) {
						$header.addClass("closed-selected");
					}
					else {
						$header.addClass("selected");
					}
					
					var categoryId = $this.attr("id");				
				
					var timeoutId = setTimeout("mcPage.updateCategoryMedia(" + categoryId + ")", 1000 );
					$this.data("hoverTimeoutId", timeoutId );
				}				
				
				if ( $("#category-contents-browser").data("hoverTimeoutId") != null ) {
				
					var browserTimeoutId = $("#category-contents-browser").data("hoverTimeoutId");
					clearTimeout( browserTimeoutId );
					
					$("#category-contents-browser").removeData("hoverTimeoutId");
				}				
			},
			
			/* mouseout */
			function() {
			
				$this = $(this);
				$header = $this.find("a:first");
				
				// -- Si es la categoria abierta...
				if ( $header.hasClass("opened")) {
				
					// -- Se cierra el browser.
					$browser = $("#category-contents-browser");
					// var timeoutId = setTimeout("mcPage.closeCategoryBrowser()", 1000 );
					// $browser.data("hoverTimeoutId", timeoutId );					
				}
				else {
				
					var isCategoryOpened = ($(this).siblings().find("a.opened").length > 0);
					var isSearchOpened = ($("#search-results-browser:visible").length > 0);
					
					$header.removeClass("closed-selected");
					$header.removeClass("selected");
					
					if ( isCategoryOpened || isSearchOpened ) {
						$header.addClass("closed");
					}
								
					clearTimeout( $this.data("hoverTimeoutId") );
					$this.removeData("hoverTimeoutId");
				}
			}
		);
	},
	
	initPlayerOptions : function() {
	
		var options = {
			header : ".ui-accordion-header",
		//	event: "mouseover",
			autoHeight : true
		}		

	
	$("#player-options").accordion( options );
	$(".ui-accordion-header").hover(function(){
	    //alert($(this).attr("id"));
	    clearTimeout(resultTimeout)
	    var id = parseInt($(this).attr("id"));
	    resultTimeout= setTimeout('$("#player-options").activate('+id+');return false;',1000);
	   // resultTimeout= setTimeout('$(this).activate(false)return false;',1000);
        
      //  cont= $(this);
        
       // setTimeout('alert(cont)',1000);
	    //resultTimeout= setTimeout('$(".ui-accordion-content").slideUp();cont.next().slideDown();return false;',1000);

	},
			
			/* mouseout */
			function() {
			//$("#player-options").activate(2);
			
			}
	);//.next().hide();
	},
	
	initPlayerOptionsForms : function() {
		
	
		$("#friend-form").submit( function() {
		
			// -- SCM --
			// -- REALIZAR ENVIO DEL MEDIA A UN AMIGO.
			var fromMail = xGetElementById("friend-email-sender").value
			var toMail = xGetElementById("friend-email").value
			var comment = xGetElementById("friend-text").value
            alert(ieexperience_Content.sendToFriend(fromMail,toMail,comment,xGetElementById("id").value).value);
			return false;
		
			return false;
		});
	
		// -- Formulario de comentarios.
		$("#comments-form").submit( function() {		
		
			// -- SCM --
			// -- GUARDAR COMENTARIO INGRESADO POR EL USUARIO.
			var nick = xGetElementById("comments-name").value
			var mail = xGetElementById("comments-email").value
			var comment = xGetElementById("comments-text").value
			var mediaId = xGetElementById("id").value
			
			//alert(mediaId)
			//alert(nick)
			//alert(mail)
			//alert(comment)
			alert(ieexperience_Content.addComment(mediaId,nick,mail,comment).value);
			ax=ieexperience_Content.cargarComentario(mediaId);
            xInnerHtml('commentsScrollPanel',ax.value);
            xGetElementById("comments-name").value=""
			xGetElementById("comments-email").value=""
			xGetElementById("comments-text").value=""
			
			// -- Se abre el panel de comentarios.
			mcPage.openCommentsContainer();
			
			return false;
		});	
	},
	
	executeOpeningAnimations : function() {
	
		$(".media-category-content").each( function(index) {
			$(this).siblings("a:first").removeClass("opened").removeClass("closed");
		});		
	
		if ( settings.OPENING_ANIMATIONS_MODE == "sequential" ) {
			$(".media-category-content:first").show("slide", { direction : "up" }, settings.OPENING_ANIMATIONS_DURATION, this.openingAnimationCallback );
		}
		else {
			$(".media-category-content").show("slide", { direction : "up" }, settings.OPENING_ANIMATIONS_DURATION );
		}
		
	},
	
	initCategoryBrowser : function() {
	
		$("#category-contents-browser").hover (
			
			/* mouseover */
			function() {
			
				$this = $(this);
			
				if ( $this.data("hoverTimeoutId") != null ) {					
					clearTimeout( $this.data("hoverTimeoutId") );
					$this.removeData("hoverTimeoutId");
				}
			},
			
			/* mouseout */
			// -- Cierre automatico en el evento mouseout
			function() {
			
				$this = $(this);
				// var timeoutId = setTimeout("mcPage.closeCategoryBrowser()", 1000 );
				// $this.data("hoverTimeoutId", timeoutId );
			}
		);
	},
	
	updateCategoryMedia : function( categoryId ) {
	
		var $this = $("#" + categoryId );
		var $relatedLink = $this.find("a:first");
		
		$relatedLink.removeClass().addClass("opened");
	
		var options = {
			direction : "up"
		}
	
		$(".media-category-content").each ( function() {
			
			var $this = $(this);
			var catId = $this.parent("div").attr("id");
			
			if ( catId != categoryId ) {
				$this.siblings("a").removeClass("selected").removeClass("opened").addClass("closed");				
			}
			
			$this.hide();
		});
		
		// -- En caso que está abierto el panel de resultados de una búsqueda, lo cierra.
		if ( $("#search-results-browser").data("open") != null ) {
			this.closeSearchResultsBrowser();
		}
		
		$("#category-contents-browser").data("selectedCategoryId", categoryId );
		
		mcPage.fixMediaItemsWidth()
		
		$(".media-list-container").hide();		
		$("#media-list-container-" + categoryId ).show();

		$("#category-contents-browser")
			.data("open", true )
			.show("slide", { direction : "up" }, settings.OPENING_ANIMATIONS_DURATION );
			
		$("#media-list-container-" + categoryId ).show().scrollable(		
			{
				items : ".media-carrousel",
				horizontal : true
			}		
		)
		
		$("#media-list-container-" + categoryId ).scrollable("begin");
	}
	/*,
	
	// -- Abre el panel de navegacion de media de una categoria.
	openCategoryBrowser : function( responseText, textStatus, xmlHttpRequest ) {	
	
		// -- Lista de Media
		var scrollOptions = {
			target: "#media-list",
			items: "li",
			start: 0,
			force: false,
			cycle: false,
			step:  1,		
			prev: "#media-list-prev",
			next: "#media-list-prox",
			lazy: true
		};
		
		// $("#category-contents-container").serialScroll( scrollOptions );
				
		$("#category-contents-browser")
			.data("open", true )
			.show("slide", { direction : "up" }, settings.OPENING_ANIMATIONS_DURATION, function() {
				// mcPage.fixMediaItemsWidth();
			});
	} */
	,

	
	// -- Cierra el panel de navegacion de media de una categoria.
	closeCategoryBrowser : function( postAnimationCallback ) {
		
		if ( postAnimationCallback == null ) {
			postAnimationCallback = this.executeOpeningAnimations;
		}
		
		var animationOptions = {
			direction : "up"
		}
	
		$("#category-contents-browser")
			.removeData("open")
			.hide( "slide", animationOptions, settings.CLOSING_ANIMATIONS_DURATION, postAnimationCallback );
	},
	
	openRelatedMediaContainer : function() {
	
		// -- Se cierra el panel de comentarios.
		this.closeCommentsContainer();	
		
		$("#related-trigger").addClass("selected").data("open", true );		
		$("#related-media-container").show("slide", { direction : "left" }, settings.OPENING_ANIMATIONS_DURATION );
		
		// -- SCM -- 
		// -- AQUI PONER CODIGO PARA ACTUALIZAR CONTENIDO RELACIONADO DESDE EL SERVIDOR.
		// -- EL CONTENEDOR SE LLAMA #related-media-container	
		
		// -- PARAMETROS PARA EL LLAMADO AJAX.
		var parameters = {};
		
		
		$("#related-media-container").load (
			"media-related.html",
			parameters,
			function () {
			
				if ( settings.CUSTOM_SCROLLBARS_ENABLED ) {
			
					var scrollOptions = {									
					};
					
					$("#related-media-container div.scroll-panel").jScrollPane( scrollOptions );
				}
			}
		);
	},
	
	openCommentsContainer : function() {
	
		// -- Se cierra el panel de media relacionado
		this.closeRelatedMediaContainer();
	
		$("#comments-trigger").addClass("selected").data("open", true );
		$("#comments-container").show("slide", { direction : "left" }, settings.OPENING_ANIMATIONS_DURATION );	
		
		// -- Se abre el panel para aniadir un comentario.
		$("#player-options").accordion("activate", 5 );
		
		// -- SCM --
		// -- AQUI PONER CODIGO PARA ACTUALIZAR LOS COMENTARIOS DESDE EL SERVIDOR.
		// -- EL CONTENEDOR SE LLAMA #comments-container
		var mediaId = xGetElementById("id").value
		var ax=ieexperience_Content.cargarComentario(mediaId);
        xInnerHtml('commentsScrollPanel',ax.value);
		// -- PARAMETROS PARA EL LLAMADO AJAX
		var parameters = {};
		
		$("#comments-container").load (
			"media-comments.html",
			parameters,
			function () {
			
				if ( settings.CUSTOM_SCROLLBARS_ENABLED ) {
			
					var scrollOptions = {	
														
					};
					
					$("#comments-container div.scroll-panel").jScrollPane( scrollOptions );
				}
			}
		)
	},
	
	closeRelatedMediaContainer : function() {		
		$("#related-trigger").removeClass("selected").removeData("open");
		$("#related-media-container").hide();			
	},
	
	closeCommentsContainer : function() {
		$("#comments-trigger").removeClass("selected").removeData("open");
		$("#comments-container").hide();				
	},
	
	initMediaRatings : function() {
	
		var options = {
		
			maxvalue : 5,
			cancel : false,
			clickCallback : this.ratingsClickCallback
		
		};
		
		$("#rating-stars-container").rating("#", options );
	
	},
	
	initPlayerControls : function() {
	
		// -- SCM --
		// -- REALIZAR LAS ACCIONES SOBRE EL MEDIA PLAYER
		
		$("#control-video-fs").click( function() { alert("Fullscreen Video"); return false; } );
		
		$("#control-audio-download").click( function() { alert("Download Audio"); return false; } );
		
		$("#control-picture-previous").click( function() { alert("Previous Picture"); return false; } );
		$("#control-picture-next").click( function() { alert("Next Picture"); return false; } );
		$("#control-picture-zoomin").click( function() { alert("Zoom In"); return false; } );
		$("#control-picture-zoomout").click( function() { alert("Zoom Out"); return false; } );
		$("#control-picture-fullscreen").click( function() { alert("Fullscreen Picture"); return false; } );
		
		$("#control-docs-up").click( function() { alert("Docs Up"); return false; } );
		$("#control-docs-down").click( function() { alert("Docs Down"); return false; } );
		$("#control-docs-download").click( function() { alert("Docs Download"); return false; } );
			
	},
	
	initAjaxIndicator : function() {
	
		$("#loading-indicator")		
			
			.ajaxStart( function() {
				$(this).show();
			})
			
			.ajaxStop( function() {				
				$(this).hide();
			});
	},
	
	// -- SCM --
	// -- AQUI PONER CODIGO PARA ACTUALIZAR EL RATING DEL MEDIA.
	// --
	ratingsClickCallback : function( rating ) {	
	    var mediaId = xGetElementById("id").value
	    var ax=ieexperience_Content.rateContent(mediaId,rating);
	},
	
	openingAnimationCallback : function() {
	
		var $this = $(this);
		$("#" + $this.parent(".media-category-content").attr("id") + " + .media-category-content").show("slide", { direction : "up" }, settings.OPENING_ANIMATIONS_DURATION, openingAnimationCallback );
	},
	
	fixMediaItemsWidth : function() {
	
		// -- Arregla el ancho de los contenedores de media
		// -- para igualar el ancho de la imagen.
				
		$(".media-carrousel div.media").each( function(index) {
		
			var $this = $(this);
			
			var imageWidth = $this.find("img:first").css("width");
			
			$this.css("width", imageWidth );;
		});
	},
	
	centerContainer : function() {	
		
		var docHeight = $(document).height();
		var docWidth = $(document).width();
		
		var $container = $("#container");
		
		var paddingTop = parseInt($container.css("padding-top"));
        var paddingBottom = parseInt($container.css("padding-bottom"));

        var borderTop = parseInt($container.css("border-top-width"));
        var borderBottom = parseInt($container.css("border-bottom-width"));

        var mediaBorder = (borderTop+borderBottom)/2;
        var mediaPadding = (paddingTop+paddingBottom)/2;
		
		var elHeight = $container.height() + mediaBorder + mediaPadding;
		var elWidth = $container.width();
				
		$("#container").css (
			{
				position : "absolute",
				top : (docHeight/2 - elHeight/2),
				left: (docWidth/2 - elWidth/2)
			}		
		);		
	}
}

$(document).ready( function() {
	mcPage.init();
})