function initHomePageNews() {
	var blog_post_nexts = $('div.blog_post a.next_post');
	blog_post_nexts.bind("click", function(e) {

		if ($(this).parents('div.blog_post').next('div.blog_post').hasClass('blog_post')) {
			$(this).parents('div.blog_post').hide().next('div.blog_post').show();
		}
		else {
			$(this).parents('div.blog_post').hide();
			$('div.blog_posts div.first').show();
		}

		e.preventDefault();
	});
}

function initHomePageTwitter() {
	var next_tweet = $('a.next_tweet');
	next_tweet.bind("click", function(e) {

		if ($('ul.twitter li.current').next('li').length > 0) {
			$('ul.twitter li.current').removeClass('current').next('li').addClass('current');
		}
		else {
			$('ul.twitter li.current').removeClass('current');
			$('ul.twitter li:first').addClass('current');
		}

		e.preventDefault();
	});
}

function initProjectThumnails() {
	var project_thumnails = $('ul#project_thumbnails li a img');
	
	project_thumnails.each(function() {
		$("<img>").attr("src", $(this).attr("src").replace('s.','l.'));
	});
	
	project_thumnails.bind("mouseenter mouseleave", function(e){
    	$(this).toggleClass("hover");
	});

	project_thumnails.bind("click", function(e) {
	    var whatIClicked = $(this);
	    $('ul#project_thumbnails li a img').removeClass("active");
	    $(this).addClass("active");
	    /*
	    $('div.current_image img').attr({ 
	    src: $(this).attr("src").replace('s.','l.')
	    });
	    */
	    $('div.current_image img').fadeOut("slow", function() {
	        $('div.current_image img').attr({
	            src: whatIClicked.attr("src").replace('s.', 'l.')
	        });
	        $('div.current_image img').fadeIn("slow");
	    });
	    e.preventDefault();
	});
}

function initSearchBox() {
	var search_box = $("input#search_query");
		
	if (search_box.val() == "" || search_box.val() == "search") {
		search_box.val("search");
		search_box.addClass("placeholder");
	}
	
	search_box.bind("focus", function(e){
		if ($(this).val() == "search") {
			$(this).val("");
			$(this).removeClass("placeholder");
		}
	});
	search_box.bind("blur", function(e){
		if ($(this).val() == "") {
			$(this).val("search");
			$(this).addClass("placeholder");
		}
	});
	
	if (navigator.userAgent.indexOf("Safari") < 0)
	{
		$('body').addClass('not_safari');
	}
	
}

function initWorkNav() {
    if ($('body.work').is(':visible')) {
        //BancTec
        if ($('body.banctec').is(':visible')) {
            $('li.banctec').remove().prependTo('ul#section_navigation');
        }
        //CoServ
        if ($('body.coserv').is(':visible')) {
            $('li.coserv').remove().prependTo('ul#section_navigation');
        }
        //Dell
        if ($('body.dell').is(':visible')) {
            $('li.dell').remove().prependTo('ul#section_navigation');
        }
        //Destination Beer
        if ($('body.destinationbeer').is(':visible')) {
            $('li.destinationbeer').remove().prependTo('ul#section_navigation');
        }
        //Ducati
        if ($('body.ducati').is(':visible')) {
            $('li.ducati').remove().prependTo('ul#section_navigation');
        }
        //Entrust
        if ($('body.entrust').is(':visible')) {
            $('li.entrust').remove().prependTo('ul#section_navigation');
        }
        //Falcon
        if ($('body.falcon').is(':visible')) {
            $('li.falcon').remove().prependTo('ul#section_navigation');
        }
        //Handango
        if ($('body.handango').is(':visible')) {
            $('li.handango').remove().prependTo('ul#section_navigation');
        }
        //LogLogic
        if ($('body.loglogic').is(':visible')) {
            $('li.loglogic').remove().prependTo('ul#section_navigation');
        }
        //MLAB
        if ($('body.mlab').is(':visible')) {
            $('li.mlab').remove().prependTo('ul#section_navigation');
        }
        //NationPoint
        if ($('body.nationpoint').is(':visible')) {
            $('li.nationpoint').remove().prependTo('ul#section_navigation');
        }
        //New York Times
        if ($('body.newyorktimes').is(':visible')) {
            $('li.newyorktimes').remove().prependTo('ul#section_navigation');
        }
        //PlainsCapital
        if ($('body.plainscapital').is(':visible')) {
            $('li.plainscapital').remove().prependTo('ul#section_navigation');
        }
        //Rees
        if ($('body.rees').is(':visible')) {
            $('li.rees').remove().prependTo('ul#section_navigation');
        }
        //Rough Creek Lodge
        if ($('body.roughcreeklodge').is(':visible')) {
            $('li.roughcreeklodge').remove().prependTo('ul#section_navigation');
        }
        //Southwest Airlines
        if ($('body.southwest_airlines').is(':visible')) {
            $('li.southwest_airlines').remove().prependTo('ul#section_navigation');
        }
        //Texadelphia
        if ($('body.texadelphia').is(':visible')) {
            $('li.texadelphia').remove().prependTo('ul#section_navigation');
        }
        //Trainline
        if ($('body.trainline').is(':visible')) {
            $('li.trainline').remove().prependTo('ul#section_navigation');
        }
        //Triple
        if ($('body.triple').is(':visible')) {
            $('li.triple').remove().prependTo('ul#section_navigation');
        }
        //U.S. Home Team
        if ($('body.ushometeam').is(':visible')) {
            $('li.ushometeam').remove().prependTo('ul#section_navigation');
        }
        //Verizon
        if ($('body.verizon').is(':visible')) {
            $('li.verizon').remove().prependTo('ul#section_navigation');
        }
    }
}

$(document).ready(function() {
	initHomePageNews();
	initHomePageTwitter()
	initProjectThumnails();
	initSearchBox();
	//initWorkNav();
});