$(document).ready(function(){	
	
	// change navigation background depending on the url #
	if (this.location.hash == '#nellie') {
		$(".navigation").css("background-position","0 0");
		$(".nellie").removeClass('hide').siblings().addClass('hide');
	}	
	if (this.location.hash == '#spendshifter') {
		$(".navigation").css("background-position","0 -70px");
		$(".spendshifter").removeClass('hide').siblings().addClass('hide');
	}
	if (this.location.hash == '#legitimiser') {
		$(".navigation").css("background-position","0 -140px");
		$(".legitimiser").removeClass('hide').siblings().addClass('hide');
	}
	if (this.location.hash == '#minitreater') {
		$(".navigation").css("background-position","0 -210px");
		$(".minitreater").removeClass('hide').siblings().addClass('hide');
	}	
	if (this.location.hash == '#righter') {
		$(".navigation").css("background-position","0 -280px");
		$(".righter").removeClass('hide').siblings().addClass('hide');
	}
	if (this.location.hash == '#haymaker') {
		$(".navigation").css("background-position","0 -350px");
		$(".haymaker").removeClass('hide').siblings().addClass('hide');
	}

	// change navigation background on click
	$("a:attr[href*='#nellie']").click(function() {
		$(".navigation").css("background-position","0 0");		
		$(".nellie").removeClass('hide').siblings().addClass('hide');			
	});
	$("a:attr[href*='#spendshifter']").click(function() {
		$(".navigation").css("background-position","0 -70px");
		$(".spendshifter").removeClass('hide').siblings().addClass('hide');
	});
	$("a:attr[href*='#legitimiser']").click(function() {
		$(".navigation").css("background-position","0 -140px");
		$(".legitimiser").removeClass('hide').siblings().addClass('hide');
	});
	$("a:attr[href*='#minitreater']").click(function() {
		$(".navigation").css("background-position","0 -210px");
		$(".minitreater").removeClass('hide').siblings().addClass('hide');
	});
	$("a:attr[href*='#righter']").click(function() {
		$(".navigation").css("background-position","0 -280px");
		$(".righter").removeClass('hide').siblings().addClass('hide');
	});					
	$("a:attr[href*='#haymaker']").click(function() {
		$(".navigation").css("background-position","0 -350px");
		$(".haymaker").removeClass('hide').siblings().addClass('hide');
	});
	
	// add hover class to list item
	$(".select_personality li").hover(function() {
		  $(this).addClass('hover');
	}, function() {
		  $(this).removeClass('hover');
	});
	
	// make entire list item area clickable
	$(".select_personality li").click(function(){
	  //get the url from href attribute and launch the url
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
	// removing additional margin for every even item
	$(".select_personality li:eq(1)").css("margin-right","0");	
	$(".select_personality li:eq(3)").css("margin-right","0");	
	$(".select_personality li:eq(5)").css("margin-right","0");	
	
	// tabs functionality
	$("#profile-tabs").tabs();
		
	// .products list equal height
	$(".first, .second, .third").equalHeight();
	  
	// #footer - remove right border from last list item
	$('#footer li:last').css("border-right","none");

	// open external links in new window
	$('a[href^="http://"]')
	  .attr({
	    target: "_blank"
	});	
});

// banner slide show on homepage
function slideSwitch() {
    var $active = $('.home ul li.active');

    if ( $active.length == 0 ) $active = $('.home ul li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.home ul li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});


// makes all matched elements equal height
jQuery.fn.equalHeight = function() {
	var height = 0, 
		maxHeight = 0;

	// store the tallest element's height
	this.each(function() {
		var t = jQuery(this);
		height = t.height() + parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10) + parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10);
		maxHeight = (height > maxHeight) ? height : maxHeight;
	});

	// set element's min-height to tallest element's height
	return this.each(function() {
		var t = jQuery(this);
			mh = maxHeight - (parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10) + parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10));
		t.css({minHeight: mh +'px', height: mh +'px'});
	});
};