﻿/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function(jQuery){jQuery.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=jQuery.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){jQuery(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;jQuery(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{jQuery(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


jQuery().ready(function () {

    //add html for font resizing
    jQuery(".globalMenu").before("<ul class='textSize'><li class='small'><a href='#'><span>A</span></a></li><li class='medium'><a href='#'><span>A</span></a></li><li class='large'><a href='#'><span>A</span></a></li></ul>");


    //z-indexing main menu because of sliced end
    var zIndex = 1003;
    jQuery(".mainMenu > ul > li").each(function () {
        jQuery(this).css("z-index", zIndex);
        zIndex--;
    });


    //main menu with delay
    jQuery(".mainMenu").addClass("jQmainMenu");
    var hoverconfig = {
        over: showSubmenu, // function = onMouseOver callback (REQUIRED)
        timeout: 300, // number = milliseconds delay before onMouseOut
        out: hideSubmenu // function = onMouseOut callback (REQUIRED)
    };
    jQuery(".jQmainMenu > ul > li").hoverIntent(hoverconfig);


    //changing font size
    currentFontSizeIndex = readCookie('fontSize');
    if (currentFontSizeIndex >= 0 && currentFontSizeIndex <= 2) { /**/ } else { currentFontSizeIndex = 0; }
    changeFontSize(currentFontSizeIndex);
    jQuery(".textSize a").click(function () {
        index = jQuery(this).parents("li").index();
        changeFontSize(index, false);
        return false;
    });


    //striped list
    jQuery(".GreyPinkUnderline li:odd").addClass("zebra");

    //striped table
    jQuery(".mainAndRightCol table").each(function () {
        jQuery(this).find("tr:even").addClass("zebra");
        jQuery(this).find("tr:eq(0)").addClass("headerRow");
    });


    //remove <br> from breadcrumb
    jQuery("#breadCrumb br").remove();


    //add indent on regulation
    $("body").prepend("<div class='test'></div>");
    jQuery(".regulation p").each(function () {
        if ($(this).text().trim() == "") {
            //remove empty <p>'s
            $(this).remove();
        } else {
            //remove <span class="innrykk"></span> that is at the start of a <p>
            if ($(this).html().trim().substring(0, 12) == "<span class=") {
                $(this).find(".innrykk:eq(0)").remove();
            }
            //add line break before <span class="innrykk"></span>
            $(this).find(".innrykk").before("<br />");
        }
    });
});

function showSubmenu() {
    jQuery(this).find("ul").css("top", "auto");
}
function hideSubmenu() {
    jQuery(this).find("ul").css("top", "-9999em");
}

function changeFontSize(index, animated) {
	var newBodyFontSize = 0.75 + index * 0.1 + "em";
	var newContentFontSize = 1 + index * 0.18 + "em";
	if (animated) { //when changing font size
		jQuery("body").animate({fontSize : newBodyFontSize}, "fast");
		jQuery(".mainCol").animate({fontSize : newContentFontSize}, "fast");
	} else { //from cookie
		jQuery("body").css({fontSize : newBodyFontSize});
		jQuery(".mainCol").css({fontSize : newContentFontSize});
	}
	jQuery(".textSize a").removeClass("selected");
	jQuery(".textSize li:eq(" + index + ") a").addClass("selected");
	createCookie('fontSize', index, 30);
}

//---cookie functions http://www.quirksmode.org/js/cookies.html----------
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
//---cookie functions end---

