// for the menu on all pages

function fixHover(cssPath, hoverClass, delay) {

	$(document).ready(function() {
		$(cssPath).hover(
			function () {$(this).addClass(hoverClass);},
			delay
				? function () {$(this).removeClass(hoverClass);}
				: function () {setTimeout(function () {$(this).removeClass(hoverClass);}, delay)}
			);
	});
}

function hoverImgSwap(hoverobj_path, img_path, hover_url, container) {
	$(container || 'body').each(function() {
		var hoverobj = $(hoverobj_path, this);
		if (hoverobj.length) {
			var img = img_path == hoverobj_path
				? hoverobj
				: $(img_path, this);

			if (img.length) {
				var normal_url = img[0].src;
				hoverobj.hover(
					function () {img.attr('src',hover_url)},
					function () {img.attr('src',normal_url)}
					);

				//preload img
				$("<img>").attr("src", hover_url);
			}
		}
	});
}

function hoverClassToggle(hoverobj_selector, target_selector, hover_class, container) {
	$(container || 'body').each(function() {
		var hoverobj = $(hoverobj_selector, this);
		if (hoverobj.length) {
			var target = target_selector == hoverobj_selector
				? hoverobj
				: $(target_selector, this);

			hoverobj.hover(
				function () {
					target.addClass(hover_class)
				},
				function () {target.removeClass(hover_class)}
				);
		}
	});
}


//compute absolute offset of an element relative to body or ancestor (a)
function getOffsetTop(d, a) {
	var gy = d.offsetTop;
	while ((d = d.offsetParent) && (!a || d!=a)) gy += d.offsetTop;
	return gy;
}

// get current scroll value for body
function getScrollTop(){
	var body=document.body;
	var d=document.documentElement;
	if (body && body.scrollTop) return body.scrollTop;
	if (d && d.scrollTop) return d.scrollTop;
	if (window.pageYOffset) return window.pageYOffset;
	return 0;
};

//fixHover('#nav li', 'sfhover');
//fixHover('#news-block .news', 'news-hover');
//fixHover('#bloc_news2', 'hover');
