/****************
-------------fő funkció hash-el való kezelése------------------------------
****************/
var cel="";
var regi_class="";
var regi_menu="";


$(document).ready(function(){
		
		cel=location.hash;
		if(cel==""){
			cel="#kezdolap"
		}
		
		$('div#betoltes_jel').css("display","block");
		$.post('data.php',{cel:cel },
		function(output){
				$('.right').html(output).show();
				$('div#betoltes_jel').css("display","none");
				CB_Init(); //clearbox újrahívásához kell
				menubeallit();
				sliderBox_adatok();
			});
});

function ugras(cel){
		var jelenlegi_cel=location.hash;
		if(jelenlegi_cel=="#"+cel){
			frissites();			
		}else{
			window.location.hash = "#"+cel;
		}
}
	
$(window).hashchange( function(){
		
		$('div#betoltes_jel').css("display","block");
		cel=location.hash;
		
		$.post('data.php',{cel:cel },
		function(output){
				$('.right').html(output).show();
				$('div#betoltes_jel').css("display","none");
				CB_Init(); //clearbox újrahívásához kell
				menubeallit();
				sliderBox_adatok();
			});

	})
//------------------------------------------------------
//aktuális oldal frisitése
function frissites(){
		cel=location.hash;
		
		$.post('data.php',{cel:cel },
		function(output){
				$('.right').html(output).show();
				$('div#betoltes_jel').css("display","none");
				CB_Init(); //clearbox újrahívásához kell
				menubeallit();
				sliderBox_adatok();
			});
}


/***************
------------- további fügyvények----------------
***************/

function menubeallit(){
var lepes1=cel.split("#");
var lepes2=lepes1[1].split("/");
var act_menu_nev=""+lepes2[0];

if(cel=="" || act_menu_nev==""){
	act_menu_nev="kezdolap"
}


//$("a[href='#"+act_menu_nev+"']").removeClass();
$("#btn_"+act_menu_nev+"").toggleClass("menu_elem_benyomva"); 

$("#btn_"+regi_menu+"").toggleClass("menu_elem_benyomva");

regi_menu=act_menu_nev;
//regi_class=$("#btn_"+act_menu_nev+"").attr("class");
$("#btn_"+regi_menu+"").onmouseup = $("#btn_"+regi_menu+"").blur();
}

/****************
---------------VENDÉGKÖNYV---------------
****************/
nyitva=0;
			
function display() {
	if(nyitva==0){
		document.getElementById('leveliras').style.display = '';
		nyitva=1;
	}else{
		document.getElementById('leveliras').style.display = 'none';
		nyitva=0;
	}		
}

function vendegkonyvbejegyzes(){
	var nev=document.forms["vendegkonyv_form"]["name"].value;
	var uzenet=document.forms["vendegkonyv_form"]["opinion"].value;
	var error="";
	
	if (nev==null || nev=="" || nev.length<2)
  	{
  		error+="Kérem adja meg a nevét!<br/>";
  	}
	if(uzenet==null || uzenet=="" || uzenet.length<2){
		error+="Az üzenet üres!<br/>"
	}
	if(error!=""){
		//volt hiba
		$('#opinion_error').html(error);
	}else{
		//nem volt hiba küldjük a hozzászolást
		
		$('#opinion_error').html("");
		$.post('tartalom/vendegkonyv_feldolgozo.php',{nev:nev,
							uzenet:uzenet
						},
		function(output){
			$('div#betoltes_jel').css("display","none");
			if(output==""){
				//sikeres sql írás
				$('#opinion_error').html("Köszönjük bejegyzését! Bejegyzése ellenőrzés után fog megjelenni.");
				$('input:text[name=opinion_name]').val("");
				$('textarea#opinion').val("");
			}else{
				//hiba kiírása
				$('#opinion_error').html(output);				
			}
			
			});
	}//else end
	  
}//function end

/***********************
Sliderbox
**************************/
var top_max=0; 
var kesz=0;
window.onresize = function(event) { 
    sliderBox_adatok();
} 


function sliderBox_adatok(){
	top_max=$(document).height()-$(window).height(); 
}


window.onscroll = function()
{
	top_ertek=265+document.documentElement.scrollTop;
	var footer_position = $("div#footer").offset();
	var SliderBox_position = $("div#SliderBox").offset();
	//top_max=$(document).height()-$(window).height(); 
	
	
	
	
	
	//alert("top_max= "+top_max+"  // elrejett= "+document.documentElement.scrollTop+" top ertek: "+top_ertek);
	//alert("footer: "+footer_position.top+"SliderBox_position: "+SliderBox_position.top);
	//if(top_max>=document.documentElement.scrollTop){
		
		if((footer_position.top-285)<=top_ertek){		//285 sliderBox height
				top_ertek=footer_position.top-285;		//285 sliderBox height
			}else{
							
			}
		
		scroll_anim();
		
	//}
		
	
}


function scroll_anim(){
		$("div#SliderBox").animate({top:''+top_ertek+'px'},10,function() { kesz=1;});
	
}
