//javascript

//by Mark Tank

$(function() {
	var whereArray;
	var inRange = "";
	$('#flicker').children().filter(function(index) { 
		var middle = Math.floor($('.thumb').length  / 2);
		return index != middle;
	}).hide();
	
	$(document).ready(function() {
		var thumbs = $('#flicker').children().length; // how many thumbnails
		var offset = $('#flicker').offset(); //where the scorller box is from the left
		var totalArea = $('#flicker').width(); //total scroll area
		var chunk = Math.floor(totalArea / thumbs);
		whereArray = new Array();
		whereArray.push(offset.left + totalArea);
		for(i=0; i < thumbs; i++) {
			totalArea = totalArea - chunk
			whereArray.push(offset.left + totalArea - chunk);
		}
		$('#flicker > img').live('click', function() {
			var bigURL = $(this).attr('src').replace("-s","");
			$('#show').fadeOut('slow',function() {
				$('#show').attr('src', bigURL);
				$(this).fadeIn('slow');
			});
		});
	});
	
	$('#flicker').mousemove(function(event) {
		var inRange = "";
		var mX = mouseX(event);
		for(i=0;i < whereArray.length; i++) {
			if(mX <= whereArray[i] && mX >= whereArray[i+1]) {
				inRange = i; 
			}
		}
		$('#flicker').children().each(function(index) {
			if(inRange == index) {
				$(this).show();
			}
			else {
				$(this).hide();
			}
		});
	});
	
	function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
	}
	function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
	}
});
