var b = navigator.userAgent.toLowerCase();
	// Figure out what browser is being used
	jQuery.browser = {
		safari: /webkit/.test(b),
		opera: /opera/.test(b),
		msie: /msie/.test(b) && !/opera/.test(b),
		msie6: /msie 6.0/.test(b) && !/opera/.test(b),
		mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
	};

var animSpeed = 1000;
$(function(){
	/*$('#content ul').jCarouselFade({
		itemVisible: 3,
		itemScroll: 1,
		scrollAnimation: 'slow'
		});*/
	
	//alert(getProps($('#content ul').children('li'), 'ul', 1));
	
	/* hiding the loading image for the frontpage
	var img_loading = $('<img>').attr({ src: 'images/loadingAnimation.gif' }).css({ position: 'absolute', top: 150, left: '50%', marginLeft: -104 }).appendTo('#content');
	$('#content ul').css({ opacity: 0 });
	$(window).load(function(){
		$('#content ul').animate({ opacity: 1 }, 500, function(){
			img_loading.remove();
			$('input.scr_pause').trigger('click');
			});
		});
	*/
	//alert($.browser.msie6);
	if($('#content ul li').length > 3){
		$('#content').jCarouselLite({
			btnNext : ".scr_next",
			btnPrev : ".scr_prev",
			speed : animSpeed,
			beforeStart : function(el, next){
				//$('<div><\/div>').html($(el[0]).clone()).appendTo('body');
				//alert(next);
				//$('body').append(getProps($(el[0]).prev(), 'el0.prev', 1));

				var numEls = $('#content ul').children('li').length - 6;
				var nextEl = $(el[0]).attr('scrollNum') - next;
				var trackWidth = $('.scr_track').width() - $('.scr_thumb').width();
				var nextLi = 0;
				var leftPos = 0;
				
				if(nextEl == -2 || nextEl == (numEls - 2)){
					nextLi = Number($(el[0]).attr('scrollNum')) - 1;
					if(nextLi < 0){
						nextLi = numEls - 1;
						}
					leftPos = (trackWidth / (numEls - 1)) * nextLi;
					$('.scr_thumb').animate({ left : leftPos }, animSpeed);
	
					$('#content ul').children('li[scrollNum=' + nextLi + ']').css({ opacity : 0 }).animate({ opacity : 1 }, animSpeed);
					$(el[2]).animate({ opacity : 0 }, animSpeed);
					}
				else{
					nextLi = Number($(el[2]).attr('scrollNum')) + 1;
					if(nextLi > numEls - 1){
						nextLi = 0;
						}
					leftPos = (trackWidth / (numEls - 1)) * $(el[1]).attr('scrollNum');
					$('.scr_thumb').animate({ left : leftPos }, animSpeed);
	
					$('#content ul').children('li[scrollNum=' + nextLi + ']').css({ opacity : 0 }).animate({ opacity : 1 }, animSpeed);
					$(el[0]).animate({ opacity : 0 }, animSpeed);
					}
				//alert('nextLi: ' + nextLi + ', curr: ' + curr);
				var prevScrollNum = $.browser.msie6 ? $(prev(el[1])).attr('scrollNum') : $(el[0]).prev().attr('scrollNum');
				
				/*$('#curritem').html(jcl_dir == 'left' ? 
					String(Number(prevScrollNum) + 1) == 'NaN' ? $(el[0]).parent().children().length - 9 : String(Number(prevScrollNum) + 1)
					: String(Number($(el[1]).attr('scrollNum')) + 1));
				*/
				//$('#curritem').html(jcl_dir == 'left' ? nextLi + 1 : nextLi - 2);
				if (jcl_dir == 'left') {
					dispCount = Number(nextLi + 1);
				} else {
					dispCount = Number(next - 2);
					if (dispCount > numEls) {
						dispCount = Number(0 - (numEls - dispCount));
					}
				}
				if (dispCount <= 0) {
					dispCount = Number(numEls);
				}
				$('#curritem').html(String(dispCount));
				}
			});
		}

	/* controls for the scroll pane */
	/*$('#content ul')
	.mouseover(function(){
		jcl_int = clearInterval(jcl_int);
		jcl_stopped = true;
		})
	.mouseout(function(){
		if(jcl_stoplock === true){ return false; }
		jcl_int = setInterval(function() { go(jcl_dir == 'left' ? curr-1 : curr+1); }, 4000);
		jcl_stopped = false;
		});*/
	$('input.scr_pause')
	.mouseover(function(){
		if(jcl_stopped){
			$(this).css('backgroundImage', 'url(images/scr_play2.png)');
			}
		else{
			$(this).css('backgroundImage', 'url(images/scr_pause2.png)');
			}
		})
	.mouseout(function(){
		if(jcl_stopped){
			$(this).css('backgroundImage', 'url(images/scr_play.png)');
			}
		else{
			$(this).css('backgroundImage', 'url(images/scr_pause.png)');
			}
		})
	.click(function(){
		if(jcl_stopped){
			$(this).css('backgroundImage', 'url(images/scr_pause.png)');
			go(jcl_dir == 'left' ? curr-1 : curr+1);
			jcl_int = setInterval(function() { go(jcl_dir == 'left' ? curr-1 : curr+1); }, 3500);
			jcl_stopped = false;
			jcl_stoplock = false;
			}
		else{
			$(this).css('backgroundImage', 'url(images/scr_play.png)');
			jcl_int = clearInterval(jcl_int);
			jcl_stopped = true;
			jcl_stoplock = true;
			}
		});
	
	});
