$(function(){
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		DD_belatedPNG.fix('h1#logo a, #header, .time img, #navigation ul li a.home-link, #navigation ul li a.home-link:hover, #slider .nav a, #slider .nav a:hover, #slider .nav a.active, #slider .direct-nav a.prev, #slider .direct-nav a.next');
	};

	$('#navigation ul li a').live('click', function(){
		loadCols($(this).attr('href'));
		$('#navigation ul li a').not($(this)).removeClass('active');
		$(this).addClass('active');
		return false;
	});
    
});

$(window).load(function() {
showCols()
$('#fade').fadeOut('slow');
						$('.flexslider').flexslider({
				slideshow: true,
		controlNav: false
					});		
});


function showCols() {

	$('#slider ul').jcarousel({
		wrap: 'both',
		scroll: 1,
		vertical: true,
		auto: 0,
		visible: 1,
		initCallback: init_carousel
	});
	
	if ($('#left-col').height() > $('#right-col').height()) {
		$('.center-col').css({height: $('#left-col').height()});
	} else {
		$('.center-col').css({height: $('#right-col').height()});
	}
	
	$('#left-col').stop(true, true).animate({left: '-254px'}, 500);
	$('#right-col').stop(true, true).animate({right: '-252px'}, 500);
	
	
	$('a[rel*=facebox]').facebox({
        loadingImage : 'css/images/loading.gif',
        closeImage   : 'css/images/x-icon.png'
    });
	

}


function loadCols(page) {
	
	if ($('#ajax-holder').length == 0) {
		$('body').append('<div id="ajax-holder"></div>');
	};
	$('#ajax-holder').html('');
	
	$('#left-col').stop(true, true).animate({left: '45px'}, 500);
	$('#right-col').stop(true, true).animate({right: '45px'}, 500, function() {
		$('#ajax-holder').load(page + ' #left-col > *', function() {
			$('#left-col').html('').append($('#ajax-holder').html());
			$('#ajax-holder').html('');
			$('#ajax-holder').load(page + ' #right-col > *', function() {
				$('#right-col').html('').append($('#ajax-holder').html());
				$('#ajax-holder').html('');
				setTimeout(function() {
					showCols();
				$('.flexslider').flexslider({
				slideshow: true,
				controlNav: false
					});					
				}, 500);
			});

		});
		
	});
	
};

function init_carousel(carousel) {
	$('#slider .nav a.prev').click(function(){
		carousel.prev();
		return false;
	});
	$('#slider .nav a.next').click(function(){
		carousel.next();
		return false;
	});
}
