(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);
$(document).ready(function(){
	$('html').addClass('js-enabled');
	var count = 1;
			counter = parseInt($('li.photo_li').length);
	if ($('#gallery_page ul li').length > 1) {
		$('#gallery_page').prepend("<span id='gallery_controls'><div id='prevBtn'><a href='#'> - </a></div> <div id='counterBtn'><span class='count'>"+count+"</span> / "+counter+"</div><div id='nextBtn'><a href='#'> + </a></div></span>");
	}
	$('#nextBtn a').click( function() {
		if (parseInt($('li.photo_li').length) > count) {
			count++;			
		} else {
			count = 1;
		}
		$('span.count').html(count);
	}).stop();
	$('#prevBtn a').click( function() {
		if (count > 1) {
			--count;			
		} else {
			count = counter;
		}
		$('span.count').html(count);
	}).stop();
	if ($('.nav ul li').length > 1) {
		$('.nav').not('.nav ul li > ul').accordion({
			selectedClass: "active",
			header: "a.accordion_nav",
		  	navigation: true,
			autoheight: false,
			clearStyle: true		
		});
		$('a.accordion_nav').click( function() {
			var url = $(this).next().find('a:first').attr('href');
			location.href = url;
		});
	}	
	$('#gallery_page ul').cycle({
		fx: "scrollHorz", 
		timeout: 0,
		autostop: 1,
		next: '#nextBtn', 
		prev: '#prevBtn'
	});
	$('#level1 a').each(function() {
    string = $(this).text();
    filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
    $(this).addClass(filename);
  });
	$('.modal').facebox();
	$("#contact .splitcol1,#contact .splitcol2").equalizeCols();
});

