var logged_in = false;
$(document).ready(function() {


	if (!logged_in) {

		if ($('.login_box').hasClass('login_box_error')) {
			$('.login_box').show();
		} else {
			$('.login_box').height($('.login_box').height()).hide();
		}
	} else {
		$('a[href="/Members-Login"]').html('logout').attr('href','/logout');
	}

	$('a[href="/Members-Login"]').click(function() {
		$('.login_box').slideToggle();
		return false;
	});

	if($('#doc_cat_id').length) {
	  if($('#fl_public').val() == 1) {
  	  $('#doc_cat select').change(function(){
  	    if($('#doc_cat select').val() == 4) {
  	      $('#doc_team').css('display','block');
  	    }
  	    else {
  	      $('#doc_team').css('display','none');
  	    }
  	  });
	  }
	}

	$( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy' });
	
	$( "a.fancybox").fancybox();


	var FADE_TIME = 500;
	if (typeof history.pushState == "function") {



		title = document.title;
		url = window.location.pathname+window.location.search;



		history.replaceState({href:url,title:title},title,url);

		window.onpopstate = function(data) {
			if (data.state) {
				navigate(data.state.href,data.state.title,true);
			}
		}

		function navigate(url,title,notNew) {

			$('.maincol').animate({opacity:0},FADE_TIME,function() {

				$.get(url,function(data) {
					if (!notNew)
						history.pushState({href:url,title:title},title,url);

					// remove '\n'
					data = data.replace(/\n/g,"");

					// remove aything before body, & body itself
					var body = data.replace(/^.*<body[^>]*>/,"");

					// remove the final tags
					body = body.replace(/<\/body><\/html>/,"");

					var $nb = $(body);
					var html = $nb.find('.maincol').html();

					$('ul.submenu .active').removeClass('active');

					$('ul.submenu a[href="'+url+'"]').parent().addClass('active');

					document.title = title;
					$('body .maincol').html(html);
					init();
					$('.maincol').animate({opacity:1},FADE_TIME);
				});
			});
		}

		$('ul.submenu a').click(function() {

			// check if control holding down

			if ($.fn.control_press.ctrl) {
				return true;
			}

			var $t = $(this);
			var url = $t.attr('href');
			title = $t.attr('title');
			if (!title)
				title = $t.html();
			navigate(url,title);

			return false;
		});

	}

	init();


	$('#s1').cycle();




});


function init() {
	$('#breadcrumbs li:not(:last-child)').append('&nbsp;&#8250;&nbsp;&nbsp;');



	$('.clickable').click(function() {
		var a = $(this).find('a').first();
		if ($.fn.control_press.ctrl)
			window.open(a.attr('href'));
		else
			window.location = a.attr('href');
		return false;
	});

	$(".accordion").accordion();

}


$.fn.control_press = {};

$.fn.control_press.ctrl = false;

document.onkeydown = function(e) {
	var unicode=e.keyCode? e.keyCode : e.charCode;
	if (unicode == 91) {
		$.fn.control_press.ctrl = true;
	}
	document.onkeydown(e);
}

document.onkeyup = function(e) {
	var unicode=e.keyCode? e.keyCode : e.charCode;
	if (unicode == 91)
		$.fn.control_press.ctrl = false;
	document.onkeyup(e);
}


	/* Search Page */

