/* JQuery powered Javascript
 * initialisation + custom animation + JQuery Smart Columns
 * for LeComtois.com
 * by Mikaël Geljic
 * |\/|.GELJIC [à] G|\/|AIL
 */
$(document).ready(function(){
	hoverfade = true;
	if($("div#logo").css("position") == "relative") { // checks a single css rule to see if CSS are actually enabled*/
		hoverInit();
	}
});
function hoverInit() {
	$('li.item a.csshover').removeClass("csshover");
	$('li.item:not(.small) a').bind("mouseenter", jshover).each(function() {
		var a = $(this);
		$(this).clone().addClass("jshover").removeClass("rounded").insertAfter(a).bind("mouseleave", jshoverout);
	});
}

function jshover() {
	$(this).unbind("mouseenter", jshover);
	$('a.jshover:visible').trigger("mouseleave");
	
	var li = $(this).next().css("margin-top", -320);
	
	var pos = $(this).position();
	var hh = $(li).height();
	var sct = $().scrollTop();
	var cli = $(window).height();
	
	var btm = pos.top + hh;
	var btmref = sct+cli;
	var offt = pos.top - sct;
	var offb = btmref - btm;
	if(offb<20) {
		if(hh+50>cli) {
			$(li).css("margin-top", -offt+30-320);
		} else {
			$(li).css("margin-top", offb-20-320);
		}
	}
	if(offt<30) {
		$(li).css("margin-top", -offt+30-320);
	}
	$(li).fadeIn("slow");
}

function jshoverout() {
	$(this).hide();
	$(this).prev().bind("mouseenter", jshover);
}