$(document).ready(function() {
	$("a[rel='lightbox']").colorbox({transition:"fade"});
	$('a.lightbox').colorbox({transition:"fade"});
	tooltips();
	tabslider();
});

function tooltips() {
	$('a.tooltip').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - "
	});	
}

function documentsInit() {
	$('ul#documents ul.sub, ul#documents ul.files, ul#documents ul.subfiles').hide();
}

function selectDocumentFolder(dcid,parent_dcid) {
	
	if (typeof parent_dcid == 'undefined') parent_dcid = 0;
	
	$('ul#documents li a').removeClass('open'); // Close all

	if (parent_dcid > 0) { // If has parent
		if ($('ul#fchild'+dcid).is(':hidden')) {
			childvisible = false;
		} else {
			childvisible = true;
		}
	} else {
		if ($('ul#fchild'+dcid).is(':hidden') || $('ul#child'+dcid).is(':hidden')) {
			childvisible = false;
		} else {
			childvisible = true;
		}
	}

	if (parent_dcid == 0) documentsInit(); // Close all other folders
	

	if (!childvisible) { // If sub elements not visible, show them

		if (parent_dcid > 0) { // If has parent
		
			// Set current a tag to open
			$('a#link'+parent_dcid).addClass('open');
			
			// Show sub ULs for files
			$('ul#fchild'+parent_dcid).show();

			// Show sub ULs for sub categories
			$('ul#child'+parent_dcid).show();

		}		
		
		// Show sub ULs for files
		$('ul#fchild'+dcid).show();
		
		// Set current a tag to open
		$('a#link'+dcid).addClass('open');
				
		// Show sub ULs for sub categories
		$('ul#child'+dcid).show();
			

	} else {
		if (parent_dcid > 0) { // If has parent

			$('ul#fchild'+dcid).hide();
			$('a#link'+dcid).removeClass('open');
			$('a#link'+parent_dcid).addClass('open');
			
		} else {
			
			$('ul#fchild'+dcid+', ul#child'+dcid).hide();
			$('a#link'+dcid).removeClass('open');
			
		}
	}

}




function getDirections(pcode) {
	window.open('http://maps.google.co.uk/maps?f=d&hl=en&saddr=' + $('#pcode').val() + '&daddr=' + pcode + '&ie=UTF8&om=1');
}

function playAudio(file) {
	$.ajax({
		url: "/inc/ajax/audio_play.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: "file=" + file,
		success: function(msg){
			$('#mediaplayer').html(msg);
		}
	});	
}


sfHover = function() {
	var sfEls = document.getElementById("topnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function tabslider() {
	$("#tabbutton").click(function() {
		
		
		if ($("#tabslide").is(':hidden')) {		
			$("#newstab").addClass("tslideOut");
			$("#tabslide").fadeIn("fast");
		} else {		
			$("#tabslide").fadeOut("fast", function() {
				$("#newstab").removeClass("tslideOut");
      });
		}
		
		return false;
	})
}

function contactForm() {
	var postvars = $('#nform').serialize();
	
	$.ajax({
		url: "/inc/ajax/scontact.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: postvars,
		success: function(msg) {
			$("#newsletterform").html(msg);
		}
	});
	return false
}


function callSearch() {

	var postvars = $('#searchForm').serialize();
	
	$.ajax({
		url: "/inc/ajax/vacancy.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: postvars,
		success: function(msg) {
			$("#vacancycon").html(msg);
		}
	});
}

function showhidecon(id) {
	id = id.replace("#","");
	$('#vdetailtab li').removeClass('sel');
	$('div.vinfocon').hide();
	$('#' + id + '_con').show();
	$("#tab_" + id).addClass('sel');

}

<!-- Popup Window for Private Documents --->
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function inputClick(id, defval) {
	if ($('#' + id).val() == defval) {
		$('#' + id).val("");
	}
}

function inputBlur(id, defval) {
	val = $('#' + id).val();
	if (val == '') {
		$('#' + id).val(defval);
	}
}