$(document).ready(function() {
	//ve se ha variavel trailer na url query string e chama funcao para carregar trailer
	var trailer = getQueryVariable("trailer");
	if(trailer == 'true'){
	    window.setTimeout('initSlide2(-858)', 300);

	    WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Trailer';
	    if (wreport_ok == 1) {
	        w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
	        w_counter.add_content(WRP_CONTENT);
	        w_counter.count();
	    }
	}
	
   //ve se ha variavel trailer na url query string e chama funcao para carregar trailer
	var passatempo = getQueryVariable("passatempo");
	if(passatempo == 'true'){
		window.setTimeout('initSlide(-1286)', 300);

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Passatempo';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
	}
	
	//event handlers de botoes para slide show	
	$('#linkComenta').click(function() {
        window.setTimeout('initSlide(-428)', 300);
		$('#videoTrailer').hide();
		writeBreadCrumb('Comenta este filme');

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Comenta';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;
    });
	
	$('#linkVerComentarios').click(function() {
        window.setTimeout('initSlide(-428)', 300);
		$('#videoTrailer').hide();
		writeBreadCrumb('Ver Comentarios');

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::VerComentarios';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;
    });
	
	$('.trailerFotos a:eq(0)').click(function(){
		window.setTimeout('initSlide2(-858)', 300);
		writeBreadCrumb('Ver Trailer');

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Trailer';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;									  
	});
	
	$('#linkPassatempos').click(function() {
		window.setTimeout('initSlide(-1286)', 300);
		$('#videoTrailer').hide();
		writeBreadCrumb('Passatempo');

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Passatempo';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;
    });
	
	$('#linkVoltar').click(function(){
		window.setTimeout('initSlide(0)', 300);
		$('#videoTrailer').hide();

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Geral';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;
	});
	
	$('#linkVoltarT').click(function(){
		window.setTimeout('initSlide(0)', 300);
		$('#videoTrailer').hide();

		WRP_CONTENT = 'SuperMovies::MotorPesquisa::CinemaFilmeDetalhe::Geral';
		if (wreport_ok == 1) {
		    w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
		    w_counter.add_content(WRP_CONTENT);
		    w_counter.count();
		}
		
		return false;
	});

	if ($('.alfa').length > 0) 
	{		
		var alfaHeight = $('.alfa').height();
		var alfaWidth = $('.alfa').width();
		$(".alfa").prepend('<div class="darkenMask"></div>');
		$(".darkenMask").height(alfaHeight).width(alfaWidth).css("opacity","0").animate({ opacity: "0.5" }, "slow");

		//$('.alfa').css({background:"#000000"}).animate({ opacity: "0.5" }, "slow")
	}
	
	//definine alturas por causa do border dos elementos	
	var blocoFundo = $('.blocoDireito').height();
	$('.sectionDetalhe').css({height:blocoFundo});
	$('#section1b').css({height:blocoFundo});
	$('#section1c').css({ height: blocoFundo });
	$('#section1d').css({ height: blocoFundo });
	$('.clunaI').css({height:blocoFundo});
	$('.clunaII').css({height:blocoFundo});

	$('.blocoDados').css({ height: blocoFundo });
	
	//definine alturas da pesquisa de cinema por causa do fundo 	
	var blocoFundoPesquisa = $('.bgCinema').height();
	$('.fundoResultPesquisa').css({height:blocoFundoPesquisa});
	$('.blocoDireito').css({ height: blocoFundoPesquisa });		
});

//funcao para fazer slide horizontal recebe medidas ex 300 -300
function initSlide(leftUnits){
	$('.section').animate({ left: + leftUnits + "px"}, 800 );
}

//funcao para fazer slide horizontal recebe medidas ex 300 -300 e carregar swf
function initSlide2(leftUnits){
	$('#videoTrailer').show();
	$('#videoTrailer').children('div:eq(0)').hide();
	$('.section').animate({ left: + leftUnits + "px"}, 800 ,function(){
		$('#videoTrailer').children('div:eq(0)').show();
	});
}

//funcao para escrever breadcrumb
function writeBreadCrumb(texto){
	$('.breadcrump span').html(texto);
}

//FUNCTION TO GET VARIABLES FROM URL QUERY STRING
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
	  return pair[1];
    }
  }
  //alert('Query Variable ' + variable + ' not found');
}