$(function() {

	$("a[href^='http']").attr('target','_blank');

	
	// Search Form
	$('#blogsearch input').focus(function() {
		if ($(this).val() == "Search") {$(this).val('');}
	});
	
	
	$('#blogsearch input').blur(function() {
		if ($(this).val() == "") {$(this).val('Search');}
	});
	
	
	// Side Select Jump
	$("#side select").change(function() {
		if ($(this).val()) {
			window.location = $(this).val();
		}
	});
	

	var flashFound = swfobject.hasFlashPlayerVersion("10"); 
	if(!flashFound) {
	
	} else {
		$("a.playlink").each(function() {
			$(this).attr('href', '#');
		});
	}

	// Play
	$("a.playlink").live('click', function() {

		var flashFound = swfobject.hasFlashPlayerVersion("10"); 
		if (!flashFound) {
			var file = $(this).attr('href');
		} else {
			var file = $(this).text();
		}

		var rel = $(this).attr('rel');
		var title = $(this).attr('title');
		
		window.document.header.loadSound(file, title, rel);
		return(false);
		
	});
	
	// Faves
	$('a.favetrigger').click (function() {
		
		if ($('.loggedin').text() == 'true') {
		
			var $el = $(this);
			var rel = $el.attr('rel');
		
			$.getJSON($el.attr('href'), function(data) {
			
				if (data.result == "added") {
					$el.html('Unfav! - '+ data.count);
					$el.addClass('faved');
					$el.attr('href', 'http://yesyesyall.org/_function/save_favorite' + $el.attr('rel') + '/delete');
				} else if (data.result == "deleted") {
					$el.html('Fav! - '+ data.count);
					$el.removeClass('faved');
					$el.attr('href', 'http://yesyesyall.org/_function/save_favorite' + $el.attr('rel'));
				}
			
			});
		
		} else {
			
			showModal('/user/login');
			
		}
		
		return false;
	});
	
	// infinitescroll() is called on the element that
	// surrounds the items you will be loading more of
	$('#content-inner').infinitescroll({
		navSelector : ".navigation",
		nextSelector : "a.next",
		itemSelector : ".postdiv",
		loadingImg : "/images/site/ajax-loader.gif",
		bufferPx : 100
	}, function() {
		//var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		//if (window.addthis) { window.addthis = null; }
		//$.getScript(script);
		addthis.toolbox('.addthis_toolbox');
	});
	
	
	

	// Share button
	$('.addthis_toolbox').live('mouseenter', function() {
		
		$hover_menu = $(this).children('.hover_menu');
		$custom_button = $(this).children('.custom_button');
	
        $hover_menu.fadeIn('fast');
        $custom_button.addClass('active');
        $(this).data('in', true);
        $hover_menu.data('hidden', false);

    });

	$('.addthis_toolbox').live('mouseleave', function() {
	
		$hover_menu = $(this).children('.hover_menu');
		$custom_button = $(this).children('.custom_button');
	
        $(this).data('in', false);

		$('.hover_menu').fadeOut('fast');
		$('.custom_button').removeClass('active');
		$('.hover_menu').data('hidden', true);

    });
	
});
