$(document).ready(function() {
	/**
	 * -------------------------------------------------------------------------
	 * This is for the search box...setting and resetting the text
	 * -------------------------------------------------------------------------
	 */
	$('#search_box').focus(function(){
		$(this).val('');
	});
	$('#search_box').blur(function(){
		if ($(this).val() == '') {
			$(this).val('Search');
		}
	});

	/**
	 * -------------------------------------------------------------------------
	 * This is for the navigational menus
	 * -------------------------------------------------------------------------
	 */
	
	$('ul#navigation_main > li').hover(
		function() {
			$(this).find('ul:first').show();
		},
		function() {
			$(this).find('a:first').css('height', 'auto');
			$(this).find('ul:first').hide();
						
		}
	);
	/**
	 * -------------------------------------------------------------------------
	 * Rotator
	 * -------------------------------------------------------------------------
	 */

	var mover = 0;
	var window = 3;
	var total_elems = $('#rotator_content > dl').length;
	var total_width = total_elems * 250;
    $('#rotator_content').css('position', 'relative');
	$('#rotator_content').css('width', total_width+'px');

	var bar_size = 290;
	var dongle_size = 10;
	var bar_length = bar_size - dongle_size;

	var dongle_movement = bar_length / (total_elems - window);
	var dongle_path = 0;

	$('.btn_left').click(function() {

		if (window > 3) {
			window -= 1;
			mover += 115;

			$('#rotator_content > dl').animate({
				left: mover + 'px'
			});
			dongle_path -= dongle_movement;
			if (dongle_path <= 5) {
				dongle_path = 1;
			}
			$('#dongle').animate({
				left: dongle_path + 'px'
			});

		}
		return false;
	});
	$('.btn_right').click(function() {
		if (window < total_elems) {
			mover -= 115;
			window += 1;

			$('#rotator_content > dl').animate({
				left: mover + 'px'
			});
			dongle_path += dongle_movement;
			if (dongle_path > bar_length) {
				dongle_path = bar_length-1;
			}
			$('#dongle').animate({
				left: dongle_path + 'px'
			});

		}
		return false;
	});
	/**
	 * --
	 * GRABBER
	 * ---
	 */
	
/*$('#dongle').mousedown(function(e) {
		var startingXPosition = e.clientX;
		$('#update_bar').mousemove(function(e){
			var newX = (startingXPosition - e.clientX)*10;
			$('#content_ancillary').text(Math.abs(newX));
			$('#rotator_content > dl').animate({
				left: $(this).clientX-Math.abs(newX) + 'px'
			});		
		});
	});*/
	return false;
});
