﻿/* 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() {
	$("#content").moveClass("body");
	$(".subleads").columnise(".sublead", {className:"row afalc", numberOfColumns:4, wrapType:"row"});
	//$(".imgaewrasp").columnise("img", {numberOfColumns:"3", className:"jamesarcher"});
	initDatePicker();
	createTabs();
	$(".labeler").labeler();
	$(".afalc").afalc();
	applyInputClass();
	$(".odd").oddEven();
	$(".tablestripe").oddEven({target:"tbody tr"});
	
	//$(".level1 ul li a").tooltiper({position:"left bottom tl", hideDelay:40, showDelay:200});
//	$(".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 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();
}

function applyInputClass() {
	$(".body input").typeClass("input_type");	
}
