jQuery(document).ready(function() {
//	reinitialiseScrollPane = function()
//	{
//		$('div#ajaxConteiner').jScrollPane();
//	}
	if (jQuery("ul.NavMenuVideo").length) {
		jQuery("ul.NavMenuVideo li a").click(function() {
			jQuery("#teste1");
			bgMenuInativo();//desabilita todas as abas
			var ativo = getClassByAtrib(this);
			jQuery(this).addClass(ativo[0]);
			var idCategoriaVideo = jQuery("input#id_categoria").val();
			var tipoVideo = jQuery(this).attr('href').substring(1);
			var dados = "idCategoriaVideo="+idCategoriaVideo+"&tipoVideo="+tipoVideo;
			jQuery.ajax({
		        type: "POST",
		        url: configGloabl+"filmes/getfilmes/rand="+ Math.floor(Math.random()*100),
		        data: dados,
		        success: function(ret){
					jQuery("#teste1").html(ret);
					showDialog();
		        }
		    });	//fim ajax
			
			//jQuery("div#ajaxConteiner").load(configGloabl+"filmes/getfilmes/rand="+ Math.floor(Math.random()*100),{'idCategoriaVideo': idCategoriaVideo,'tipoVideo':tipoVideo},reinitialiseScrollPane);
		});
	}	
	
	function bgMenuInativo() {
		jQuery("ul.NavMenuVideo li").find("a").each(function(i) {
			var inativo = getClassByAtrib(this);
			jQuery(this).removeClass();//limpa as classes
			jQuery(this).addClass(inativo[1]);
		});
	}
	//recupera as clases de css pelo Atributo "rel" do elemento "a"
	// retorna um array
	function getClassByAtrib(elemnto){
		return  jQuery(elemnto).attr('rel').split(",");
	}
	
	function showLoading(){
		var tmp = "<div style='margin-left:180px;margin-top: 80px' id='carregando'>";
		tmp+="<p>Carrengando...</p>";
		tmp+="<img src='"+configGloabl+"/public/site/img/loadingAnimation.gif' />";
		tmp+="</div>";
		return tmp;
	}
	//mostra a tela
	function showDialog(){
		jQuery('a.openUI').click(function(){
			var titulo = jQuery(this).parent().find('p').text();
			jQuery('div#telaFimes div#videoEscolhido').html("");
			jQuery('div#telaFimes div#videoEscolhido').html(showLoading());
			jQuery('div#telaFimes h2').text(titulo);
			jQuery('#telaFimes').dialog('open');
			detalheFilme(jQuery(this).attr('rel'));
			return false;
		});
		// Dialog			
		jQuery('#telaFimes').dialog({
			autoOpen: false,
			width: 850,
			height:500,
			modal:true,
			buttons: {
				"F E C H A R": function() { 
					jQuery('#telaFimes').dialog("close"); 
				}
			}
		});
	}
	showDialog();
	//detalhe Filmes
	function detalheFilme(id_video){
		jQuery.ajax({
	        type: "POST",
	        url: configGloabl+"filmes/detalhefilme/rand="+ Math.floor(Math.random()*100),
	        data: "id_video="+id_video,
	        success: function(ret){
				//
			jQuery("div#videoEscolhido").html(ret);
	        }
	    });	//fim ajax
	}
});