var scroll_offset = 0;
var scroll_width = 0;
$(document).ready(function() {
	$('#scroller-hide').click(function(){
		scroller_hide();
		return false;
	});
	$('#scroller-show').click(function(){
		$('#scroller').slideToggle();
		$('#scroller-show').hide();
		return false;
	});
	scroll_offset = $('#scroll-list li').outerWidth(true);
	scroll_width = scroll_offset * $('#scroll-list li').length;
	var scroll_start = false;
	$('#scroll-list').width(scroll_width);
	$('#scroll-next').click(function(){
		if (scroll_start == false) {
			var p = $('#scroll-list').position();
			if (p.left > (-scroll_width + (scroll_offset * 4))) {
				scroll_start = true;
				$('#scroll-list').animate({left:'-='+scroll_offset},1000,function(){scroll_start = false;});
			}
		}
		return false;
	});
	$('#scroll-prev').click(function(){
		if (scroll_start == false) {
			var p = $('#scroll-list').position();
			if (p.left < 0) {
				scroll_start = true;
				$('#scroll-list').animate({left:'+='+scroll_offset},1000,function(){scroll_start = false;});
			}
		}
		return false;
	});
	$('#nav li a').click(function(){
		var href = $(this).attr('href');
		if (href.charAt(0) == '#') {
			drop_clear();
			var p = $(this).position();
			$(href).css('left',p.left+440).fadeIn();
			$(this).parent().addClass('active');
			return false;
		} else {
			return true;
		}
	});
	$('.drop').hover(function(){},function(){
		drop_clear();
	});
	// drop down thumbnails
	//$('.drop a').hover(function(){
		//var src = $(this).attr('rel');
		//if (src) $(this).closest('.drop').find('img').show().attr('src',src);
	//},function(){});
	$('#counter-down').click(function(){
		counter_show(false);
		return false;
	});
	$('#counter-up').click(function(){
		counting = false;
		$('#counter').slideUp();
		$(this).hide();
		$('#counter-down').show();
		return false;
	});
});
function scroller_hide(){
	$('#scroller').slideToggle();
	$('#scroller-show').show();
}
function counter_show(show){
	if (show) {
		$('#counter').show();
	} else {
		$('#counter').slideDown();
	}
	$('#counter-down').hide();
	$('#counter-up').show();
	counting = true;
	//counter();
}
function drop_clear(){
	$('#nav li.active').removeClass('active');
	$('.drop').fadeOut();
}
var count = 1001000000;
var count_max = 1001009023;
var counting = false;
function counter(){
	count++;
	if (count <= count_max) {
		var num = String(count).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
		$('.counter-number').text(num);
		if (counting) setTimeout(counter,1000);
	}
}
