/*
 *	LONSAS Common javascript
 *	Created by Stephen, March 2009
 */

/* Font replacement */

Cufon.replace(".topnav li a", { fontFamily: 'Gotham Book' });

$(document).ready(function(){
						   	
	// Tabs


	$(".tabs").tabs();

	// Jquery UI elements
	
	$("input.date").datepicker({ 
		duration: '',
		dateFormat: 'dd/mm/yy'
	});

	// Labelify

	$("input:text").labelify({
		labelledClass: "labelled"
	});
	
	
	// Login dialog
	$("#login_dialog").dialog({
		autoOpen: false,
		title: "Login",
		bgiframe: true,
		modal: true,
		draggable: false,
		dialogClass: 'login_dialog',
		open: function() {
			$(this).parent().appendTo('form:first');
		}
	});
	/*$(".loginlink").click(function(){
		$('#login_dialog').dialog('open');
		return false;
	});*/
	
	// Fade error on log in error
	$("#ctl00_PageHolder_LoginPanel1_updLogin").live('load',function(){
		$(this).animate({ 
			background: '#fac9c9'
		}, 1500 );
    });

	// Select all | select none
	$(".js_selectall").click(function(){
	
		$(this).parents(".value").find("input:checkbox").attr("checked",true);
		return false;
	
	});
	$(".js_selectnone").click(function(){
	
		$(this).parents(".value").find("input:checkbox").attr("checked",false);
		return false;
	
	});

	// Nested checkboxes on regisration page
	$(".form_registration fieldset.checkbox-nested .group_head input").each(toggleCheckboxGroup);
	$(".form_registration fieldset.checkbox-nested .group_head input").click(toggleCheckboxGroup);
	
	// In-module galleries
	if($('table.gallery').length > 0) {
		inlineGallery($('table.gallery'));
	}

});

// Select all checkboxes in a group
function toggleCheckboxGroup(e) {
	var group = $(this).parents(".group").find(".group_body");
    if ($(this).attr("checked")) {
		group.show();	
    } else {
		group.hide();	
    }
	group = null;
}

// When passed the name of a container, the lightbox script is loaded called on all the links in that container
function inlineGallery(gallery) {
	// Paths
	var lightboxscript = "/javascript/jquery-lightbox-0.5/js/jquery.lightbox-0.5.min.js";
	
	// Load Script
	$.getScript(lightboxscript,function(){ 
		gallery.find('a').lightBox();
	});	
}
