﻿/* This file runs on every page, every time they are loaded. Do not remove it, it's a core file. */
/* Init - runs when document is ready. All functions which require the document to be ready should be called from here */
$(function() {
	$(".labeler").labeler();
	initDatePicker();	
	createTabs();
	$(".subleads").columnise(".sublead", {className:"new_row afalc", numberOfColumns:6, wrapType:"row"});
	$(".row").columns(".column");
	$(".afalc").afalc();
	$("#content").moveClass("body");
	$(".body input").typeClass("input_type");
	page_tools();
	jsp_paging();
	//$(".double_column_list .ul").columnise(".li", {className:"column border_top"});
	$(".odd").oddEven();
	$(".tablestripe").oddEven({target:"tbody tr"});
	//$(".slidingpane").slidingPane();
	//$(".form_wrap .input_type_submit").clickAndWait({animate:true});
	//$("ul, li").removeIfEmpty();
	//$(".pane .clickable").clickable(".pane");
	
});

/*$(window).load(function() {
	$("a[href^='http://'], a[href^='www.']").oinw();
});*/

function page_tools() {
	$(".page_tools a").tooltip({ position: "bottom center" });
}

function jsp_paging() {
	$('.jsp_paging').each(function(){
								   
		var $pager = $('.jsp_dots',this);
		var $next = $(".next",this);
		var $prev = $(".prev",this);
		var $pages = $('.jsp_page',this);
		var containerHeight = 0;
		
		if($pages.length > 1) {
			
			// If there are more than one pages work out the height and load the paging
			
			if($(this).hasClass('autostart')) {
				var timeout = 4000;
				var speed = 1000;
			} else {
				var timeout = 0;
				var speed = 0;
			}
			
			$pages.each(function(){
				if($(this).height() > containerHeight ) {
					containerHeight = $(this).height();
	 			}										 
			});
	
			$('.jsp_pages',this).cycle({ 
				speed: speed,
				timeout: timeout,
				pager: $pager,
				next: $next,
				prev: $prev,
				height: containerHeight
			});
			
		} else {
			
			// If there is just the one page, hide the nav
			
			$('.jsp_nav',this).hide();
			
		}
		

	});
}

function initDatePicker() {
	// Datepickers for date input fields
	$('input.date').datepicker({ dateFormat: 'dd/mm/yy' });
}
 
// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w = 500;
	var h= 300;
	if(width) {
		w = width;	 
	}
	if(height) {
		h = height;	 
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false
    }); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			$("#dialog").html(data);
		}
    });
}

// Replace alrt boxes with a much nicer alternative
function ajaxAlert(msg) {
	if($('#alert').length == 0) {
		$("body").append('<div id="alert"></div>');	
	}
    $('#alert').dialog('destroy').html(msg).dialog({
		dialogClass: 'alert',
		width: 200,
		minHeight: 80,
		modal: true,
		cache: false,
		buttons: { "Ok": function() { $(this).dialog("close"); } }
    }); 
}

/* create tabs function - to allow for tabs to be called by other means */
function createTabs(){
	$(".tabs").tabs();
}
