﻿/**************************************************************************************************
***************************************************************************************************
*************************************** GALERÍA DE TESTIMONIALES **********************************
***************************************************************************************************
***************************************************************************************************/
var actTestimonial = 0;
var active_select = null;
var _selectHeight = 23;
var seMueveManual = false;
//Mueve el testimonio actual, al siguiente o al anterior
//Parámetros:
//divCnt - Identificador del div que contiene la galería de los testimoniales
//isNext - Bandera que indica si se mueve al siguiente o al anterior
//topImg - Máximo índice para la colección de testimoniales
function moveTestimonialGalery (divCnt, isNext, topImg)
{   
    seMueveManual = true;
    //Deshabilitar botón
    $('#' + divCnt).prev().find('input').attr('disabled', 'true');
    //Ocultar testimonial
    $('#' + divCnt + ' > div').eq(actTestimonial).animate ({opacity:'1'}, 1000);
    //setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').css(\'display\', \'none\')', 1);
    $('#' + divCnt + ' > div').eq(actTestimonial).css('display', 'none');
    //Setear variables
    if (isNext)
        if (actTestimonial < topImg) actTestimonial = actTestimonial + 1;
        else actTestimonial = 0;
    else
        if (actTestimonial > 0) actTestimonial = actTestimonial - 1;
        else actTestimonial = topImg;
    //Mostrar testimonial
    //setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').css(\'display\', \'block\')', 1);
    $('#' + divCnt + ' > div').eq( actTestimonial).css('display', 'block');
    //setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').animate ({opacity:\'1\'}, 1000)', 1);
    $('#' + divCnt + ' > div').eq(actTestimonial).animate ({opacity:'1'}, 1000);
    //Habilitar botón
    //setTimeout('$(\'#' + divCnt + '\').prev().find(\'input\').removeAttr(\'disabled\')', 1);
    $('#' + divCnt).prev().find('input').removeAttr('disabled');
    
}
//Mueve el testimonio actual automáticamente al siguiente.
//Parámetros:
//divCnt - Identificador del div que contiene la galería de los testimoniales
//largo - Máximo índice para la colección de testimoniales
function moveTestimonialGaleryAutomatic (divCnt, largo)
{
   if(!seMueveManual) 
   {
        //Deshabilitar botón
        $('#lnkPrev').attr('disabled', 'true');
        $('#lnkNext').attr('disabled', 'true');
        //Ocultar testimonial
        $('#' + divCnt + ' > div').eq(actTestimonial).animate ({opacity:'0'}, 1000);
        setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').css(\'display\', \'none\')', 1000);
        //Setear variables
        if (actTestimonial < largo) actTestimonial = actTestimonial + 1;
        else actTestimonial = 0;

        //Mostrar testimonial
        setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').css(\'display\', \'block\')', 1000);
        setTimeout('$(\'#' + divCnt + ' > div\').eq(' + actTestimonial + ').animate ({opacity:\'1\'}, 1000)', 1000);
        //Habilitar botón
        setTimeout('$(\'#lnkPrev\').removeAttr(\'disabled\');$(\'#lnkNext\').removeAttr(\'disabled\');', 1000);
        
    }
}
//Activa el movimiento automático de la galería.
function activateAutomaticGallery()
{
    setTimeout('seMueveManual = false;',10000);
}
//showing options
function showOptions(divOptions, divSelect) {
		_elem = document.getElementById(divOptions);		
		if (active_select && active_select != _elem) {
			active_select.className = active_select.className.replace('optionsDivVisible','');
			active_select.className += " optionsDivInvisible";
			active_select.style.height = "auto";
		}
		if(_elem.className.indexOf("optionsDivInvisible") != -1) {
			_elem.style.left = "-9999px";
			_elem.style.top = $('#'+divSelect).position().top + _selectHeight + 'px';
			_elem.className = _elem.className.replace('optionsDivInvisible','');
			_elem.className += " optionsDivVisible";
			/*if (_elem.offsetHeight > 200)
			{
				_elem.style.height = "200px";
			}*/
			_elem.style.left = $('#'+divSelect).position().left + 'px';
			
			active_select = _elem;
		}
		else if(_elem.className.indexOf("optionsDivVisible") != -1) {
			_elem.style.height = "auto";
			_elem.className = _elem.className.replace('optionsDivVisible','');
			_elem.className += " optionsDivInvisible";
		}
		//_elem.onmouseout = hideOptions;
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}
function FKeyPressed(object, e, idAscii, objFunc, kE)
{
    //Obtener la tecla presionada
    var objKey;
    if (window.event) objKey = window.event.keyCode;
    else if (e) objKey = e.which;

    //Verificar la tecla presionada y ejecutar la función pasándole el objeto
    if (objKey == idAscii)
    {
        objFunc (object);
        if (kE) rmvEvent (e);
    }
}
function rmvEvent(e)
{
    if (!e)
        var e = window.event;
    if(e.preventDefault) //NS//FF
        e.preventDefault();
    else
    { //IE
        e.cancelBubble = true;
        e.returnValue = false;
        e.keyCode = 0;
    }
}
function fillFiller(fillerStyle)
{
    var hSidebar = $('.sidebar').height() + 4;
    var hContentBox = $('.content-box').height();
    if(hSidebar - hContentBox > 0)
    {
        $('#filler').attr('class', fillerStyle);
        $('#filler').height(hSidebar - hContentBox);
    }
}