<script>

jQuery(document).ready(function(){
    calc_video_height();
    jQuery('.controls_fullscreen').css('cursor', 'pointer');

    _fullscreen = jQuery('.controls_fullscreen').children('img');
    _srcimg = _fullscreen.attr('src');

    _fullscreen.hover(
        function() { 
            _fullscreen.attr('src', _srcimg.replace('fullscreen.png', 'fullscreen_on.png'));
        },
        function() { 
            _fullscreen.attr('src', _srcimg.replace('fullscreen_on.png', 'fullscreen.png'));
        }
    );

    _fullscreen.bind('click', function(){        
        if (jQuery('#the_slider').hasClass('fullscreen_div')) {
            jQuery('#the_slider').removeClass('fullscreen_div');
            jQuery('.mediaWrapper').css('width', '');
            jQuery('.youtubeHolder').css('width', '');
            jQuery('.vimeoHolder').css('width', '');
            _fullscreen.parent().appendTo(jQuery('#dedicationFooter_container .columns.two.last'));
        } else {
            jQuery('#the_slider').addClass('fullscreen_div');
            _fullscreen.attr('src', _srcimg.replace('fullscreen.png', 'fullscreen_exit.png'));            
            //_fullscreen.parent().appendTo(jQuery('.slideshow_controls'));
            _fullscreen.parent().appendTo(jQuery('#componentWrapper'));
        }
        calc_video_height();
    });
    
    jQuery(window).resize(function(){calc_video_height()});
});

function calc_video_height() {
    if (jQuery('#the_slider').hasClass('fullscreen_div')) {
        jQuery('#componentWrapper').css('height', '100%').css('height', '-=115px');
    } else {
        if (jQuery('#componentWrapper').css('height') != '500px') {
            jQuery('#componentWrapper').css('height', '500px');
        }
    }
}

   
jQuery(document).ready(function(){
    jQuery('.home-page .wp-pagenavi a').live('click', function(e){
        e.preventDefault();
        link = jQuery(this).attr('href');
        jQuery('.home-page .wp-pagenavi').remove();
        
        jQuery.get(link, function(data) {
            var kids = jQuery(data).find('.contentInner').children();
            jQuery.each(kids, function(){
                jQuery('#content-wrapper #content .contentInner').append(jQuery(this));
            });            
        });
    });
    
    jQuery('.dedication-profile .home_column_my_dedications a.read-more').live('click', function(e){
        e.preventDefault();
        link = jQuery(this).attr('href');
        jQuery('.dedication-profile .home_column_my_dedications a.read-more').remove();
        
        jQuery.get(link, function(data) {
            var kids = jQuery(data).find('#content').children();
            jQuery.each(kids, function(){
                if (jQuery(this).hasClass('post-loop')) {
                    jQuery(this).removeClass();
                    jQuery(this).addClass('home-my-dedications post-loop');
                }
                jQuery('.dedication-profile .home_column_my_dedications').append(jQuery(this));
            });            
        });
    });    
    
    
    jQuery('.dedication-profile .home_column_dedicated_2_me a.read-more').live('click', function(e){
        e.preventDefault();
        link = jQuery(this).attr('href');
        jQuery('.dedication-profile .home_column_dedicated_2_me a.read-more').remove();
        
        jQuery.get(link, function(data) {
            var kids = jQuery(data).find('#content').children();
            jQuery.each(kids, function(){
                if (jQuery(this).hasClass('post-loop')) {
                    jQuery(this).removeClass();
                    jQuery(this).addClass('home-dedicated-2-me post-loop');
                }
                jQuery('.dedication-profile .home_column_dedicated_2_me').append(jQuery(this));
            });            
        });
    });    
    
});

var aIndex=-1;
var oUrl='';

