$(document).ready(function(){
                
    // Presentation setup
    if(navigator.userAgent.match(/iPad/i) == null){
        //SWF
        var params = {
            allowScriptAccess: "always", 
            wMode: "transparent"
        };
        var atts = {
            id: "presentacion-player"
        };
        swfobject.embedSWF("http://www.youtube.com/e/kc4KhtFnBz8?enablejsapi=1&playerapiid=ytplayer&autohide=1&hd=1",
            "presentacion-video-embed", "698", "393", "8", null, null, params, atts);
    }else{
        //IFRAME/HTML5
        $("#presentacion-activate").remove();
        $("#presentacion-video-fade").remove();
        $("#presentacion-video").removeClass("no-show");
        $("#presentacion-video-embed").html('<iframe width="698" height="393" src="http://www.youtube.com/embed/kc4KhtFnBz8" frameborder="0" allowfullscreen></iframe>');
    }
                
    // Event listener: show presentation
    $("#presentacion-activate").click(function(){
        showPresentation();
    });
                
    // News slider setup
    if(navigator.userAgent.match(/iPad/i) == null){
        $("#news-history-scroll-bar").slider({
            orientation:"vertical",
            range: "min",
            min: 0,
            max: 100,
            value: 100,
            slide: function(event, ui) {
                scrollNewsList(ui.value);
            }
        });
    }else{
        document.addEventListener('touchmove', function(e){
            e.preventDefault();
        });
        var myScroll = new iScroll('news-history-list');
    }
                
    // News press slider setup
    /*if(navigator.userAgent.match(/iPad/i) == null){
        $("#press-history-scroll-bar").slider({
            orientation:"vertical",
            range: "min",
            min: 0,
            max: 100,
            value: 100,
            slide: function(event, ui) {
                scrollNewsPressList(ui.value);
            }
        });
    }else{
        document.addEventListener('touchmove', function(e){
            e.preventDefault();
        });
        var myScroll = new iScroll('press-history-list');
    }*/
                
    // Finoli finoli bio slider setup
    if(navigator.userAgent.match(/iPad/i) == null){
        $("#finoli-bio-scroll-bar").slider({
            orientation:"vertical",
            range: "min",
            min: 0,
            max: 100,
            value: 100,
            slide: function(event, ui) {
                scrollFinoliBioList(ui.value);
            }
        });
    }else{
        document.addEventListener('touchmove', function(e){
            e.preventDefault();
        });
        var myScroll= new iScroll('finoli-bio-scroll-bar');
    }
                
    // Video gallery setup
    videoGallerySetup();
                
    // Photo gallery setup
    photoGallerySetup();
                
    // Bio setup
    var bioEl='<div class="finoli-bio" style="display:none;">';
    bioEl+='<h3><span></span><a id="finolis-backtoshow" href="#">&#171; Volver a Finoli Finoli</a><div style="clear:both;"></div></h3>';
    bioEl+='<p></p>';
    bioEl+='</div>';
    $("#finolis-summary .show-description").after(bioEl);
                
    // Event listener: Finolis bio
    $("#finolis-list .finolis .finoli-summary.clickable").click(function(){
        finolisShowFinoliBio(this);
    });
                
    // Event Listener: News / Press
    $("#news-menu-items span").click(function() {
       newsShow(this);
    });
                
    // Event listener: Other Finolis
    $("#finolis-list h3").click(function(){
        finolisShowOtherFinolis(this);
    });
                
    // Event listener: back to Finoli Finoli summary
    $("#finolis-backtoshow").click(function(){
        finolisShowSummary();
        return false;
    });
                
    $('#formulario #submit').click(function() {
        var form_data = {
            nombre : $('#formulario #nombre').val(),
            email : $('#formulario #email').val(),
            asunto : $('#formulario #asunto').val(),
            mensaje : $('#formulario #mensaje').val(),
            ajax : '1'
        };
        $.ajax({
            url: "http://www.finolifinoli.com/index.php/main/contacto",
            type: 'POST',
            async : false,
            dataType: 'json',
            data: form_data,
            success: function(data) {
                if(data.codigo == 2){
                    $('#formulario #nombre').val('');
                    $('#formulario #email').val('');
                    $('#formulario #mensaje').val('');
                }
                $('#formulario #formRight #contactoMsg').empty().append(data.mensaje);
            }
        });
        return false;
    });
                
});
