jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};

$(document).ready(function() {
	//sifr config
	$.sifr({
		path: "wp-content/themes/pistils/fonts/",
		textAlign: "left"
	});
	
	//sifr calls
	$('#content h1, #wideColumn h1').sifr({
		font: "AdobeJensonProBoldCaptionSmallCaps",
		textAlign: "center",
		after: function() { $(this).prepend('<span class=\"titleFlourish before\" />').append('<span class=\"titleFlourish after\" />'); }
	});
	$('#content h2').sifr({
		font: "AdobeJensonProBoldCaptionSmallCaps"
	});
	$('#content h5').sifr({
		font: "AdobeJensonProSemiBoldItalicCaption"
	});
	$('.featured h5').sifr({
		font: "AdobeJensonProBoldCaption"
	});
	
	//image captions
	$("div#subBody img[title]").each(function() {
		
		var $caption = $(this).attr("title");
		var $width = $(this).width();
		var $classes = $(this).attr("class");
		
		$(this).wrap ('<div class="imageContainer ' + $classes + '"></div>').parent().width($width).append ('<span class="caption">' + $caption + '</span>');
	});
		
	$('#header ul.secondaryNav li:first,#footer ul.secondaryNav li:first').addClass('first');
	$('#header ul.secondaryNav li:last,ul#topNav li a:last,#footer ul.secondaryNav li:last').addClass('last');
	
	$('#content p:first').addClass('first');
	
//	$('h1 span.flash-replaced').before('<span class="titleFlourish before"></span>').after('<span class="titleFlourish after"></span>');
	
	$('ul.blogroll li a').wrap('<h4>');
	
	//fix pngs
	$("img[@src$=.png]").ifixpng("/img/pixel.gif");
	$("div.bucketText").ifixpng("/img/pixel.gif");
	$("img.quote").iunfixpng();	
	$("a#alphaFloover").ifixpng();	
	$("div#quote").ifixpng();	
	
	//pull bookmark links
	$('ul.blogroll li').each (function() {
		var $link = $(this).children('h4').find('a').attr('href');
		$(this).children('h4').find('a').clone().text($link).css({ display:"block" }).appendTo($(this));
	});
	$('ul.resourcesCategory li').each (function() {
		
		var $link = $(this).children('a').attr('href');
		$(this).children('a').wrap("<h4></h4>").clone().text($link).css({ display:"block" }).appendTo($(this));
	});
	$(function(){
		$('ul.resourcesCategory li a, ul.blogroll li a, a.newwindow').click(function(){
	        window.open(this.href);
	        return false;
	    });
	});
	$('input:hidden').addClass('hidden');

	$('img.press').parent('p').addClass('pressImg');
	$('body#press p.first').removeClass('first');
	
});
$(window).load(function() {
	//set widths of divs in Safari
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="safari")
		$("div.imageContainer").each(function() {
			var $width = $(this).children("img").width();
			$(this).width($width);
		});
	});
});