$(document).ready(function() {

	// Cufon replacemenmts
	Cufon.replace('#content h2', {fontFamily: 'Futura Md BT'});
	Cufon.replace('#content h3', {fontFamily: 'Futura Md BT'});
	Cufon.replace('#content h4', {fontFamily: 'Futura Md BT'});
	Cufon.replace('#comments h2',{fontFamily: 'Futura Md BT'});
	Cufon.replace('#footer h5',  {fontFamily: 'Futura Md BT'});
	Cufon.replace('a.more-link', {fontFamily: 'Futura Md BT'});
	
	// Show/Hide podcast player
	$(".audio").toggle(
		function () {
			$(".podcast.archive").find(".playercontainer").slideUp("fast");
			$(".podcast.archive").find(".audio").removeClass("active");
			$(this).parent(".item").find(".playercontainer").slideDown("fast");
			$(this).addClass("active");
		},
		function () {
			$(this).parent(".item").find(".playercontainer").slideUp("fast");
			$(this).removeClass("active");
	});
	
	// Lightbox for galleries
	$(".gallery").each(function(index, obj){
			var galleryid = Math.floor(Math.random()*10000);
			$(obj).find("a").colorbox({rel:galleryid, maxWidth:"95%", maxHeight:"95%"});
		});
		
	// Generic lightbox hooks
	$("a.lightbox").colorbox({maxWidth:"95%", maxHeight:"95%"});
	$("a[rel='lightbox']").colorbox({width:"800px", height:"80%", iframe:true, rel:"nofollow"});
	$("a[rel='lightbox-print']").colorbox({width:"1100px", height:"80%", iframe:true, rel:"nofollow"});
	$("a[rel='podcast']").colorbox({width:"720px",height:"600px",iframe:false});

	// Search function
	$("#search").val($("#search").attr("title"));
	$("#search").attr("autocomplete","off");
	
	$("#search").focus(
		function () {
			$(this).val('');
		});
	$("#search").blur(
		function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr("title"));
			}
	});
	
	// Newsletter
	$("#emailsubscribe").val($("#emailsubscribe").attr("title"));
	$("#emailsubscribe").attr("autocomplete","off");
	
	$("#emailsubscribe").focus(
		function () {
			$(this).val('');
		});
	$("#emailsubscribe").blur(
		function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr("title"));
			}
	});

	// Show/Hide the categories
	$("#showcategories").click(function(){
		$("#categories").slideToggle();
		if ($("#archives").is(':visible')) { $("#archives").slideUp(); }
		return false;
	});
	
	// Insert ads after the DOM has loaded
	$(function() {
    	var $ads;
    		$('div[id^="adsref-"]').each(function() {
				$ads = $('#ads-' + this.id.substr(7)).empty();
				$('ins:first', this).appendTo($ads);
				//$(this).contents().appendTo($ads);
		});
	});

}); // End document ready
