/* Info slide */

var info_interval = null;
var info_current = 1;

var preload = [];

preload[0] = new Image();
preload[0].src = '/resources/images/banner/1.jpg';

preload[1] = new Image();
preload[1].src = '/resources/images/banner/2.jpg';

preload[2] = new Image();
preload[2].src = '/resources/images/banner/3.jpg';

preload[3] = new Image();
preload[3].src = '/resources/images/banner/4.jpg';

$(document).ready(function () {

    $('.info .text').hide();

    $('.info .text-1').show();

    info_interval = setInterval('info_animate(null)', 6000);

    $('.info .nav a').click(function (e) {
        e.preventDefault();

        clearInterval(info_interval);

        info_animate(parseInt($(this).text()));
    })
});

var info_lock = false;

function info_animate(current)
{
    if (info_lock == true)
        return;
    info_lock = true;

    $('.info .nav a.selected').removeClass('selected');

    var info_last = info_current % 4;
    if (info_last == 0)
        info_last = 4;
    
    info_current++;

    if (current == null)
    {
        current = info_current % 4;
        if (current == 0)
            current = 4;
    }
    else
    {
        info_current = current;
    }

    $('.info .nav .a-' + current).addClass('selected');

    $('.info .text-' + info_last).fadeOut('slow', function () {
        $('.info .text-' + current).fadeIn('slow');

        $('#banner').css('background-image', 'url(/resources/images/banner/'+ current +'.jpg)');

        info_lock = false;
    });
}

/* Menu */

$(document).ready(function () {

    $('#info .close a').click(function (e) {
        e.preventDefault();

        $('#servicios #info').effect('drop', {}, 'slow', function () {
            $('#servicios .mas-info').fadeIn('slow');
        });
    });

    $('#servicios .mas-info a').click(function (e) {
        e.preventDefault();

        $('#servicios .mas-info').fadeOut('slow', function () {
            $('#servicios #info').css('left', 0);
            $('#servicios #info').show();
            $('#servicios #nav a.selected').trigger('click');
        });
    });

    $('.servicios-slide').cycle({
        fx: 'fade'
    });

    /*$('#servicios #nav a').click(function (e) {
        e.preventDefault();

        var id = $(this).attr('id');

        $('#servicios #info').fadeOut('slow', function () {

            if (id == 'sonido')
                $('#servicios #info').css('left', 20)
            else if (id == 'instalacion')
                $('#servicios #info').css('left', 180)
            else if (id == 'produccion')
                $('#servicios #info').css('left', 390)
            else if (id == 'iluminacion')
                $('#servicios #info').css('left', 515)

            $('#servicios #info .wrapper').hide();
            $('#servicios #info .' + id).show();
            
            $('#servicios #info').fadeIn('slow');
        })
    })*/

    var servicios_lock = false;

    $('#servicios #nav a').click(function (e) {
        $('.servicios-slide').cycle('destroy');

        e.preventDefault();

        if (servicios_lock == true)
            return;
        servicios_lock = true;

         $('#servicios #info .wrapper').hide();
         $('#servicios #nav a.selected').removeClass('selected');
         $(e.target).addClass('selected');

        var id = $(this).attr('id');

        if (id == 'sonido')
        {
            $('#servicios #info').animate( { left: 20 }, 1200, 'easeOutElastic',  function () { callback() } );
            $('.servicios-slide').html('\
                    <img src="/resources/images/servicios/sonido/1.jpg" />\
                    <img src="/resources/images/servicios/sonido/2.jpg" />\
                    <img src="/resources/images/servicios/sonido/3.jpg" />\
                    <img src="/resources/images/servicios/sonido/4.jpg" />\
                    <img src="/resources/images/servicios/sonido/5.jpg" />\
                    <img src="/resources/images/servicios/sonido/6.jpg" />\
                ');
        }
        else if (id == 'instalacion')
        {
            $('#servicios #info').animate( { left: 180 }, 1200, 'easeOutElastic', function () { callback() })
            $('.servicios-slide').html('\
                    <img src="/resources/images/servicios/instalacion/1.jpg" />\
                    <img src="/resources/images/servicios/instalacion/2.jpg" />\
                    <img src="/resources/images/servicios/instalacion/3.jpg" />\
                    <img src="/resources/images/servicios/instalacion/4.jpg" />\
                ');
        }
        else if (id == 'produccion')
        {
            $('#servicios #info').animate( { left: 390 }, 1200, 'easeOutElastic', function () { callback() })
            
            $('.servicios-slide').html('\
                    <img src="/resources/images/servicios/produccion/1.jpg" />\
                    <img src="/resources/images/servicios/produccion/2.jpg" />\
                    <img src="/resources/images/servicios/produccion/3.jpg" />\
                    <img src="/resources/images/servicios/produccion/4.jpg" />\
                    <img src="/resources/images/servicios/produccion/5.jpg" />\
                ');
        }
        else if (id == 'iluminacion')
        {
            $('#servicios #info').animate( {left: 515 }, 1200, 'easeOutElastic', function () { callback() })
            
            $('.servicios-slide').html('\
                    <img src="/resources/images/servicios/iluminacion/1.jpg" />\
                    <img src="/resources/images/servicios/iluminacion/2.jpg" />\
                    <img src="/resources/images/servicios/iluminacion/3.jpg" />\\n\
                    <img src="/resources/images/servicios/iluminacion/4.jpg" />\
                ');
        }

       var callback = function()
       {
            $('#servicios #info .' + id).show();
            servicios_lock = false;

            $('.servicios-slide').cycle({
                fx: 'fade'
            });
       }
    });

    var clientes_lock = false;

    $('#clientes-nav a').click(function (e) {
        
        e.preventDefault();

        if (clientes_lock == true)
            return;
        clientes_lock = true;

        $('#clientes-nav a.selected').removeClass('selected');


        var id = $(this).attr('id');

        $('.contenido .wrapper').filter(':visible').fadeOut('slow', function () {
            if (id == 'instituciones')
                $('#nav-arrow').animate( {left: 135 }, 1200, 'easeOutElastic', function () { callback() })
            else if (id == 'teatro')
                $('#nav-arrow').animate( {left: 215 }, 1200, 'easeOutElastic', function () { callback() })
            else if (id == 'productoras')
                $('#nav-arrow').animate( {left: 300 }, 1200, 'easeOutElastic', function () { callback() })
            else if (id == 'comercios')
                $('#nav-arrow').animate( {left: 385 }, 1200, 'easeOutElastic', function () { callback() })
            else if (id == 'colegios')
                $('#nav-arrow').animate( {left: 460 }, 1200, 'easeOutElastic', function () { callback() })

            var callback = function()
            {
                $(e.target).addClass('selected');
                $('.contenido .' + id).fadeIn('slow');

                clientes_lock = false;
            }
            
        })
    })
});
