/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                 //
//                                         ___           ___                                                       //
//                                        /__/\         /  /\         _____                                        //
//                                       _\_ \:\       /  /:/_       /  /::\                                       //
//                                      /__/\ \:\     /  /:/ /\     /  /:/\:\                                      //
//                                     _\_ \:\ \:\   /  /:/ /:/_   /  /:/~/::\                                     //
//                                    /__/\ \:\ \:\ /__/:/ /:/ /\ /__/:/ /:/\:|                                    //
//                                    \  \:\ \:\/:/ \  \:\/:/ /:/ \  \:\/:/~/:/                                    //
//                                     \  \:\ \::/   \  \::/ /:/   \  \::/ /:/                                     //
//                                      \  \:\/:/     \  \:\/:/     \  \:\/:/                                      //
//                                       \  \::/       \  \::/       \  \::/                                       //
//                                        \__\/         \__\/         \__\/                                        //
//        ___           ___                         ___                                   ___           ___        //
//       /  /\         /  /\                       /__/\          ___       ___          /  /\         /__/\       //
//      /  /:/_       /  /::\                      \  \:\        /  /\     /  /\        /  /::\        \  \:\      //
//     /  /:/ /\     /  /:/\:\    ___     ___       \  \:\      /  /:/    /  /:/       /  /:/\:\        \  \:\     //
//    /  /:/ /::\   /  /:/  \:\  /__/\   /  /\  ___  \  \:\    /  /:/    /__/::\      /  /:/  \:\   _____\__\:\    //
//   /__/:/ /:/\:\ /__/:/ \__\:\ \  \:\ /  /:/ /__/\  \__\:\  /  /::\    \__\/\:\__  /__/:/ \__\:\ /__/::::::::\   //
//   \  \:\/:/~/:/ \  \:\ /  /:/  \  \:\  /:/  \  \:\ /  /:/ /__/:/\:\      \  \:\/\ \  \:\ /  /:/ \  \:\~~\~~\/   //
//    \  \::/ /:/   \  \:\  /:/    \  \:\/:/    \  \:\  /:/  \__\/  \:\      \__\::/  \  \:\  /:/   \  \:\  ~~~    //
//     \__\/ /:/     \  \:\/:/      \  \::/      \  \:\/:/        \  \:\     /__/:/    \  \:\/:/     \  \:\        //
//       /__/:/       \  \::/        \__\/        \  \::/          \__\/     \__\/      \  \::/       \  \:\       //
//       \__\/         \__\/                       \__\/                                 \__\/         \__\/       //
//                           ___           ___           ___           ___           ___                           //
//                          /  /\         /__/\         /  /\         /  /\         /__/|                          //
//                         /  /:/_        \  \:\       /  /::\       /  /:/        |  |:|                          //
//                        /  /:/ /\        \__\:\     /  /:/\:\     /  /:/         |  |:|                          //
//                       /  /:/ /::\   ___ /  /::\   /  /:/~/::\   /  /:/  ___   __|  |:|                          //
//                      /__/:/ /:/\:\ /__/\  /:/\:\ /__/:/ /:/\:\ /__/:/  /  /\ /__/\_|:|____                      //
//                      \  \:\/:/~/:/ \  \:\/:/__\/ \  \:\/:/__\/ \  \:\ /  /:/ \  \:\/:::::/                      //
//                       \  \::/ /:/   \  \::/       \  \::/       \  \:\  /:/   \  \::/~~~~                       //
//                        \__\/ /:/     \  \:\        \  \:\        \  \:\/:/     \  \:\                           //
//                          /__/:/       \  \:\        \  \:\        \  \::/       \  \:\                          //
//                          \__\/         \__\/         \__\/         \__\/         \__\/                          //
//                                                                                                                 //
//                                                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                 //
//                                       W e b   S o l u t i o n   S h a c k                                       //
//                                                    Matt Rabe                                                    //
//                                                       '09                                                       //
//                                                                                                                 //
//                                             www.websolutionshack.com                                            //
//                                                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var speed = 6; // 1 to 10
var rate = 10; // This number is the amount of time between cycles
var avatar_xmargin = 12;
var avatar_width = 58;
var avatar_border = 6;
var numberofavatars = 18;
var numberofavatarsinpreview = 7;

var avatarselector_locked = false;
function avatarselector_move(dir)
{
	if (!avatarselector_locked)
	{
		avatarselector_locked = true;

		dir = (dir == -1 ? -1 : 1);

		left = ($('avatars').getStyle('left') == null || $('avatars').getStyle('left') == '') ? 0 : parseInt($('avatars').getStyle('left'));

		if (dir > 0)
		{
			goal = left + -(numberofavatarsinpreview * (avatar_xmargin + avatar_width + avatar_border));
		}else{
			goal = left + (numberofavatarsinpreview * (avatar_xmargin + avatar_width + avatar_border));
		}

		if (goal <= 0 && goal >= -(numberofavatars * (avatar_xmargin + avatar_width + avatar_border)))
		{
			avatarselector_updateArrows();
			
			avatarselector_scroll(goal, dir);
		}else{
			avatarselector_locked = false;
		}
	}
}

function avatarselector_scroll(goal, dir)
{
	dir = (dir == -1 ? -1 : 1);

	left = ($('avatars').getStyle('left') == null || $('avatars').getStyle('left') == '') ? 0 : parseInt($('avatars').getStyle('left'));

	if (goal != left)
	{
		if (dir > 0)
		{
			next = left - Math.ceil((left - goal) / (31 - (speed * 3)));

			$('avatars').setStyle('left: '+next+'px');

			window.setTimeout('avatarselector_scroll('+goal+', '+dir+')', rate);
		}else{
			next = left + Math.ceil((goal - left) / (31 - (speed * 3)));

			$('avatars').setStyle('left: '+next+'px');

			window.setTimeout('avatarselector_scroll('+goal+', '+dir+')', rate);
		}
	}else{
		avatarselector_locked = false;
	}
}

function avatarselector_updateArrows()
{
	if (goal == 0)
	{
		$$('#avatarselector_prev a')[0].addClassName('disabled');
		$$('#avatarselector_next a')[0].removeClassName('disabled');
	}else if (goal <= (avatar_xmargin + avatar_width + avatar_border) * -(numberofavatars - numberofavatarsinpreview))
	{
		$$('#avatarselector_prev a')[0].removeClassName('disabled');
		$$('#avatarselector_next a')[0].addClassName('disabled');
	}else{
		$$('#avatarselector_prev a')[0].removeClassName('disabled');
		$$('#avatarselector_next a')[0].removeClassName('disabled');
	}
}

function avatarselector_gotoAvatar(ind)
{
	goal = Math.floor((ind - 1) / numberofavatarsinpreview) * -(numberofavatarsinpreview * (avatar_xmargin + avatar_width + avatar_border));
	
	if (goal < 0)
	{
		$('avatars').setStyle('left: '+goal+'px');
		
		avatarselector_updateArrows();
	}
}
