

//===================================================
// OnLoad Handler
//===================================================
$(window).load(function () {
	
	// Button hover
	$('.Button').each(function(index){
		$(this).hover(
			function() { $(this).addClass('Button-hover'); },
			function() { $(this).removeClass('Button-hover'); }
		)
		.click(
			function() {
				$(this).removeClass('Button-hover');
				
				// Show loading screen after short delay, dont want to see it every time...
				$(this).delay(500).queue(function(){ 
					//showLoading(); 
				});
			}
		);
	});
	
	// Main Tooltips
	$('.Tooltip').each(function(index){
		if ($(this).attr('href')=='#') $(this).attr('href','javascript:void(0);'); // replace '#' with something less annoying
		$(this).qtip({
			content: $(this).attr('rel'),
			style: {
				tip: true,
				classes: 'ui-tooltip-rounded'
			},
			position: {
				at: "top middle",
				my: "bottom left"
			},
			hide: {
				fixed: true,
				event: "mouseout"
			}
		});
	});


	
	
});

//===================================================
// Show Loading Modal
//===================================================
function showLoading() {
	
	$('<div />').qtip({
		
		id: 'LoadingModal', // Since we're only creating one modal, give it an ID so we can style it
		content: {
			title: {
				text: '',
				button: false
			},
			text: '<img src="/images/loader.gif" alt="Loading...">' // The text to use whilst the AJAX request is loading
		},
		position: {
			my: 'center', at: 'center', // Center it...
			target: $(window) // ... in the window
		},
		show: {
			ready: true, // Show it straight away
			modal: {
				on: true // Make it modal (darken the rest of the page)...
			}
		},
		hide: false,
		style: 'ui-tooltip-loading ui-tooltip-rounded',
		events: {
				// Destroy the tooltip once it's hidden as we no longer need it!
				hide: function(event, api) { api.destroy(); }
			}
	});
}



//===================================================
// Redirect URL
//===================================================
function redirect(URL) {
	document.location = URL;
}

//===================================================
// Ajax Handler
//===================================================
function ajax(f,a,callbackFunction){
	$.ajax({
		url: '/ajax/' + f + '/',
		type: 'GET',
		data: a,
		timeout: 5000,
		traditional: true,
		error: function(r){ alert('Error'); },
		success: function(r){ if (callbackFunction) callbackFunction(r); }
	});
}


//===================================================
// Var Dump
//===================================================
function dump(obj) {
	var out = '';
	for (var i in obj) {
		out += i + ": " + obj[i] + "\n";
	}
	return out;
}


