
$(document).ready(function(){
	
	function setEqualHeight(container) {
		columns = container.children().filter("div");
		var tallestcolumn = 0;
		columns.each(
			function() {
				currentHeight = $(this).height();
				if(currentHeight > tallestcolumn) {
					tallestcolumn  = currentHeight;
				}
			}
		);
		container.css("min-height",tallestcolumn);
	}
	setEqualHeight($(".main-content"));
	setEqualHeight($("#main"));
		
	var current_nav_color = $("#nav-primary .selected div").css("background-color");
	$("#breadcrumbs").css("background-color", current_nav_color);
	
	var thumb_class = "gallerythumbnail";
	var large_class = "imagelarge";
	$("a[rel=gallery]").each(function() {
		var src = $(this).children("img").first().attr("src");
		$(this).attr("href", src.replace(thumb_class, large_class));
	});
	$("a[rel=gallery]").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'titlePosition' : 'over'
	});
	
	$(".tooltip").tooltip({

	});
	
	$.fn.wizardize = function(options) {
			var steps = $('<ul>');
			steps.attr("id", "steps");
			var index = 1;
			$('fieldset', this).each(function() {
				var step = $('<li>');
				step.html("<span class='step-point'>Step "+index+"</span><span class='step-name'>"+$('legend', this).html()+"</span>");
				step.data('fieldset', this);
				steps.append(step);
				index++;
			});
			
			$('.attribute-header', this).after(steps);
					
			var count = $('fieldset', this).size();
			$('fieldset', this).hide()
			$('.buttonblock:last', this).hide();
			$('fieldset:eq(0)', this).show();
			$('li:eq(0)', steps).addClass('active');
			var context = $(this);
		
			var prev = $("<input>");
			var next = $("<input>");
			next.attr('type', 'button');
			next.attr('value', 'Next');
			prev.attr('type', 'button');
			prev.attr('value', 'Prev');
			next.click(function() { nextFieldset(context); });
			prev.click(function() { prevFieldset(context); });
			this.append(prev);
			this.append(next);
			
			prev.hide();
			
			function nextFieldset(form) {
				var current = $("fieldset:visible");
				current.hide();
				current.next('fieldset').show();
				prev.show();
								
				$("li", steps).removeClass("active");
				$("li:eq("+(current.next('fieldset').index('fieldset'))+")", steps).addClass("active");
				
				if(current.next('fieldset').next('fieldset').size()==0) {
					next.hide();
					$('.buttonblock', form).show();
				}
			}
			
			function prevFieldset(form) {
				var current = $('fieldset:visible');
				current.hide();
				current.prev('fieldset').show();
				next.show();
				
				$("li", steps).removeClass("active");
				$("li:eq("+(current.prev('fieldset').index('fieldset'))+")", steps).addClass("active");
				
				$('.buttonblock', form).hide();
				if(current.prev('fieldset').prev('fieldset').size()==0) {
					prev.hide();
				}
			}
			
	        return this;
	};
	
	$(".game-edit form").wizardize();
});