$(document).ready(function() {
 
	// TABS
	$(".tab_content").hide();
	
	// if there's a URL hash on load, show that tab, otherwise, show the first
	if (window.location.hash.length) {
		var tabToSelect = "tab"+ window.location.hash.substring(1);
		$("ul.tabs li").find("a[href*="+ tabToSelect +"]").parent().addClass("active").show();
		$("#"+ tabToSelect).show();
	} else {
		$("ul.tabs li:first").addClass("active").show();
		$(".tab_content:first").show();
	}
	
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		
		$(".tab_content").hide();
		var activeTab = $(this).find("a");
		$(activeTab.attr("href")).fadeIn();
		window.location.hash = activeTab.attr('title');
		
		return false;
	});
	
	$(".tab_content2").hide();
	$("ul.tabs2 li:first").addClass("active").show();
	$(".tab_content2:first").show();
	
	$("ul.tabs2 li").click(function() {
		$("ul.tabs2 li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content2").hide();
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	//MODALS
	if (jQuery.facebox) {
		$("a[rel*=facebox]").facebox();
	}
	
	//ABOUT IMAGE HOVERS
	$('.img-holder').hover(
		function(){
			var $this = $(this).find('img');
			var src = $this.attr('src').split('.');
			$this.attr('src',src[0]+'1.'+src[1]);
		},
		function(){
			var $this = $(this).find('img');
			var src = $this.attr('src').split('1');
			$this.attr('src',src[0]+src[1]);
		}
	);
	
	// change "login" to "My Memolane" when a user is logged in
	//  - a bit of a hack, but the best/easiest solution for now
	$.ajax({
		url: '/me',
		dataType: "html",
		success: function(data, textStatus, jqXHR){
			if ( $(jqXHR.responseText).find('#login').length == 0 ) {
				$('#utility-signup').css('right','120px');
				$('#utility-signin a').text('My Memolane').attr('href','/me');
			}
		}
	});
});
