$(function(){

    // Nix the widows
    $('blockquote, h1 a, h1').widont();
    
    $('div.post_info_bottom').css({display: 'block'});
    
    // Customize Vimeo player
    $("object[data^='http://vimeo.com']").each(function() {
    		var parent = $(this).parent();
    		var vimeoCode = parent.html();
    		var params = "";
    		if (vimeoCode.toLowerCase().indexOf("<param") == -1) {
    			$("param", this).each(function() {
    				params += $(this).get(0).outerHTML;
    			});
    		}
    		var oldOpts = /show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF/g;
    		var newOpts = "show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=FFE75A";
    		vimeoCode = vimeoCode.replace(oldOpts, newOpts);
    		if (params != "") {
    			params = params.replace(oldOpts, newOpts);
    			vimeoCode = vimeoCode.replace(/<embed/i, params + "<embed");
    		}
    		parent.html(vimeoCode);
    	});

    // Customize Youtube player
    $("object").each(function() {
        if ($(this).find("param[value^='http://www.youtube.com']").length > 0) {
            var parent = $(this).parent();
            var youtubeCode = parent.html();
            var params = "";
            if (youtubeCode.toLowerCase().indexOf("<param") == -1) {
                $("param", this).each(function() {
                    params += $(this).get(0).outerHTML;
                });
            }
            var oldOpts = /rel=0/g;
            var newOpts = "rel=0&amp;hd=1&amp;color1=0xf1f1f1&amp;color2=0xf3f3f3";
            youtubeCode = youtubeCode.replace(oldOpts, newOpts);
            if (params != "") {
                params = params.replace(oldOpts, newOpts);
                youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed");
            }
            parent.html(youtubeCode);
        }
    });
    	
    // Search samples
	var searches = ['interface', 'design', 'typography','Apple', 'iPad', 'jQuery', 'web', 'iPhone', 'app', 'javascript'];
    $('#searchbox').not('body.search #searchbox').addClass('hint').attr('value', 'Search (eg. ' + searches[Math.floor(Math.random()*7)] + ')').one('focus', function(){$(this).attr('value', '').removeClass('hint')});
    
    // $('header').hover(function(){
    //     $(this).find('nav').animate({'height': 50}, 250);
    // }, function(){
    //     $(this).find('nav').animate({'height': 10}, 250);
    // });
    
    // Fix the Tumblr controls
    $('#tumblr_controls').css('position', 'fixed');
    
    // For "ask" and "submit" pages
    if ($('li.time').text() == '')
    {        
        $('li.time').closest('footer').remove();
    }
    
    // Share icons
    $('.social').hide().each(function(){
        var $parent = $(this).closest('article');
        var fulltitle = $('h1, blockquote, p', $parent).slice(0,1).text();
        var title = fulltitle.substr(0,80);
        var url = $parent.data('permalink');
        var shorturl = $parent.data('shortlink');

        if (title.length < fulltitle.length) {
            title += '...';
            if ($parent.hasClass('quote')) title += '”';
        }
        

        // console.log(title);
        // console.log(url);
        // console.log(shorturl);

        $('.soc-twitter', $parent).attr('href', 
            'http://twitter.com/home?status=' + title + '%3A%20'+ shorturl + '%20%2Fvia%20%40DavidKaneda');
        $('.soc-stumble', $parent).attr('href', 
            'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
        $('.soc-moo', $parent).attr('href', 
            'http://designmoo.com/submit/?url=' + url + '&title=' + title);
        $('.soc-bump', $parent).attr('href', 
            'http://designbump.com/submit/?url=' + url + '&title=' + title);
        $('.soc-linkedin', $parent).attr('href', 
            'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&source=http://www.davidkaneda.com');
        $('.soc-delicious', $parent).click(function(){
            window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+url+'&amp;title='+title,'delicious', 'toolbar=no,width=550,height=550');
            return false;
        })
        $('.social a').attr('target', '_blank');
        

    });
    
    $('.social').parent().hover(function(){
        $('.sharelabel', this).hide(0);
        $('.social', this).show(0);
    }, function(){
        $('.sharelabel', this).show(0);
        $('.social', this).hide(0);
    })
    
    
        
})