(function($, undefined) {
	$.fn.selectSlide = function() {
		this.css({
			'display': 'block',
			'z-index': 5,
			'opacity': 1
		});
		
		return this;
	}
	$.fn.deselectSlide = function() {
		this.css({
			'display': 'none',
			'z-index': 4,
			'opacity': 0
		});
		
		return this;
	}
})(jQuery);

function getPageFromUrl(location) {
	return location.substr(location.lastIndexOf('/') + 1) || location;
}

$(function() {
	// Make inside columns equal height
	$('.inside .column').equalHeight();

	// Homepage slideshow
	var slideShow = $('.cycle').cycle('fade');
	var selected;
	
	// Stop slideshow on hover
	$('.banner .nav a').hover(function() {
		var slide = '#cycle-' + (this.id.split('-')[1]);
		
		slideShow.cycle('pause');
		
		selected = slideShow.find('img').map(function() {
			if ($(this).css('display') === 'block') {
				return this;
			}
		});
		
		slideShow.find('img').deselectSlide();
		$(slide).selectSlide();
	}, function() {
		slideShow.find('img').deselectSlide();
		selected.selectSlide();
		slideShow.cycle('resume');
	});
	
	// Box buttons
	$('.box1').click(function() { window.location = 'commercial.aspx'; });
	$('.box2').click(function() { window.location = 'personal.aspx'; });
	$('.box3').click(function() { window.location = 'life.aspx'; });
	
	// Find links to current page and add class of 'current'
	var currentPage = getPageFromUrl(window.location.toString());
	$('.nav a').each(function(){
		if (getPageFromUrl(this.href) === currentPage) {
			$(this).addClass('current');
		}
	});
	
});
