/*
 * 	MouseoverNavigation the jQuery version
 * 	A Javascript Module by Gaya Kessler
 * 	Version 1.0
 * 	Date: 09-04-09
 * 
 */
 
var MouseoverNav = {
	
	statusArr: new Array(),
	debugging: false,
	containerHeight: 0,
	container: "",
	photo: "",
	photoHeight: 0,
	
		
	init: function(id, height, height2, activeMouseContainerPercent, debugging) {
		//catch undefined vars	
		if (typeof(debugging) != 'undefined') {
			MouseoverNav.debugging = debugging;
		} else {
			MouseoverNav.debugging = false;
		}
		
		//make room in status array
		MouseoverNav.statusArr[0] = "";
		MouseoverNav.statusArr[1] = "";
		
		$('#' + id).mousemove(function(event){
			var x = event.pageX - $(this).offset().left; //358
			var y = event.pageY - $(this).offset().top - (MouseoverNav.containerHeight * activeMouseContainerPercent);
			var activeMouseHeight = MouseoverNav.containerHeight * (1 - activeMouseContainerPercent * 2);

			if (y < 0) y=0;
			if (y > activeMouseHeight) y = activeMouseHeight;
			
			var perc = (y / activeMouseHeight) * 100;
			
			MouseoverNav.posPicture(perc);
			
			MouseoverNav.addStatus('X: '+x+'  Y:'+y + ' '+perc+'%');
	    });
		
		//set some object vars
		MouseoverNav.container = id;
		MouseoverNav.containerHeight = height;
		MouseoverNav.photoHeight = height2;

		$("#" + id + " .fixed").each(function(i) {
			MouseoverNav.photo = $(this);
			MouseoverNav.photo.css({"height":height2 + "px"});
		});
		
		$('#'+MouseoverNav.container).css({"height":height + "px"});
	},
	
	addStatus: function(str) {
		if (MouseoverNav.debugging == true) {
			MouseoverNav.statusArr.unshift(str);
			MouseoverNav.statusArr.splice(3, 10);
			
			$("#status").html("");
			
			for (var i = 2; i > 0; i = i - 1) {
				$("#status").html(MouseoverNav.statusArr[i] + "<br />" + $("#status").html());
			}
		}
	},
	
	posPicture: function(y) {
		var full = MouseoverNav.photoHeight;
		full = full - MouseoverNav.containerHeight;
		var curY = full * (y / 100);
		
		if (curY < 0) curY = 0;
		
		MouseoverNav.addStatus("curY container: " + curY);
		
		MouseoverNav.photo.css({
			marginTop: "-"+curY+"px"
		});
	}
}
