// JavaScript Document

//give tables alternating row colours
$(document).ready(function(){
	$('.form table tr:odd').addClass("odd");
	$('.form').eq(0).css({'background':'url(images/graphics/form_bg.png) -260px -260px no-repeat'});

});

//make tabs on page
$(document).ready(function(){
	$('.tab').click(function(){
		$('.tab').removeClass("activeTab");
		$(this).addClass("activeTab");
		console.log('switch');					 
	});
		
});

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

$(function(){
	$('#navigation li')
		.css( {backgroundPosition: "-20px 35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-20px 104px)"}, {duration:500});
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-20px 35px"})
			}})
		})
});

//Handles login field clearing and color change
$(function(){
	if($('#login input').eq(0).attr('value') == ''){
		console.log($('#login input').eq(0).attr('value'));
		$('#login input').eq(0).css('background', 'url(images/graphics/username.png) no-repeat');
	}
	if($('#login input').eq(1).attr('value') == ''){
		$('#login input').eq(1).css('background', 'url(images/graphics/password.png) no-repeat');
	}
	$('#login input').focus(function(){
		if($(this).css('backgroundPosition')=='0% 0%' && $(this).attr('value') == ''){
			$(this).css('backgroundPosition','-1000% 0%');
		}
	});
	$('#login input').blur(function(){
		if($(this).attr('value') == ''){
			$(this).css('backgroundPosition','0% 0%');
			console.warn($(this).attr('value'));
		}
	});
});

/*
$(function(){
	i=0;
	var barColours = new Array();
	barColours[1] = '#f08';
	barColours[2] = '#ea7';
	barColours[3] = '#1ba';
	barColours[4] = '#c35';
	$('.barGraph div').each(function(){
		i++;
		$('.barGraph div').eq(i-1).css({backgroundColor:barColours[i]});
	});
});
*/

//submit button disabled until agree to TOS
$(function(){
	var reqCheck = $('.buttonSet .checkbox:checked').is(':checked');
	isRequired()
	$('.buttonSet .checkbox').change(function(){
	isRequired()
	});
	function isRequired(){
		if(reqCheck==false){
			$('.buttonSet .button').css({backgroundPosition:'0px -50px'});
			$('.buttonSet .button').attr('disabled','disabled');
			reqCheck = true;
		}
		else
		{
			$('.buttonSet .button').css({backgroundPosition:'0px 0px'});
			$('.buttonSet .button').hover(function(){
				$('.buttonSet .button').css({backgroundPosition:'0 -25px'});
			})
			$('.buttonSet .button').hover(
			function(){
				$('.buttonSet .button').css({backgroundPosition:'0 -25px'});
			},
			function(){
				$('.buttonSet .button').css({backgroundPosition:'0 0'});
			})
			reqCheck = false;
			$('.buttonSet .button').attr('disabled','');
		}
	}
	
});