// $Id$
// JavaScript Document
// Original script: Anchor Jump . brandspankingnew - http://www.brandspankingnew.net/specials/anchorjump/anchorjump_01.html
/*
The script parses all of the links to anchors on the page and replaces them with a javascript method that scrolls the page to the anchor instead of jumping to it. Turning off javascript leaves you with classic anchor links.
*/
$(document).ready(function () {
							
	var scrollInt;
	var scrLocation = window.location.href;
	var scrNum = scrLocation.indexOf("#");
	var scrUrl = scrLocation.slice(0,scrNum);

	var scrTime, scrSt, scrDist, scrDur, scrInt;

	function replaceAnchorLinks()
	{
		var anchors, i, targ, targarr, className;
	
		if (!document.getElementById)
			return;
		
		// get all anchors
		anchors = $("a");
		
		for (i=0;i<anchors.length;i++)
		{
				// check if href links to an anchor on this page
			if ( anchors[i].href.indexOf("#") != -1 && anchors[i].href.indexOf( scrUrl ) != -1 )
			{
				// get name of target anchor
				targ = $(anchors[i]).attr("href").substring( $(anchors[i]).attr("href").indexOf("#")+1 );
				
				// find target anchor
				targarr = $("*[name=" + targ + "]") ;
				
				if (targarr.length && targ !='')
				{
					className = (targarr[0].offsetTop < anchors[i].offsetTop) ? "up" : "down";
					$(anchors[i]).addClass(className);
					$(anchors[i]).attr("id", "__" + targ); // save target as id with prefix (used in onclick function below)
					$(anchors[i]).mouseup(function () { scrollToAnchor( this.id.substring( 2 ) ); return false; });
					/*$(anchors[i]).attr("href", "#jump:" + $(anchors[i]).text());*/ // rewrite href	
					$(anchors[i]).attr("href", "#k"); // rewrite href	
				}
			}
			
		}
	}
	/*
	SCROLL FUNCTIONS
	*/
	function scrollPage()
	{
		scrTime += scrInt;
		if (scrTime < scrDur) {
			window.scrollTo( 0, easeInOut(scrTime,scrSt,scrDist,scrDur) );
		}else{
			window.scrollTo( 0, scrSt+scrDist );
			clearInterval(scrollInt);
		}
	}
	
	function scrollToAnchor(aname)
	{
		var anchors, i, ele;
	
		if (!document.getElementById)
			return;
		
		// get anchor
		anchors = $("a");
		for (i=0;i<anchors.length;i++) {
			if ($(anchors[i]).attr("name") == aname) {
				//alert ($(anchors[i]).attr("name"));
				ele = anchors[i];
				i = anchors.length;
				//alert (ele);
				//ele = $('#'+aname).offset().top;
				
				//alert (aname + '--' + ($("#adatlap-kitoltese").offset().top));
			//	alert (aname + '--' + ($("#"+aname).offset().top));
				//alert (currentOffset);

			}
		}
		
		// set scroll target
		if (window.scrollY)
			scrSt = window.scrollY;
		else if (document.documentElement.scrollTop)
			scrSt = document.documentElement.scrollTop;
		else
			scrSt = document.body.scrollTop;
			
			//alert (ele.offsetTop);
			/*var offset = ele.offset().top;
			alert (offset);*/
			//alert (ele.offsetTop);
				//			alert (this.offsetTop);
			
			
		var v;
		
		if ($("#"+aname))
		{
				//alert (($("#"+aname).offset().top));
				v = ($("#"+aname).offset().top);
		}
		else
		{
		if (ele.offsetTop > 414)
			v = ele.offsetTop + 414;
			else
			v = 0;	
		}
		//alert (ele.offsetTop);
		//alert (($("#"+aname).offset().top));
		
		/*if (ele.offsetTop > 414)
			v = ele.offsetTop + 414;
			else
			v = 0;*/

	/*alert (ele.offsetTop);*/
		//scrDist = v - scrSt;
		scrDist = v - scrSt + 414;

		scrDur = 500;
		scrTime = 0;
		scrInt = 10;
		
		// set interval
		clearInterval(scrollInt);
		scrollInt = setInterval( scrollPage, scrInt );
	}
	
	/*
	EASING FUNCTIONS
	*/
	
	function easeInOut(t,b,c,d)
	{
		return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
	}
	
	$(function () {
		replaceAnchorLinks();
		
	});
	
$(".hiba").fadeOut(8000);
});

