/*-----------------------------------------------------------------
  Easy form element styling (because of IE6)
-----------------------------------------------------------------*/
$(document).ready(function() {
	$("input[@type=password], input[@type=text]").addClass("text");
	$("input[@type=password], input[@type=text], textarea").focus(function() {
		$(this).addClass("focus");
	});
	$("input[@type=password], input[@type=text], textarea").blur(function(){
		if ($(this).find(".focus")) {
			$(this).removeClass("focus");
		}
	});
});

/*-----------------------------------------------------------------
  Copy values
-----------------------------------------------------------------*/
function copyVals(elements)
{
	for (var n in elements)
	{
		$(elements[n]).val($(n).val());				  
	}
}
/*-----------------------------------------------------------------
  Tabs (custom by Ian)
-----------------------------------------------------------------*/
(function($) {
	$.fn.tabs = function() {
		return this.each(function() {
			var container = this;
			$('.tabs-container', container).not(':first').hide();
			$('.tabs-nav a:first', container).parent().addClass('active');
			$('.tabs-nav a', container).click(function(){
				var link = $(this);
				$('.tabs-nav a', container).parent().removeClass('active');
				link.parent().addClass('active');
				$('.tabs-container', container)
				.filter(function(){return ('#' + $(this).attr('id')) != link.attr('href')})
				//.fadeOut()
				.hide()
				.end()
				.filter(function(){return ('#' + $(this).attr('id')) == link.attr('href')})
				.fadeIn();
				//.show();
				return false;
				});
		});
	}
})(jQuery);
/*-----------------------------------------------------------------
  Form Dependency Toggle
  Things to do:
	-Comment this sucker
	-rel of target connects to **id** of trigger (less markup needed)
	-create functions for option elements
-----------------------------------------------------------------*/
(function($) {	
	$(document).ready(function(){
		var d1 = new Date();
		var t1 = d1.getTime();
		initialCheck();
		addHooks();
		var d2 = new Date();
		var change = d2.getTime() - t1;
		$('#log').append('Loaded in: ' + change / 1000 + ' secs<br />');
	});
	
	function addHooks()
	{
		$('input:checkbox[@rel]').click(function(){
			var rel = $(this).attr('rel');
			if ($(this).attr('checked'))
				showAndEnable(rel);
			else
				hideAndDisable(rel);
		});
		$('input:radio[@rel]').click(function(){
			var rel = $(this).attr('rel');
			var name = $(this).attr('name');
			hideOtherRadio(name, rel);
			showAndEnable(rel);
		});
		/* ------------ not done ------------
		$('option[@rel]').click(function(){
			
			hideOthers(name, rel);
			showAndEnable(rel);
		}); ------------ not done ------------ */
	}
	
	function initialCheck()
	{
		
		$('input[@rel]').each(function(){
			if (!$(this).attr('checked'))//{
				hideAndDisable($(this).attr('rel'));//$('#log').append($(this).attr('id') + ' found<br />');}
		});
		// $('[@rel]').not('input').not('option').each(function()
			// {	
				// if (!$('input[@rel=' + $(this).attr('rel') + ']').attr('checked'))
					// hideAndDisable($(this).attr('rel'));
			// });
	}
	
	function hideAndDisable(rel)
	{
		$('[@rel=' + rel + ']').not('input').not('option').not('.hd')
			.addClass('hd')
			.hide()
			.find('input, select, textarea').not('.hd')
			.addClass('hd')
			.attr('disabled','disabled')
			/* .each(function(){
				if ($(this).attr('rel'))
				{
					hideAndDisable($(this).attr('rel')); 
					//console.log('called on: ' + $(this).attr('id'));
				} 
			}); */
	}
	
	function showAndEnable(rel, animationOptions)
	{
		$('[@rel=' + rel + ']').not('input').not('option').filter('.hd')
		.removeClass('hd')
		.show('fast')
		.find('input.hd, select.hd, textarea.hd')
		.removeClass('hd')
		.removeAttr('disabled')
		// .each(function(){ if ($(this).attr('rel') && $(this).attr('checked')) showAndEnable($(this).attr('rel')) });
	}
	
	/* ------------ not done ------------
	function hideOtherSelect(name, not$(this)Rel)
	{
		$('input[@name=' + name + ']').each(function(){
			var rel = $(this).attr('rel');
			if (rel != not$(this)Rel)
			{
				hideAndDisable(rel);
			}
		});
	} ------------ not done ------------ */
	
	function hideOtherRadio(name, notThisRel)
	{
		$('input:radio[@name=' + name + ']').each(function(){
			var rel = $(this).attr('rel');
			if (rel && rel != notThisRel)
			{
				hideAndDisable(rel)
			}
		});
	}
})(jQuery);