
$(document).ready(function(){
	// Correct primary navigation
	nav = $('ul.primary-nav');
	nav.find('a').attr('title','');
	
	nav.find('>li').each(function(index, element){
		element.hoverId;
		$(element).hover(function(){
				$(this).addClass('hover')
				if (element.hoverId) clearTimeout(element.hoverId);
			},function(){
				$this = $(this);
				element.hoverId = setTimeout(function(){$(element).removeClass('hover')},70);
			}
		);
	})

	nav.find('div.b-sh').each(function(){
		var div = $(this);
		div.w = div.width();

		var innerUL = div.find('div.b-sh-w>ul');
		innerUL.w = innerUL.width();

		innerUL.find('>li').hover(function(){
				$(this).addClass('hover');
				var thirdUl = $(this).find('ul');
				if (thirdUl.length > 0)
				{
					div.width(850);
					innerUL.width(850);
					innerUL.height(thirdUl.height());
					div.width(div.w + thirdUl.width() + parseInt(thirdUl.css('padding-left'),10) + parseInt(thirdUl.css('padding-right'),10) + 5);
					innerUL.width(innerUL.w + thirdUl.width() + parseInt(thirdUl.css('padding-left'),10) + parseInt(thirdUl.css('padding-right'),10));
					innerUL.height( Math.max(thirdUl.height() + 24, innerUL.height() + parseInt(thirdUl.css('padding-top'),10) + parseInt(thirdUl.css('padding-bottom'),10)) );
				}
			},function(){
				$(this).removeClass('hover');
				innerUL.width(innerUL.w);
				div.width(div.w);
				innerUL.height('auto');
			}
		);
	});
	// END of Correct primary navigation

	// buttons hover effect
	$('input[type=submit], input[type=button]').hover(function() { $(this).addClass($(this).attr('type') + "-sfhover") },function(){ $(this).removeClass($(this).attr('type') + "-sfhover") });

	//  New design for inputs
	$('input[type=checkbox]').not('#moreContainer input[type=checkbox]').each(function(){
		ST_Design.init(this);
	});
	
	$('input[type=radio]').not('#moreContainer input[type=radio]').each(function(){
		ST_Design.init(this);
	});


	// Creating the top link
	function getPageSize(txt){
		var de = document.documentElement,
			h = window.innerHeight || self.innerHeight || (de&&de.clientHeight),
			wh = document.body.clientHeight,
			topLink = $('span#on-top-link');
		if (h*1.5 <= wh) {
			if ($(topLink).hasClass('hide')) $(topLink).attr('class','show').append(txt);
		} else {
			$(topLink).text('');
			$(topLink).attr('class','hide');
		}
	}
	getPageSize("<a href='#header' accesskey='t'>Top of Page</a>");
	window.onresize = function(){
		getPageSize("<a href='#header' accesskey='t'>Top of Page</a>");
	};

}); // End of ready



function OnToolTipShow(sender, eventArgs)
{
	if ($('div.TelerikModalOverlay')) {
		var tooltip = $('div.RadToolTip_NorthernNet:visible');
		$('div#NNOverlay').append(tooltip).append($('div.TelerikModalOverlay'));

		// Correct size of Overlay 	!IMPORTANT!
		$('div.TelerikModalOverlay').css({
			height: 0,
			width: '100%'
		});

		var height = $('div.container').height() + $('div.footer').outerHeight();
		height = $(window).height() > height ? $(window).height() : height;

		$('div.TelerikModalOverlay').css({ height: height });

		var top = Math.round($(document).scrollTop() + ($(window).height() - tooltip.height()) / 2);
		tooltip.css({
			top: top > 0 ? top : 20,
			left: Math.round( ($(window).width() - tooltip.width()) / 2 )
		})
	}    
}
