//Feel free to look and learn, but please don't steal my stuff!
$(window).load(function() {
$("div.home-thumb a img").lazyload({ 
    placeholder : "http://www.vagrantradio.com/wp-content/themes/silver/images/grey.gif",
    effect : "fadeIn" 
});
$("img.size-full").lazyload({ 
    placeholder : "http://www.vagrantradio.com/wp-content/themes/silver/images/grey.gif",
    effect : "fadeIn" 
});
$("div#photos a img").lazyload({ 
    placeholder : "http://www.vagrantradio.com/wp-content/themes/silver/images/grey.gif",
    effect : "fadeIn" 
});
//remove next & prev text in comments pagination
$(".navigation a.next").html("&raquo;");
$(".navigation a.prev").html("&laquo;");
//make all external links target="_blank"
$("a[href^=http://]").not("a[href^=http://www.vagrantradio]").attr("target", "blank");
$("blockquote").before("<span id='tq'></span>");
$("blockquote").after("<span id='bq'></span>");
$(".noimg blockquote").before("<span id='noimgtq'>&#8220;</span>");
$(".noimg blockquote").after("<span id='noimgbq'>&#8221;</span>");
//poular posts toggle
$("#popular h2").toggle(function() {
	$("#popular h2").css("background-position", "0 -34px");
	$("#popular ul").slideUp("slow");
	$.cookie('com_popular', 'collapsed');
	}, 
	function () {
	$("#popular h2").css("background-position", "0 0px");
	$("#popular ul").slideDown("slow");
	$.cookie('com_popular', 'expanded');
	});
// cookie
	var com_popular = $.cookie('com_popular');
	// Set the user's selection for the right column
	if (com_popular == 'collapsed') {
		$("#popular h2").css("background-position", "0 -34px");
		$("#popular ul").hide();
	};
//recent comment toggle
$("#recent-comments-3 h2").toggle(function() {
	$("#recent-comments-3 h2").css("background-position", "0 -34px");
	$("#recent-comments-3 ul").slideUp("slow");
	$.cookie('comments', 'collapsed');
	}, 
	function () {
	$("#recent-comments-3 h2").css("background-position", "0 0px");
	$("#recent-comments-3 ul").slideDown("slow");
	$.cookie('comments', 'expanded');
	});
// cookie
	var comments = $.cookie('comments');
	// Set the user's selection for the right column
	if (comments == 'collapsed') {
		$("#recent-comments-3 h2").css("background-position", "0 -34px");
		$("#recent-comments-3 ul").hide();
	};
//learn something toggle
$("#linkcat-2 h2").toggle(function() {
	$("#linkcat-2 h2").css("background-position", "0 -34px");
	$("#linkcat-2 ul").slideUp("slow");
	$.cookie('linkcat', 'collapsed');
	}, 
	function () {
	$("#linkcat-2 h2").css("background-position", "0 0px");
	$("#linkcat-2 ul").slideDown("slow");
	$.cookie('linkcat', 'expanded');
	});
// cookie
	var linkcat = $.cookie('linkcat');
	// Set the user's selection for the right column
	if (linkcat == 'collapsed') {
		$("#linkcat-2 h2").css("background-position", "0 -34px");
		$("#linkcat-2 ul").hide();
	};
//archives list toggle
$("#archives-3 h2").toggle(function() {
	$("#archives-3 h2").css("background-position", "0 -0px");
	$("#archives-3 ul").slideDown("slow");
	$.cookie('archives', 'collapsed');
	}, 
	function () {
	$("#archives-3 h2").css("background-position", "0 -34px");
	$("#archives-3 ul").slideUp("slow");
	$.cookie('archives', 'expanded');
	});
// cookie
	var archives = $.cookie('archives');
	// Set the user's selection for the right column
	if (archives == 'collapsed') {
		$("#archives-3 h2").css("background-position", "0 -0px");
		$("#archives-3 ul").show();
	};
		//poll list toggle
$("#text-7 h2").toggle(function() {
	$("#text-7 h2").css("background-position", "0 -34px");
	$(".textwidget").slideUp("slow");
	$.cookie('poll', 'collapsed');
	}, 
	function () {
	$("#text-7 h2").css("background-position", "0 -0px");
	$(".textwidget").slideDown("slow");
	$.cookie('poll', 'expanded');
	});
// cookie
	var poll = $.cookie('poll');
	// Set the user's selection for the right column
	if (poll == 'collapsed') {
		$("#text-3 h2").css("background-position", "0 -34px");
		$(".textwidget").hide();
	};

	//user-submitted list toggle
$("#community-news-submissions h2").toggle(function() {
	$("#community-news-submissions h2").css("background-position", "0 -34px");
	$("#community-news-submissions ul").slideUp("slow");
	$("#submit_links").fadeOut("slow");
	$.cookie('comm_news', 'collapsed');
	}, 
	function () {
	$("#community-news-submissions h2").css("background-position", "0 -0px");
	$("#community-news-submissions ul").slideDown("slow");
	$("#submit_links").fadeIn("slow");
	$.cookie('comm_news', 'expanded');
	});
// cookie
	var comm_news = $.cookie('comm_news');
	// Set the user's selection for the right column
	if (comm_news == 'collapsed') {
		$("#community-news-submissions h2").css("background-position", "0 -34px");
		$("#community-news-submissions ul").hide();
		$("#submit_links").hide();
	};
//flickr photos toggle
$("h2#flickr").toggle(function() {
	$("h2#flickr").css("background-position", "0 -34px");
	$("#photos").slideUp("slow");
	$.cookie('flickr', 'collapsed');
	}, 
	function () {
	$("h2#flickr").css("background-position", "0 0px");
	$("#photos").slideDown("slow");
	$.cookie('flickr', 'expanded');
	});
// cookie
	var flickr = $.cookie('flickr');
	// Set the user's selection for the right column
	if (flickr == 'collapsed') {
		$("h2#flickr").css("background-position", "0 -34px");
		$("#photos").hide();
	};
//toggle .comment author url
$(".author a").hover(function() {
		$(this).next("span").css({ display: "inline"});
	}, function() {
		$(this).next("span").css({ display: "none"});
	});
//form validation 
$("input#submit-comment").click(function() {
	$(":input").removeAttr("style");	
	$("#error_message").fadeOut("fast");
	var message = $("textarea#comment").val();
	var author = $("input#author").val();
	var email = $("input#email").val();
	if (message == "") {
		$("textarea#comment").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
	if (author == "") {
		$("input#author").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
	if (email == "") {
		$("input#email").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	} 
});
$("input#fvCommunityNewsSubmit").click(function() {
	$(":input").removeAttr("style");	
	$("#error_message").fadeOut("fast");
	var description = $("textarea#fvCommunityNewsDescription").val();
	var title = $("input#fvCommunityNewsTitle").val();
	var url = $("input#fvCommunityNewsLocation").val();
	if (title == "") {
		$("input#fvCommunityNewsTitle").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
	if (url == "") {
		$("input#fvCommunityNewsLocation").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	} 
	if (description == "") {
		$("textarea#fvCommunityNewsDescription").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
});
$("input#contact-submit").click(function() {
	$(":input").removeAttr("style");	
	$("#error_message").fadeOut("fast");
	var message = $("textarea#comment").val();
	var author = $("input#author").val();
	var email = $("input#email").val();
	if (message == "") {
		$("textarea#comment").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
	if (author == "") {
		$("input#author").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	}
	if (email == "") {
		$("input#email").css("border", "2px solid #900").focus();
		$("#error_message").fadeIn("fast");
		return false;
	} 
});
//back to top scroll function. Any link with a hash (#) will scroll to that id on the page
  $('a[href*=#]').click(function() {
 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
 && location.hostname == this.hostname) {
   var $target = $(this.hash);
   $target = $target.length && $target
   || $('[name=' + this.hash.slice(1) +']');
   if ($target.length) {
  var targetOffset = $target.offset().top;
  $('html,body')
  .animate({scrollTop: targetOffset}, 900);
    return false;
   }
 }
  });
});
//jQuery cookie plugin
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};