
var app = {
	initialise: function() {
	    app.column_height_adjust();
		$(window).resize(function() {
		    app.column_height_adjust();
		});
		app.press_page_paging();
		
		app.column_div_set_height();
		
		if($('#admin_area').length > 0){
			$('textarea').ckeditor();
		}
		
		$("#question_filter").change(function() {
		    $(this).closest("form").submit();
		});
		
		$('#flashMessage').delay(3000).slideUp('slow');
	
		if($('#logged_in').length > 0){
			$("#content div:eq(0)").attr('id', 'main_content');
			$("#content div.actions").attr('id', 'actions_menu');
		}
		
		$("#actions_menu").height( $(document).height() - 44 );
		
		
		$('.answer').hide();
		
		$('.question').click(function() {
			$(this).parent().find('.answer').toggle('fast');
			return false;
		});
		
		if($('.a_gallery a').length > 0){
			$('.a_gallery a').lightBox();
		}
		
	},

	column_height_adjust: function () {
		$('#main_container').height( ($(document).height() ) );
		$('#content_container').height( ($(document).height() ) );
		
		$("#actions_menu").height( $(document).height() - 44 );
	},
	
	log: function(message) {
		if(typeof console != 'undefined') console.log(message);
	},
	
	column_div_set_height: function() {
		col_1_height = $('#column_1').height() + 30;
		col_2_height = $('#column_2').height() + 30;
		$('#column_div').height(col_1_height);
		if(col_1_height < col_2_height){
			$('#column_div').height(col_2_height);
		}
		
		if($('#column_div').length > 0){
			$('#footer').css('margin-top', 0);
		}
		
	},
	
	press_page_paging: function() {
		
		$('.press_links_page').fadeOut(0);
		$('.press_links_page:eq(0)').fadeIn(0);
		$('#press_posts_holder').height( $('.press_links_page:eq(0)').height() + 10 );
		
		$('#press_paging a').click(function () {
			
			var to_fadein = $(this).index();
			
			$('.press_page_on').fadeOut(333, function(){
				$('.press_page_on').removeClass('press_page_on');
				$('.press_links_page:eq('+ to_fadein +')').fadeIn(333);
				
				$('#press_posts_holder').animate({
				    height: ($('.press_links_page:eq('+ to_fadein +')').height() + 10) + 'px'
				  }, 500 );
				
				$('.press_links_page:eq('+ to_fadein +')').addClass('press_page_on');
			});
			
			$('#press_paging a').removeClass('on');
			$(this).addClass('on');
			return false;
		});
		
		
		//web links
		$('.web_links_page').fadeOut(0);
		$('.web_links_page:eq(0)').fadeIn(0);
		$('#web_posts_holder').height( $('.web_links_page:eq(0)').height() + 10 );
		
		
		$('#web_paging a').click(function () {
			
			var to_fadein = $(this).index();
			
			$('.web_page_on').fadeOut(333, function(){
				$('.web_page_on').removeClass('web_page_on');
				$('.web_links_page:eq('+ to_fadein +')').fadeIn(333);
				
				$('#web_posts_holder').animate({
				    height: ($('.web_links_page:eq('+ to_fadein +')').height() + 10) + 'px'
				  }, 500 );
				
				$('.web_links_page:eq('+ to_fadein +')').addClass('web_page_on');
			});
			
			$('#web_paging a').removeClass('on');
			$(this).addClass('on');
			return false;
		});
		
	}

};

toggle_speed = 1;

var server_nav = {
	initialise: function() {
		$('h1 a').click(function() {
			$('.' + $(this).attr('id')).slideToggle(toggle_speed, function() {
				app.column_height_adjust();
			});
			$(this).parent().parent().find('.a_level:first').slideToggle(toggle_speed, function(){
				app.column_height_adjust();
			});
			return false;
		});
		
		$('h1 a').click();
		toggle_speed = 333;
	}
};

$(document).ready(function(){
	if ($.browser.webkit) {
		$('#newsletter_signup .input').css('margin-bottom', '0px')
	}
	app.initialise();
	server_nav.initialise();
});

$(window).load(function(){	
	app.column_height_adjust();
});















