
function greenborder_resize(){

	var max_w = 1200;

	$('table.main').css(
		'width',
		($('table.main').outerWidth(true) > max_w) ? max_w+'px' : '100%'
	);

	if($('table.main').outerWidth(true) < 960){
		$('table.main').css('width', '960px');
	}
}

function crew() {
	var curbox = $('<div class="current-box"></div>');

	if(location.hash){
		var cls = location.hash.replace('#','');
		var current = $('.crew-photo .item img.' + cls).parent();
		var curstaff = $('.crew-staff .item.' + cls);
	}else{
		var current = $('.crew-photo .item').eq(0);
		var curstaff = $('.crew-staff .item').eq(0);
	}

    if ( curstaff.hasClass("noitem") ) {
        curstaff.show().addClass('current');
    } else {
        current.addClass('current').append(curbox);
	    curbox.fadeIn(300);
	    curstaff.slideDown(300).addClass('current');
    }

	$('.crew-photo .item').unbind('click').click(function(){

		if($(this).is('.current')){
			return false;
		}

		var t = $(this);
		var c = t.find('img').attr('class');

		$('.crew-staff .item.current').removeClass('current').hide(0, function(){
			$('.crew-staff .item.' + c).show(0).addClass('current');
			return false;
		});

		location.hash = '#' + c;
		$('.crew-photo .current').removeClass('current');

		curbox.fadeOut(100, function(){
			t.addClass('current').append(curbox);
			curbox.fadeIn(300);
			return false;
		});

		return false;
	});
}


$(function() {

	$('.header .logotype a img').hover(function(){
		$(this).attr('src','/media/images/krp-logo-green.png');
	}, function(){
		$(this).attr('src', '/media/images/krp-logo.png');
	});

	crew();

	$(window).resize(function(){
	  	greenborder_resize();
		return false;
	});

	greenborder_resize();

});
