(function($) {
	$.fn.updateContent = function() {
		var click_me = function(e) {
			if ($(this).hasClass("active")) return false;
			var siblingsArray = $("*[rel="+this.rel+"]"),
			index = siblingsArray.index(this),
			contentParent = $("#c-images-content"),
			imagesParent = $("#c-images");
			siblingsArray.removeClass("active").eq(index).addClass("active");
			contentParent.children().removeClass("active").eq(index).addClass("active");
			if (imagesParent.children().length > index) imagesParent.children().removeClass("active").eq(index).addClass("active");
			return false;
		};
		
		return $(this).bind('click', click_me);
	};
	
	var handle_embedly = function(oembed, dict) {
		if (typeof oembed != "undefined" && oembed != null) $(this).data("oembed", oembed);
	};
	
	var show_embedly = function(e) {
		if (!(oembed = $(this).data("oembed"))) return false;
		$.fancybox({content: oembed.code, hideOnOverlayClick: false, title: oembed.title});
		return false;
	}
	
	
	
	
	
	$(document).ready(function() {
		if ($.browser.msie) $("body").addClass("ie");
		if ($.browser.msie && $.browser.version == "7.0") $("body").addClass("ie7");
		$("a[rel=update-content]").updateContent();
		$("a.embedly").embedly({method: "after", success: handle_embedly}).bind('click', show_embedly);
		
		$(".ui-button").each(function() {
			
			$(this).button();
		});
	});
})(jQuery);
