google.setOnLoadCallback(function() {
	$(document).ready(function() {
		var helptime = 15000;	
		scrolling();
		newWindowLinks();	
		nav();
		ajax();
		$("#showhide").click(function() {			
			if($("body").hasClass("intro")) {				
				$("body").removeClass("home").removeClass("intro");	
				showScrollBar();
				$("#help").show()	
				setTimeout(function(){ $("#help").fadeOut(1000,function() { $(this).remove() }) },helptime);		
			} else {
				$("body").addClass("intro");
				$("#help").hide()
			}
			return false;
		});	

		if($.browser.msie) {
			setContentPaneHeight();
			$(window).resize(function() {
				setContentPaneHeight();
			})
		} else {
			$(window).resize(function() {
				showScrollBar();
			})
		}
		$("body").append('<div id="help"><div class="inner"><div><p>Click this icon to open/close the website and view the videos.</p><p>Clicking on the pause icon stops the video and you can adjust the volume by dragging the slider.</p></div></div></div>');	
		if(!$("body").hasClass("intro")) {
			setTimeout(function(){ $("#help").fadeOut(1000,function() { $(this).remove() }) },helptime);
		}
	});	
});

function setContentPaneHeight() {
	var contentHeight	= $(window).height() - 164;
	$("#contentPane").css({bottom:"auto",height: contentHeight+"px"});
	$("#scrollbarWrapper").css({bottom:"auto",height: (contentHeight-46)+"px"});
	showScrollBar()
}


function scrolling() {
	showScrollBar();
	$("#innerPane").css({overflow:"hidden",position:"relative",top:"0px"});
	$("#scrl").slider({
		value: 100,
		orientation: 'vertical',
		step: 1, 
		animate: true,
	   	slide: function(event, ui) { 			
			var viewportHeight 	= $("#contentPane").height();
			var contentHeight	= $("#innerPane").height();
			var maxScroll		= contentHeight-viewportHeight;			
			var yPos			= -((100-ui.value)*(maxScroll/100));
			$("#innerPane").css({"top": yPos+"px"});
		}
	});
}

function showScrollBar() {	
	$("#scrl").slider('option', 'value', 100);
	var viewportHeight 	= $("#contentPane").height();	
	var contentHeight	= $("#innerPane").height();
	if(contentHeight>viewportHeight) {
		$("#scrollbarWrapper").fadeIn()
	} else {
		$("#innerPane").css({top:"0px"});
		$("#scrollbarWrapper").hide()
	}
}

/* Un-obfuscate email */
function fnE(inarr,text) {
	inarr = inarr.split(",");
	var out = "";
	for(i=inarr.length-1;i>=0;i--) {
		out += inarr[i];
	}
	if(text==false || text=="" || text==undefined) {
		text = out;
	}
	//document.write('<a href="mailto:'+out+'">'+text+'</a>');	
}


function ajax() {
	$("#nav a, a.live").live("click",function() {				
		var t 		= $("#innerPane");
		var path 	= $(this).attr("href");
		$("#scrollbarWrapper").hide();
		$("#contentPane").css({background:"#f2eeec url(/inc/loader.gif) 50% 50% no-repeat"});
		t.fadeOut(500,function(){	
			$.getJSON(path + "?mode=ajax", function(json){				
				document.title = json.pagetitle;	
				t.html(json.pagebody).fadeIn(500);
				t.scrollTop(0);		
				scrolling();	
				$("#contentPane").css({background:"#f2eeec"});
			});	
	
		});
		return false;
	});

}

function nav() {
	$("#nav a").click(function() {		
		$("#nav a").removeClass("selected");
		$(this).addClass("selected")		
	});

}


/**	
 * Target new windows
 */
function newWindowLinks(){
	$('a.pop').live('click',function(){
		window.open($(this).attr('href'));
		return false;
	});
}

function gallery(imagearray) {
	$("#galleryHeading").append('<a href="#" id="galleryPrev">Previous</a><a href="#" id="galleryNext">Next</a>')
	$("#galleryNext").click(function(){
		currentGalleryImage++;
		if(currentGalleryImage>imagearray.length-1) {
			currentGalleryImage = 0;
		}
		$("#galleryImage").attr("src",imagearray[currentGalleryImage])
		return false;
	});
	$("#galleryPrev").click(function(){
		currentGalleryImage--;
		if(currentGalleryImage<0) {
			currentGalleryImage = imagearray.length-1;
		}
		$("#galleryImage").attr("src",imagearray[currentGalleryImage])
		return false;
	});
}

