spliurl = document.URL.split('/');
var APP_URL = spliurl[0]+"/"+spliurl[1]+"/"+spliurl[2]+"/";


function reload(valor)
{

	if(valor)
	{
		// inicializamos las variables
		var url = APP_URL+'sextatv/reload';
		var section = false;
		var type = false;
		var page = 0;
		var section_id = false;

		if(temp = valor.split('_'))
		{

			if(temp[0]){ var section 		= temp[0];}
			if(temp[1]){ var type    		= temp[1];}
			if(temp[2]){ var page    		= temp[2];}
			if(temp[2]){ var section_id 	= temp[3];}

			new Ajax.Request(url , {
				method: 'post',
				asynchronous: true,
				encoding: 'utf-8',
				parameters: {seccion: section, pagina: page, tipo:type, section_id:section_id },
				onCreate: function(){

					if( !$('contenedor_videos').hasClassName('lsv_listado_videos_cargando') )
					{
						$('contenedor_videos').addClassName('lsv_listado_videos_cargando');
					}

		    },
				onSuccess: function(transport) {

					var response = transport.responseText;

					if( $('contenedor_videos').hasClassName('lsv_listado_videos_cargando') )
					{
						$('contenedor_videos').removeClassName('lsv_listado_videos_cargando');
					}

					$('contenedor_videos').innerHTML = response;

				},
				onComplete: function(transport) {
          			width_pagination('paginacion_normal_contenedor');
				}
			});

		}// fin del split

	}

}// fin de reload

function reload_generic_comments(page)
{

	 // inicializamos las variables
	 var url          = APP_URL + 'comunidad/ajaxCommentListGeneric';
	 var item_id_form = $('item_id_form').value;
	 var show_id_form = $('show_id_form').value;
	 var bd_id_form   = $('bd_id_form').value;

	 var height_div = $('list_comment').getHeight();

	 new Ajax.Request(url , {
			method: 'post',
			asynchronous: true,
			encoding: 'utf-8',
			parameters: {item_id  : item_id_form,
			             show_id  : show_id_form,
			             bd_id    : bd_id_form,
			             pag      : page,
			             limit    : 10
			},
			onCreate: function(){

				if( !$('list_comment').hasClassName('comentarios_listado_content_cargando') )
				{
					$('list_comment').addClassName('comentarios_listado_content_cargando');
				}


	    },
			onSuccess: function(transport) {

				var response = transport.responseText;

				if( $('list_comment').hasClassName('comentarios_listado_content_cargando') )
				{
				  $('list_comment').removeClassName('comentarios_listado_content_cargando');
				}

			  $('list_comment').innerHTML = response;

			},
			onComplete: function(transport) {
        		width_pagination('paginacion_comments_contenedor');
        		initialize();
			}
	});

}// fin de reload

function reload_comments(page)
{

	 // inicializamos las variables
	 var url          = APP_URL + 'comunidad/ajaxCommentListSextaTv';
	 var item_id_form = $('item_id_form').value;
	 var show_id_form = $('show_id_form').value;
	 var bd_id_form   = $('bd_id_form').value;

	 var height_div = $('list_comment').getHeight();

	 new Ajax.Request(url , {
			method: 'post',
			asynchronous: true,
			encoding: 'utf-8',
			parameters: {item_id  : item_id_form,
			             show_id  : show_id_form,
			             bd_id    : bd_id_form,
			             pag      : page,
			             limit    : 3
			},
			onCreate: function(){

				if( !$('list_comment').hasClassName('comentarios_listado_content_cargando') )
				{
					$('list_comment').addClassName('comentarios_listado_content_cargando');
				}


	    },
			onSuccess: function(transport) {

				var response = transport.responseText;

				if( $('list_comment').hasClassName('comentarios_listado_content_cargando') )
				{
				  $('list_comment').removeClassName('comentarios_listado_content_cargando');
				}

			  $('list_comment').innerHTML = response;

			},
			onComplete: function(transport) {
        		width_pagination('paginacion_comments_contenedor');
        		initialize();
			}
	});

}// fin de reload



function reload_programs(page)
{
	 // inicializamos las variables
	 var url 			= APP_URL+'sextatv/reload_programs';
	 var item_id_form 	= 1;
	 var show_id_form 	= 1;
	 var bd_id_form   	= 1;

	 new Ajax.Request(url , {
			method: 'post',
			asynchronous: true,
			encoding: 'utf-8',
			parameters: {item_id  : item_id_form,
			             show_id  : show_id_form,
			             bd_id    : bd_id_form,
			             pagina   : page,
			             limit    : 3
			},
			onCreate: function(){

				if( !$('list_programas').hasClassName('programas_listado_content_cargando') )
				{
					$('list_programas').addClassName('programas_listado_content_cargando');
				}

	    },
			onSuccess: function(transport) {

				var response = transport.responseText;

				if( $('list_programas').hasClassName('programas_listado_content_cargando') )
				{
				  $('list_programas').removeClassName('programas_listado_content_cargando');
				}

			  $('list_programas').innerHTML = response;

			},
			onComplete: function(transport) {
       		 width_pagination('paginacion_programas_contenedor');
       		 initialize();
			}
	});

}// fin de reload

function reload_recomendados(page)
{
	alert('hola');
	 // inicializamos las variables
	 var url 			= APP_URL+'sextatv/reload_recomendados';
	 var item_id_form 	= 1;
	 var show_id_form 	= 1;
	 var bd_id_form   	= 1;

	 new Ajax.Request(url , {
			method: 'post',
			asynchronous: true,
			encoding: 'utf-8',
			parameters: {item_id  : item_id_form,
			             show_id  : show_id_form,
			             bd_id    : bd_id_form,
			             pagina   : page,
			             limit    : 3
			},
			onCreate: function(){

				if( !$('list_recomendados').hasClassName('programas_listado_content_cargando') )
				{
					$('list_recomendados').addClassName('programas_listado_content_cargando');
				}

	    },
			onSuccess: function(transport) {

				var response = transport.responseText;

				if( $('list_recomendados').hasClassName('programas_listado_content_cargando') )
				{
				  $('list_recomendados').removeClassName('programas_listado_content_cargando');
				}

			  $('list_recomendados').innerHTML = response;

			},
			onComplete: function(transport) {
       		 width_pagination('paginacion_recomendados_contenedor');
       		 initialize();
			}
	});

}// fin de reload



function width_pagination(capa)
{
	var temp = 0;
//paginacion_contenedor
  if( $jQ('#'+capa)){

	  $jQ('#'+capa+' a').each(function(n){
			temp += $jQ(this).outerWidth(true);
	  });

	  $jQ('#'+capa+' span').each(function(n){
			temp += $jQ(this).outerWidth(true);
	  });

	  $jQ('#'+capa).width(temp);
	}

}


function __initialize()
{
	jQuery(document).find('[class=answer]').empty();
	jQuery(document).find('span[class=status][name=1]').show();
	jQuery(document).find('span[class=status][name=2]').hide();
}

function initialize()
{
	__initialize();

	jQuery('a[class=responderbox_comments]').toggle(
		function(){
			// Empty previously openened answers
			jQuery(document).find('[class=answer]').empty();

			// Import answers belongs to current item
			answers( jQuery(this).attr( 'item_id' ) );

			__initialize();

			// Toggles text to show close link
			jQuery(this).find('span').toggle();
		},
		function(){
			// Empty previously openened answers
			jQuery(document).find('[class=answer]').empty();
			__initialize();
		}
	);
}
