if (document && document.documentElement){
    document.documentElement.className = 'js';
}

// Navegación
$(function() {
    $('#s')
        .each(function() {
            this._value = $(this).val();
        })
        .click(function(e) {
            if ($(this).val() == this._value) {
                $(this).val('');
            }
        })
        .blur(function() {
            if (!$(this).val()) {
                $(this).val(this._value);
            }
            
        });
});
// Popups
function utilPopup(e) {
    
    /* Posición */
    var offset = $(this).offset();
    var document_width = document.width ? document.width : document.documentElement.offsetWidth;
    
    offset.top  = offset.top + $(this).outerHeight();
    offset.left = document_width < offset.left + 296 ? ( offset.left - (296 - $(this).outerWidth()) ) : offset.left;
    
    
    $('div.util-popup').hide();
    
    var jquery_selector = '';
    switch (this.className) {
        case 'compartir':
            jquery_selector = '#compartir';
            var self = this;
            $(jquery_selector).find('a').each(function() {
                this.href = this._href.replace('#', $(self).attr('href'));
            });
            break;
        case 'suscribir':
            jquery_selector = '#suscribir';
                var value = $(this).attr('href');
                $('#fuente').val(value);
                
                $('#fuenteLarga').unbind('submit');
                $('#fuenteLarga').submit(function(e){
                    window.open('http://feedburner.google.com/fb/a/mailverify?uri='+value, 'popupwindow', 'scrollbars=yes,width=550,height=520');
                });

        break;
    }
    
    if (jquery_selector != '') {
        e.preventDefault();
        $(jquery_selector).css(offset).fadeIn('fast');
    }
}
$(function() {
    $('div.util-popup span.cerrar').click(function() {
        $(this).parent().hide();
    });
        
    $('.util-atajos a')
        .click(utilPopup);
    $('#compartir a').each(function() {
        this._href = this.href;
    });
});
