var HTML_Content, current_page = false, unclickable = false;

$(document).ready(function() {

	//Get HTML Content and preload images inside content
	$.ajax(
		{
			url: "content.html",
			cache: false,
			success: function(html){
				HTML_Content = document.createElement('div');
				$(HTML_Content).html(html);
				
				$(HTML_Content).find('img').each(function() {
					var img = new Image();
					img.src = $(this).attr('src');
				});
			}
		}
	);
	
	$('.column_content a').attr('href','#');
	
	//Column Effects and Behaviors
	$('.column').css('cursor','pointer').each(function() {
		$(this).hover(function() {
			if( !unclickable && $(this).attr('id') != current_page ) {	//Prevent onhover from working if page is selected
				$(this).find('.column_bg').stop(true).animate({opacity: .3}, 300);
			}
		}, function() {
			if( !unclickable && $(this).attr('id') != current_page ) {	//Prevent onhover from working if page is selected
				$(this).find('.column_bg').animate({opacity: .1}, 300);
			}
		});
		$(this).click(function() {
			if( !unclickable && current_page && current_page != $(this).attr('id') ) {
				unclickable = true;	//Using this variable to prevent weird bugs that only exist in IE7 >:o
				$('#'+current_page).find('.column_bg').stop().animate({opacity: .1}, 300);
			}
			display_page($(this).attr('id'));
		});
	});
	
});

function display_page( page ) {

	var elements = 0;
	
	current_page = page;
	
	if( (version >= 5.5) ) {
		$('#left_side, #right_side, #right_side span, #right_side img').animate({opacity:0}, 0, function() {
		
			elements++;
			
			if( elements == $('#left_side, #right_side, #right_side span').length ) {

				var html = $(HTML_Content).find('#'+page).html();
				
				$('#left_side').html($(HTML_Content).find('#'+page+' .left_side').html());
				$('#right_side').html($(HTML_Content).find('#'+page+' .right_side').html());
				$('#left_side, #right_side, #right_side span').animate({opacity: 1}, 10, function() {
					unclickable = false;
				});
				
				if( typeof version != 'undefined' && (version >= 5.5) && (version < 7) ) {
					fixPNG(document.getElementById('right_side').getElementsByTagName('img')[0]);
				}
				
			}
			
		});
	}
	else {
		$('#left_side, #right_side, #right_side span, #right_side img').fadeOut('slow', function() {
		
			elements++;
			
			if( elements == $('#left_side, #right_side, #right_side span').length ) {
				
				var html = $(HTML_Content).find('#'+page).html();
				
				$('#left_side').html($(HTML_Content).find('#'+page+' .left_side').html());
				$('#right_side').html($(HTML_Content).find('#'+page+' .right_side').html());
				$('#left_side, #right_side, #right_side span').fadeIn('fast', function() {
					unclickable = false;
				});
				
				if( typeof version != 'undefined' && (version >= 5.5) && (version < 7) ) {
					fixPNG(document.getElementById('right_side').getElementsByTagName('img')[0]);
				}
				
			}
			
		});	
	}


}