$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) {
				currentTallest = $(this).height();
			}
		});
		// if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) {
			$(this).children().css({
				'height': currentTallest
			});
		}
		$(this).children().css({
			'height': currentTallest
		});
	});
	return this;
};

var xn = {};

xn.config = {};

xn.helper = {
	stylize: function(selector) {
		if (typeof(selector) == 'undefined') {
			selector = 'body';
		}

		$(selector).find("*").hover(function () {
			$(this).addClass("hover");
		}, function () {
			$(this).removeClass("hover");
		}).focus(function() {
			$(this).addClass('focus');
		}).blur(function() {
			$(this).removeClass('focus');
		});
	
		$(selector).find("h1 *").each(function() {
			var h = $(this).html();
			var index = h.indexOf(' ');
			if(index == -1) {
				index = h.length;
			}
			$(this).html('<span class="first">' + h.substring(0, index) + '</span>' + h.substring(index, h.length));
		});
		
		$(selector).find("input:text").addClass("text");
		$(selector).find("input:password").addClass("password");
		$(selector).find("input:reset").addClass("reset");
		$(selector).find("input:submit").addClass("submit");
		$(selector).find("input:button").addClass("button");
		$(selector).find("input:radio").addClass("radio");

		$(selector).find(".tab_content .tab:first-child, .blocks > .block:first-child").addClass("first");
		$(selector).find(".tab_content .tab:last-child, .blocks > .block:last-child").addClass("last");
		
		$(selector).find("ul > li:nth-child(odd), ol > li:nth-child(odd), .list > .comment:nth-child(odd)").addClass("odd");
		$(selector).find("ul > li:nth-child(even), ol > li:nth-child(even), .list > .comment:nth-child(even)").addClass("even");
		$(selector).find("ul > li:first-child, ol > li:first-child, .list > .comment:first-child").addClass("first");
		$(selector).find("ul > li:last-child, ol > li:last-child, .list > .comment:last-child").addClass("last");

		$(selector).find("[class^=blocks_] > div.block:first-child").addClass("first");
		$(selector).find("[class^=blocks_] > div.block:last-child").addClass("last");

		$(selector).find("[class^=grid] tr").removeClass("first last even odd");
		$(selector).find("[class^=grid] tr:first-child").addClass ("first");
		$(selector).find("[class^=grid] tr:last-child").addClass ("last");
		$(selector).find("[class^=grid] tr:nth-child(odd)").addClass ("even");
		$(selector).find("[class^=grid] tr:nth-child(even)").addClass ("odd");

		$(selector).find("[class^=grid] tr:first-child td:first-child").addClass ("first");
		$(selector).find("[class^=grid] tr:first-child td:last-child").addClass ("last");
		$(selector).find("[class^=grid] tr:first-child td:nth-child(odd)").addClass ("even");
		$(selector).find("[class^=grid] tr:first-child td:nth-child(even)").addClass ("odd");
		
		$(selector).find("a > img").parent ().addClass ("attachment");
		$(selector).find("p > object").parent ().addClass ("object");
		
		$.fancybox.resize ();
	}
};

$(function() {	
	$(".commentcontainer .comment-body:odd, #category .post:odd").addClass("comment-odd");
	$(".commentcontainer .comment-body:even, #category .post:even").addClass("comment-even");
	
	var search_string = "Search Here";
	$(".search input[type='text']").attr ("value", search_string);
	$(".search input[type='text']").click (function () {
		if ($(this).attr ("value") == search_string){
			$(this).attr ("value", "");
		}
		$(this).addClass ("focus");
	});
	$(".search input[type='text']").blur (function () {
		if ($(this).attr ("value") == ""){
			$(this).attr ("value", search_string);
		}
		$(this).removeClass ("focus");
	})
	
	$(".search_button").click(function (){
		$("#searchform").slideToggle (100);
	})
	
	xn.helper.stylize('body');
});

var konami = "38,38,40,40,37,39,37,39,66,65".split(',');
var keyIndex = 0;
$(document).keydown(function(ev) {
	(konami[keyIndex] == ev.keyCode) ? keyIndex++:keyIndex = 0;
	if (keyIndex == konami.length) {
		$.fancybox('<div id="konamicode"><iframe title="YouTube video player" class="youtube-player" type="text/html" width="853" height="510" src="http://www.youtube.com/embed/tgbNymZ7vqY?rel=0&autoplay=1" frameborder="0"></iframe></div>', {
			'width': 853,
			'height': 510,
			'scrolling': 'none',
			'overlayColor': '#000000',
			'overlayOpacity': 0.75,
			'centerOnScroll': true,
			'onClosed': function () {
				$('.even').addClass ('rotate2');
				$('.odd').addClass ('rotate-2');
				$('#konamicode').remove ();
			}
		});
		keyIndex = 0;
	}
});

