$(document).ready(function(){
    $("#fmflickr").hide();
    $("img#home").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#home").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#blog").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#blog").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#mapa").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#mapa").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#fotos").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#fotos").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#tablon").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#tablon").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#web").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#web").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#mail").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#mail").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("#sendImgSubmit").click(function() {
       $("#fmflickr").toggle("slow");
    });
    $("img#btn_facebook").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#btn_facebook").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#btn_twitter").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#btn_twitter").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#btn_vimeo").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#btn_vimeo").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#btn_youtube").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#btn_youtube").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
    $("img#btn_flickr").mouseover(function() {
        var src = $(this).attr("src").replace(/.png/, 'on.png');
        $(this).attr("src", src);
    });
    $("img#btn_flickr").mouseout(function() {
        var src = $(this).attr("src").replace(/on.png/, ".png");
        $(this).attr("src", src);
    });
});

function initPortada() {
    //Inicializar slideshow
    var slideshow = $('#slideshow');
    var images = slideshow.find('div#slide');
    var paginator = slideshow.find('div.pages');
    var controls = slideshow.find('div.controls');
    var box = slideshow.find('div.box');
    var countPages = images.length;
    var currentPage = -1;
    var widthPage = 900;
    var intervalo;

    var paginator_html='<span class="go" rel="back"><img src="http://www.compostlive.com/wp-content/themes/wp_compostlive/images/page-prev.gif" alt="-" /></span>';
    for (var i=0; i<countPages; i++){
        paginator_html+='<span class="go" rel="'+(i+1)+'">'+(i+1)+'</span>';
    }
    paginator_html+='<span class="go" rel="next"><img src="http://www.compostlive.com/wp-content/themes/wp_compostlive/images/page-next.gif" alt="+" /></span>';

    function setPage(page) {
        paginator.find('span').each(function(i) {
            var rel = this.getAttribute('rel');
            switch(rel) {
            case 'back': this.className = (page>1)? 'go':'disabled';break;
            case 'next': this.className = (page<countPages)? 'go':'disabled';break;
            default: this.className='go';
            }
            }).get(page).className='current';

        box.animate({
            'left': -(widthPage)*(page-1)
            }, 1500);
        currentPage=page*1;
    }

    paginator.html(paginator_html).find('span').click(function() {
        clearInterval(intervalo);
        var t = $(this);
        if (t.hasClass('disabled')) return false;
        var page = this.getAttribute('rel');
        if (page=='back') return setPage(currentPage-1);
        if (page=='next') return setPage(currentPage+1);
        setPage(page);
        runInterval();
    });
    $("#play").click(function() {
       clearInterval(intervalo);
       runInterval();
    });
    $("#pause").click(function() {
       clearInterval(intervalo);
    });
    runInterval();
    setPage(1);

    function runInterval() {
        intervalo = setInterval(function(){
            if(currentPage < countPages) {
                currentPage++;
                setPage(currentPage);
            } else {
                currentPage = 1;
                setPage(currentPage);
            }
        }, 5000);
    }
}

var upload_number = 2;
function addFileInput() {
    if(upload_number < 6) {
        var d = document.createElement("div");
        var file = document.createElement("input");
        file.setAttribute("type", "file");
        file.setAttribute("name", "strresume"+upload_number);
        d.appendChild(file);
        document.getElementById("moreUploads").appendChild(d);
        upload_number++;
    }
    if(upload_number == 6) {
        setDisplay();
    }
}
function setBlock() {
   document.getElementById('moreLink').style.display = 'block';
}
function setDisplay() {
   document.getElementById('moreLink').style.display = 'none';
   document.getElementById('maxfiles').style.display = 'block';

}

function enabledButton() {
    if( (document.getElementById('strname').value) != "" ) {
        var email = document.getElementById('stremail').value;
        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (filter.test(email)) {
//        if((document.getElementById('stremail').value) != "") {
            document.getElementById('buttonsubmit').disabled = false;
            return true;
        }
    }
    document.getElementById('buttonsubmit').disabled = true;
    return false;
}

