$.fn.equalHeights = function(){
	var heights = [], i = this.length;
	while(i--){ heights[i] = this.eq(i).height(); }
/*	return this.height(Math.max.apply(Math, heights)+10); */
}

/*! http://mths.be/placeholder v1.8.4 by @mathias */
(function($){var e='placeholder' in document.createElement('input'),a='placeholder' in document.createElement('textarea');if(e&&a){$.fn.placeholder=function(){return this};$.fn.placeholder.input=$.fn.placeholder.textarea=true}else{$.fn.placeholder=function(){return this.filter((e?'textarea':':input')+'[placeholder]').bind('focus.placeholder',b).bind('blur.placeholder',d).trigger('blur.placeholder').end()};$.fn.placeholder.input=e;$.fn.placeholder.textarea=a;$(function(){$('form').bind('submit.placeholder',function(){var f=$('.placeholder',this).each(b);setTimeout(function(){f.each(d)},10)})});$(window).bind('unload.placeholder',function(){$('.placeholder').val('')})}function c(g){var f={},h=/^jQuery\d+$/;$.each(g.attributes,function(k,j){if(j.specified&&!h.test(j.name)){f[j.name]=j.value}});return f}function b(){var f=$(this);if(f.val()===f.attr('placeholder')&&f.hasClass('placeholder')){if(f.data('placeholder-password')){f.hide().next().attr('id',f.removeAttr('id').data('placeholder-id')).show().focus()}else{f.val('').removeClass('placeholder')}}}function d(){var j,i=$(this),f=i,h=this.id;if(i.val()===''){if(i.is(':password')){if(!i.data('placeholder-textinput')){try{j=i.clone().attr({type:'text'})}catch(g){j=$('<input>').attr($.extend(c(this),{type:'text'}))}j.removeAttr('name').data('placeholder-password',true).data('placeholder-id',h).bind('focus.placeholder',b);i.data('placeholder-textinput',j).data('placeholder-id',h).before(j)}i=i.removeAttr('id').hide().prev().attr('id',h).show()}i.addClass('placeholder').val(i.attr('placeholder'))}else{i.removeClass('placeholder')}}}(jQuery));

$(function(){
	$("a.blank").attr("target", "_blank");
	
	$('a[href^="http://"]').live("click", function(){
		$.get("index.cfm", {
			page: "track",
			url: encodeURI(this.href)
		});
	});
	
	$('input, textarea').placeholder();
	
	$('#icons ul').jcarousel();

	// grocery list dialog
	var recipeList = $('#recipe-list');
	if(recipeList.length) {
		var dialog = $('#ingredients-dialog').dialog({
			autoOpen: false,
			modal: true,
			width: 500,
			height: 400,
			buttons: {
				Print: function() {
					window.location = "http://www.kidkritics.com/recipes/?action=print-groceries&print=true&recipeID=" + dialog.recipeID.split("-")[1];
				},
				Close: function(){
					$(this).dialog("close");
				}
			}
		});
		
		recipeList.delegate(".ingredients-dialog", "click", function(event){
			event.preventDefault();
			dialog.dialog("option", "title", this.getAttribute("data-title"));
			dialog.html( $(this.hash).html() ).dialog("open");
			dialog.recipeID = this.hash;
		});
	}
	
	
	// terms & conditions
	var terms = $("#contest-terms");
	if(terms.length) {
		var dialog = $('<div class="left"></div>')
		.appendTo(document.body)
		.hide()
		.load("/index.cfm?page=terms", { ajax: true })
		.dialog({
			autoOpen: false,
			modal: true,
			width: 700,
			height: 500,
			title: "Terms &amp; Conditions",
			buttons: {
				Close: function(){
					$(this).dialog("close");
				}
			}
		});
		
		terms.bind("click", function(event){
			event.preventDefault();
			dialog.dialog("open");
		});
	}

	// homepage slideshow
	if($("#slideshow").length) {
		var $controls = $("#controls");
		var slideshow = $("#slideshow").slideshow({
			controls:false,
			onChange: function(index){
				$controls.find("a").removeClass("active").filter(function(){
					return $(this).text() == index;
				}).addClass("active");
			}
		});
	
		// bind controls..
		$("a[id^='slideshow-']").bind("click", function(){
			slideshow.slideshow( this.id.split("-")[1] );
			return false;
		});
		$("#controls ul a").bind("click", function(){
			var num = parseInt( $(this).text() );
			slideshow.slideshow("move", num);
			return false;
		});
	}
});


