﻿/**********************************************************************
IMPORTANTE!!! LEE ESTO!!!
Desarrollado por: DIGITALEX - Elkin Siabato
Bogotá - Colombia.
NO COPIES EL CÓDIGO, CONTÁCTAME, y PREGUNTAMÉ que necesitas.
Y siempre da las gracias a todos, no pierdes nada. Te sentirás muy bien.
Blog de contacto para que preguntes: http://graciasinternet.blogspot.com/
Mail: elkin0727@yahoo.com.ar
***********************************************************************/
var numslides;
var slidemostrar;
var timeperiodo;
$(document).ready(function(){

});
function iniciartodo()
{
	
	$('.bannerdescripcion').css('visibility', 'visible');
    $('.slide').css("margin-left", -1 * (1920 - $(window).width()) / 2);
    numslides = $('.slide').length;
    slidemostrar = 0;
    mostrarSlide(); //inicio

    timeperiodo = setInterval("autoslide()", $('#slide' + slidemostrar).attr('tiempo'));
    $('.flechaizq').click(function() {
        clearInterval(timeperiodo);
        getPrev();
        mostrarSlide();
    });
    $('.flechader').click(function() {
        clearInterval(timeperiodo);
        getNext();
        mostrarSlide();
    });
    //opciones click
    $('#optbanner1').click(function() {
        clearInterval(timeperiodo); slidemostrar = 0; mostrarSlide();
    });
    $('#optbanner2').click(function() {
        clearInterval(timeperiodo); slidemostrar = 1; mostrarSlide();
    });
    $('#optbanner3').click(function() {
        clearInterval(timeperiodo); slidemostrar = 2; mostrarSlide();
    });
    $('#optbanner4').click(function() {
        clearInterval(timeperiodo); slidemostrar = 3; mostrarSlide();
    });
    //efecto opciones
    $('#optbanner1').mouseenter(function() {
        mostrarOpctionBanner($('#optbanner1imagen'));
    });
    $('#optbanner1').mouseleave(function() {
        setTimeout("restartOptionbanner('#optbanner1imagen');", 10);
    });
    $('#optbanner2').mouseenter(function() {
        mostrarOpctionBanner($('#optbanner2imagen'));
    });
    $('#optbanner2').mouseleave(function() {
        setTimeout("restartOptionbanner('#optbanner2imagen');", 10);
    });
    $('#optbanner3').mouseenter(function() {
        mostrarOpctionBanner($('#optbanner3imagen'));
    });
    $('#optbanner3').mouseleave(function() {
        setTimeout("restartOptionbanner('#optbanner3imagen');", 10);
    });
    $('#optbanner4').mouseenter(function() {
        mostrarOpctionBanner($('#optbanner4imagen'));
    });
    $('#optbanner4').mouseleave(function() {
        setTimeout("restartOptionbanner('#optbanner4imagen');", 10);
    });
}
//efecto de opciones
var aumento = 40;
var heightNormal = 100;
function mostrarOpctionBanner(id) {
    clearInterval(timeperiodo);
    var heightup = heightNormal + aumento;
    $(id).stop(true, false);
	//alert('#' + $(id).attr('id').replace("imagen", "desc"));
    $(id).animate({
        top: -aumento,
        height: heightup
    },
    {
        duracion: 500,
        complete: finMostrar
    });
	//animacion descripcion
	$('#' + $(id).attr('id').replace("imagen", "desc")).animate({
        top: 30
    },
    {
        duracion: 500
    });
}
function finMostrar() {
    if ($(this).css('top') == -aumento + "px") {
        $('#' + $(this).attr('id').replace('imagen', 'desc')).fadeIn();
    }
}
function restartOptionbanner(id) {
    clearInterval(timeperiodo);
    var heightnormal = parseInt($(id).css("height")) - aumento;
    $(id).animate({
        top: "0",
        height: heightNormal
    },
    {
        duracion: 500,
        complete: finOcultar
    });
	//animacion descripcion
	$(id.replace('imagen', 'desc')).animate({
        top: -5
    },
    {
        duracion: 500
    });
    
}
function finOcultar() {
    //alert('#' + $(this).attr('id').replace('imagen','desc'));
    //$('#' + $(this).attr('id').replace('imagen', 'desc')).css("display", "none");
}
//core para slide de banners
function getPrev() {
    if (slidemostrar == 0) {
		slidemostrar = numslides - 1;
    }
    else {
        slidemostrar--;
    }
}
function getNext() {
    if (slidemostrar == numslides - 1) {
        slidemostrar = 0;
    }
    else {
        slidemostrar++;
    }
}
function autoslide() {
    getNext();
    mostrarSlide();
}
function mostrarSlide() {
    for (i = 0; i < numslides; i++) {
        if (slidemostrar != i) {
            $('#slide' + i).fadeOut('slow');
			if($('#slide' + i).attr('type') == 'swf')
				{
					imprimirSWF($('#slide' + i).children(':first-child').attr('id'), 'swf/blank.swf', '1', '1');
				}
        }
        else {
            $('#slide' + slidemostrar).fadeIn('slow', function() {
                clearInterval(timeperiodo);
                timeperiodo = setInterval("autoslide()", $('#slide' + slidemostrar).attr('tiempo'));
            });
			if($('#slide' + slidemostrar).attr('type') == 'swf')
				{
					imprimirSWF($('#slide' + slidemostrar).children(':first-child').attr('id'), '../swf/' + $('#slide' + slidemostrar).children(':first-child').attr('id') + '.swf', '1920', '400');
				}
        }

    }
}
function mostrarSlideAhora(idslide){
	clearInterval(timeperiodo);
	for (i = 0; i < numslides; i++) {
        if (idslide != i) {
            $('#slide' + i).fadeOut('slow');
        }
        else {
		
            $('#slide' + idslide).fadeIn('slow', function() {
                clearInterval(timeperiodo);
                timeperiodo = setInterval("autoslide()", $('#slide' + idslide).attr('tiempo'));
            });
			if($('#slide' + idslide).attr('type') == 'swf')
				{
					imprimirSWF($('#slide' + idslide).children(':first-child').attr('id'), '../swf/' + $('#slide' + idslide).children(':first-child').attr('id') + '.swf', '1920', '400');
				}
        }
    }
}
$(window).resize(function() {
    $('.slide').css("margin-left", -1 * (1920 - $(window).width()) / 2);
});

function redirectURL(URL, type) {	
	if(type == null)
	{
		var newWindow = window.open(URL, '_self');
		newWindow.focus();
	}
	else{
		var newWindow = window.open(URL, type);
		newWindow.focus();
	}
	
}
