$(document).ready(function() {

	var animateElement = 'html,body,document';
	
	//var browser = $.browser;
	//if (browser.safari==true) animateElement = 'body';
	
	//alap adatok
	var fullWidth = $(window).width();
	var fullHeight = $(window).height();
	var boxWidth = $('.box').width();
	var boxHeight = $('.box').height();
	
	//gorgeto sav eltuntetese kis felbotnasban
	if (fullWidth<1200) {
		var arrowWidth = $('.box_arrow').width();
		$('.box_arrow').remove();
		boxWidth -= arrowWidth;
		$('.box').width(boxWidth);
	}
	
	//boxok kozepre helyezese -> megoldva CSS-el
	//var boxMarginWidth = (fullWidth-boxWidth)/2;
	//$('.box').css('margin-left', boxMarginWidth);
	
	//header
	if (fullWidth<1200) {
		var headerWidth = boxWidth+20;
		$('#header').width((headerWidth<fullWidth?fullWidth:headerWidth));
		if (headerWidth>fullWidth) {
			$(window).scroll(function() {
				var headerLeft = ($(window).scrollLeft()*(-1));
				$('#header').css('left', headerLeft);
			});
		}
	} else {
		$('#header ul').css('margin-left', ((fullWidth-$('#header ul').width())/2)-($('#header span').width()+10));
	}
	
	//boxok 1 oldalassa tetelet
	var jump = 0; var boxMarginHeight = 0;
	if (boxHeight<fullHeight) {
		boxMarginHeight = (fullHeight-boxHeight)/2;
		jump = boxHeight+boxMarginHeight;
		$('.box').css('margin-bottom', boxMarginHeight).css('margin-top', boxMarginHeight);
	} else {
		boxMarginHeight = 45;
		jump = boxHeight+boxMarginHeight;
		$('.box').css('margin-bottom', boxMarginHeight).css('margin-top', boxMarginHeight);
	}
	
	//top pic
	$('#top_pics').css('top', (boxMarginHeight*(-1))+20);
	/*$('#image_map area').mouseover(function() {
		var img = "images/index/"+$(this).attr('rel')+".png";
		
		//$('#top_pics').append($('img'));
	});*/
	
	jump = Math.round(jump);
	
	//lapozas le
	$('.arrow_bottom').click(function() {
		var scrollTop = $(window).scrollTop();
		var jumpTop = scrollTop%jump;
		if (jumpTop==scrollTop) jumpTop=0;
		//alert(scrollTop+" "+jumpTop+" "+jump+" "+(scrollTop+(jump-jumpTop)));
		//$(window).scrollTop(scrollTop+(jump-jumpTop));
		$(animateElement).animate({scrollTop: (scrollTop+(jump-jumpTop))}, 600);
	});
	//lapozas fel
	$('.arrow_top').click(function() {
		var scrollTop = $(window).scrollTop();
		var jumpTop = scrollTop%jump;
		//if (jumpTop==scrollTop) jumpTop=0;
		//alert(scrollTop+" "+jumpTop+" "+jump+" "+(scrollTop+(jump-jumpTop)));
		//$(window).scrollTop(scrollTop-(jump-jumpTop));
		$(animateElement).animate({scrollTop: (scrollTop-jump)}, 600);
	});
	//ugras
	$('.box_arrow ul li').click(function() {
		if ($(this).hasClass('active')) return false;
		else {
			var pos = $('#'+$(this).attr('class').replace('jump_','')).position();
			//$(window).scrollTop(pos.top+boxMarginHeight);
			$(animateElement).animate({scrollTop: (pos.top+boxMarginHeight)}, 600);
		}
	});
	
	//alap oldal betoltes
	$(window).scrollTop($(document).height());
	$(animateElement).animate({scrollTop: 0}, 1500);
});