function updateInfo() {
    var id = jQuery.fn.videoGallery.getMediaID();

    if ((aIndex != id) && (id >= 0)) {
        aIndex = id;

        if (oUrl == '') {
            oUrl = jQuery('#dedicate_this_song_button').attr("href");
        }

        var the_id = jQuery('#postdata-id-' + id).text();
        var new_title = jQuery('#postdata-title-' + id).html();
        var from_to = jQuery('#postdata-from-to-' + id).html();
        var artist = jQuery('#postdata-artist-' + id).html();
        var song = jQuery('#postdata-song-' + id).html();
        var link = jQuery('#postdata-link-' + id).html();
        var enc_link = jQuery('#postdata-extlink-' + id).html();

        var nUrl = oUrl + 'id/' + the_id;
        jQuery('#dedicate_this_song_button').attr("href", nUrl);

        // Social networks
        nUrl = 'https://www.facebook.com/sharer.php?u=' + enc_link;
        jQuery('#fsbbtn a').attr("href", nUrl);
        nUrl = 'http://twitter.com/intent/tweet?source=sharethiscom&url=' + enc_link;
        jQuery('#twtbtn a').attr("href", nUrl);
        nUrl = 'https://plusone.google.com/_/+1/confirm?url=' + enc_link;
        jQuery('#gpsbtn a').attr("href", nUrl);
        nUrl = 'javascript:void(window.open("http://www.myspace.com/Modules/PostTo/Pages/?u=' + enc_link + '"+encodeURIComponent(document.location.toString()),"ptm","height=450,width=550").focus())';
        jQuery('#mysbtn a').attr("href", nUrl);


        jQuery('#dedication-data-panel').hide('fast');
        jQuery('#dedication-data-panel').slideUp(
            'fast',
            function() { 
                jQuery('#dedication-data-panel').html(from_to); 
                jQuery('#dedicationTitle-data-panel').html(from_to);                        
            }
        );
        jQuery('#dedication-data-panel').slideDown();

        jQuery('#dedicationFooter_container').slideUp(
            'fast',
            function() { 
                jQuery('#dedicationArtits').html(artist);
                jQuery('#dedicationSong').html(song);
            }
        );
        jQuery('#dedicationFooter_container').slideDown(
            'fast',
            function() {}
        );
        jQuery('#dedicationTitle').html(new_title); 
        shrinkTitle(); 
        jQuery('#dedicationTitle a').jTypeWriter(); 

        jQuery('#dedicationComments_container').slideUp(
            'fast',
            //function() { jQuery('#dedicationComments_container').html(comments); }
            function() {                 
                jQuery('#dedicationComments_container').load(
                    link + ' #comments', '', function(data) {
                        init_comments();
                        jQuery('#dedicationComments_container').on('submit', 
                            '#commentform', 
                            function() {
                                prepare_new_comment_home();
                                return false;
                            }
                        )
                    }
                );
            }
        );                
        jQuery('#dedicationComments_container').slideDown();
               
               
        if(jQuery('#postdata-mark-read-' + id).length > 0) {
            console.log('doy por leido ' + id);
            jQuery('#postdata-mark-read-' + id + ' .mar_mark_as_read').click();
            jQuery('#postdata-mark-read-' + id).remove();                
            console.log('quito elemento ' + id);
        }
    }
}

function shrinkTitle()
{
    var textH1 = document.getElementById("dedicationTitle");
    var textDiv = document.getElementById("dedicationTitle_container");

    textH1.style.fontSize = 42+"px";
    while(textH1.offsetWidth > textDiv.offsetWidth)
    {
        size = parseInt(textH1.style.fontSize.replace("px",""));
        size -= 1;
        textH1.style.fontSize = size+"px";
    }
    textH1.style.fontSize -= 10+"px";
}

   

jQuery(window).ready(function() {
    
    if (jQuery('#slider-wrapper').length > 0 ) {
        jQuery('#content-wrapper .post-loop .post-thumbnail a').click(function(e) {
            e.preventDefault();
            var oUrl = jQuery(this).attr('href');
            jQuery('#playlist li [id^=postdata-link-]').each(function(indice, valor){
                var nUrl = jQuery(this).html();
                if (nUrl == oUrl) {
                    jQuery('#componentWrapper').videoGallery.loadMedia(indice);
                    return false;
                }
            });
            return false;
        });
    }
    
    if (jQuery('#slider-wrapper')) {        
        jQuery('#componentWrapper').videoGallery({			
            componentFixedSize: true,
            animateVideoSizeOnPlaylistClose: true,
            thumbOrientation: 'vertical',
            activePlaylist:'playlist',
            activeVideo:0,
            autoPlay:true,
            loopingOn:false,
            randomPlay:false,            
            autoAdvanceToNextVideo:true,
            youtubeChromeless:false,
            thumbWidth: 120,
            thumbHeight: 90,
            thumbsScrollValue: 150,
            autoOpenPlaylist: false,
            closePlaylistOnVideoSelect: false,
            thumbBackgroundColor: '#fff',
            iconLoader: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/loader.gif',
            iconClose: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/close.png',
            iconCloseOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/close_on.png',
            iconOpen: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/open.png',
            iconOpenOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/open_on.png',
            iconBackwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/backward_on.png',
            iconBackward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/backward.png',
            iconForwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/forward_on.png',
            iconForward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/forward.png',
            iconShare: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/share.png',
            iconShareOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/share_on.png',
            iconThumbForward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward.png',
            iconThumbForwardV: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_v.png',
            iconThumbForwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_on.png',
            iconThumbForwardVOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_v_on.png',
            iconThumbBackward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward.png',
            iconThumbBackwardV: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_v.png',
            iconThumbBackwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_on.png',
            iconThumbBackwardVOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_v_on.png',
            videoGallerySetupDone: function(){setInterval("updateInfo()", 750);},
            videoGalleryPlaylistEnd: function(){
                redirect();
            } 
        });
        
    }
});

jQuery(document).ready(function(){
    jQuery('#sidebar .sidebarposts .top_10 .posts').hide();
    jQuery('#sidebar .sidebarposts .top_10 h3').click(function() {
        jQuery('#sidebar .sidebarposts .top_10 .posts').toggle('slow', function() {});
    });
});

</script>