// JavaScript Document

/* Let's align our columns */
function alignColumns() {
	var H = 0;
	$(".align").each(function(i){
		var h = $(".align").eq(i).height();
		if(h > H) H = h;
	});
	$(".align").height(H);
	console.log('align');
}

/* animates rollovers on the grid */
function gridItemsRollovers() {
	$(".grid_item").hover(function() {
	  $(this).find(".color").hide().fadeIn(150);
	}, function() {
	  //$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});

}

function scrollTxt() {
	if ($('.content-textbox').height() - $('.moveme').height() < 0) { 
		//$('.content-textbox').mousemove(mouseoverDiv); 
		$('#content_text').append('<div class="up"><img src="/uploads/images/up.gif" /></div><div class="down"><img src="/uploads/images/down.gif" /></div>');
		$('#content_text .up').hover(startUpDown, stopUpDown);
		$('#content_text .down').hover(startUpDown, stopUpDown);
	}
	if ($('.thumbs img').length > 5) { 
		//$('.thumbs').mousemove(mouseoverDivThumb);
		$('.gallery').append('<div class="left"><img src="/uploads/images/left.gif" /></div><div class="right"><img src="/uploads/images/right.gif" /></div>');
	}
		$('#content_text .left').hover(startLeftRight, stopUpDown);
		$('#content_text .right').hover(startLeftRight, stopUpDown);
		
	//$('.content-textbox').hover(function() {}, function() {$('.moveme').animate({'top': '5px'})});
}
var updwI = 0
var updwID = 0
function startUpDown(e) {
	updwID = $(this).hasClass('up') ? 2 : -2;
	updwI = setInterval(moveUpDown, 10);
} 

function startLeftRight(e) {
	updwID = $(this).hasClass('left') ? 2 : -2;
	updwI = setInterval(moveLeftRight, 10);
} 

function stopUpDown(e) {
	clearInterval(updwI);
}

function moveLeftRight() {
	var min = -($('.thumbs img').length-5)*84
	_y = $('.thumbs .list').position().left + updwID;
	_y = _y > 0 ? 0 : _y
	_y = _y < min ? min : _y;
	$('.thumbs .list').css({'left': _y+'px'});
}

function moveUpDown() {
	var min = $('.content-textbox').height() - $('.moveme').height();
	_y = $('.moveme').position().top + updwID;
	_y = _y > 5 ? 5 : _y
	_y = _y < min ? min : _y;
	$('.moveme').css({'top': _y+'px'});
}

function mouseoverDiv(e) {
	var proc = ((e.pageY - $('.content-textbox').offset().top)/$('.content-textbox').height());
	if (proc < 0) { proc = 0; }
	if (proc > 1) { proc = 1; }
	var _y = proc * ($('.content-textbox').height() - $('.moveme').height() - 10) + 5;
	$('.moveme').css({'top': _y+'px'});
}

function mouseoverDivThumb(e) {
	var proc = ((e.pageX - $('.thumbs').offset().left)/419);
	if (proc < 0) { proc = 0; }
	if (proc > 1) { proc = 1; }
	var _x = proc * (3-($('.thumbs img').length-5)*84) ;
	$('.list').css({'left': Math.round(_x)+'px'});
}


$(document).ready(function(){
	//alignColumns();
	gridItemsRollovers();
	scrollTxt();
	$('.bigimage').hide();
});


