var searchForm, sendForm, loadPage;
var hidePageTime = 300;// 500;
var showPageTime = 400;// 500;
var DW_DOCUMENT_HASH = '';

$(document).ready(function() {
	$('.bottommenu11').css("background","transparent url(images/bottom2.png) center top repeat-x");
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
	$.browser.safari = /webkit/.test( navigator.userAgent.toLowerCase());

	if($.browser.chrome||$.browser.safari)$("textarea").css("resize","none");
	
	function initAnchors(selector) {
		// $('.tr1, .tr2').hover(function(){
		// $(this).addClass('trhover');},function(){
		// $(this).removeClass('trhover');});
		$(".iconed a[href$='.pdf']").addClass("pdf");
		$(".iconed a[href$='.doc'], a[href$='.txt'], a[href$='.rft']")
				.addClass("txt");
		$(".iconed a[href$='.zip'], a[href$='.rar']").addClass("zip");
		$(".iconed a[href^='mailto:']").addClass("email");
		$('.iconed a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).addClass("external");

		$(selector).each(function() {
			if ($(this).hasClass("ajax")) {
				if (!$(this).data('ajaxurl'))
					$(this).data('ajaxurl', this.href);
				this.href = 'javascript:;';
				//this.href='javascript:void("'+this.href+'");';
			}
		});

		$(selector).click(
				function() {
					if (this.rel == 'sh' || !$(this).hasClass("ajax")) {
						return true;
					}
					var t = $(this).data('ajaxurl').replace(
							document.getElementsByTagName('base')[0].href,
							'');
					loadPage(t,{});
					
					this.blur();
					return false;
				});

	}

	initAnchors('a');
	
	// # eseten a megfelelo oldalt tolti be


	window.setInterval(function() {
		if (DW_DOCUMENT_HASH != document.location.hash) {
			DW_DOCUMENT_HASH = document.location.hash;
			if (document.location.hash.length > 1 || document.location.hash == '' || document.location.hash == '#') {
				if (document.location.hash.length > 1) { t = document.location.hash; } else { t = 'index.php'; }
				t = t.replace('#', '');
				
				loadPage(t,{});
				
			}
		}
	}, 750);


	loadPage = function(t,attr){
		$('.bottommenu').css('display','none');
		
		if($.browser.msie)$('#ajaxbody').hide(hidePageTime,function(){
			loadPagePre();
			$.get(t, attr, function(data) {
				document.title = data.substring(data.indexOf('<title')+7, data.lastIndexOf('title>')-2);
				data = data.substring(data.indexOf('<body'), data.lastIndexOf('body>'))+"body>";
				var tmpclass = "clsclaass"+ Math.floor(Math.random() * 1100000);
				$('#ajaxbody').addClass(tmpclass).html($(data).filter('#ajaxbody').html());
				$('#btcontent').addClass(tmpclass).html($(data).find('#btcontent').html());
				document.location.hash = t.replace(document
						.getElementsByTagName('base')[0].href, '');
				DW_DOCUMENT_HASH = document.location.hash;
				$(document).ready(function() {
					initAnchors('.' + tmpclass + ' a');
				});
				shbox.changeAnchors();
				$.scrollTo(0, 10);
				loadPagePost();
				$('#ajaxbody').show(showPageTime,function(){})
			});
		});
		
		if(!$.browser.msie)$('#ajaxbody').animate({opacity:0.0},hidePageTime,function(){
			loadPagePre();
			$.get(t, attr, function(data) {
				document.title = data.substring(data.indexOf('<title')+7, data.lastIndexOf('title>')-2);
				data = data.substring(data.indexOf('<body'), data.lastIndexOf('body>'))+"body>";
				var tmpclass = "clsclaass"+ Math.floor(Math.random() * 1100000);
				$('#ajaxbody').addClass(tmpclass).html($(data).filter('#ajaxbody').html());
				$('#btcontent').addClass(tmpclass).html($(data).find('#btcontent').html());
				document.location.hash = t.replace(document
						.getElementsByTagName('base')[0].href, '');
				DW_DOCUMENT_HASH = document.location.hash;
				$(document).ready(function() {
					initAnchors('.' + tmpclass + ' a');
				});
				shbox.changeAnchors();
				$.scrollTo(0, 10);
				loadPagePost();
				$('#ajaxbody').animate({opacity:1.0},showPageTime,function(){})
			});
		});
		
		$('.bottommenu11').css("background","transparent url(images/bottom2.png) center top repeat-x");
	}
	
	loadPagePre = function(){
		//$('#ajaxshader').css({display:'block',opacity:0.0});
		//$('#ajaxshader').animate({opacity:1.0},showPageTime);
	}
	loadPagePost = function(){
		if($.browser.msie&&$.browser.version>6)$('#ajaxbody').css('display','table');
		$('#ajaxshader').animate({opacity:0.0},hidePageTime,function(){$(this).css({display:'none'});$('.bottommenu').css('display','block');});
	}
	$('#ajaxshader').ajaxError(function(){
		alert('Opps This request returned null.');
		if($.browser.msie&&$.browser.version>6)$('#ajaxbody').css('display','table');
		$('#ajaxshader').animate({opacity:0.0},hidePageTime,function(){$(this).css({display:'none'});$('.bottommenu').css('display','block');});
		if(!$.browser.msie)$('#ajaxbody').animate({opacity:1.0},showPageTime,function(){})
		if($.browser.msie)$('#ajaxbody').show(showPageTime,function(){})
	})
	
	if($.browser.msie)window.setInterval(function(){$('#ajaxshader').css('top',$(window).scrollTop()+"px");},10);
	if($.browser.msie&&$.browser.version>6)window.setInterval(function(){$('#ajaxbody').css('display','table');},100);
	if(!$.browser.msie){$('#ajaxshader').css('position','fixed');}
});

	// elkuld egy formot a fajlfeltoltest nem tamogatja csak a szoveges
	// tartalmakat
	sendForm = function(resultdivid, formselectorid, bakcendurl, lang) {
		var dataToSendToBackend = {};
		$('#' + formselectorid + ' input,' + '#' + formselectorid+ ' select,' + '#' + formselectorid + ' textarea')
				.each(function() {
					dataToSendToBackend[this.name] = $(this).val();
					if ($(this).attr('type') == 'checkbox') {
						if ($(this).attr('checked') + '' == 'true') {
							dataToSendToBackend[this.name] = 'igen';
						} else {
							dataToSendToBackend[this.name] = 'nem';
						}
					}
				});
		dataToSendToBackend.lang = lang;
		dataToSendToBackend.formselectorid = formselectorid;
		$('#' + resultdivid).load(bakcendurl, dataToSendToBackend,	function() {});
		return false;
	};

	searchForm = function(t) {
		loadPage('search.php',{ scr : t, ajax : 'true'});
	}
	

function collapse(img) {
	id = img.id.split("_")[2];
	if (img.src.indexOf('plus') > 0) {
		img.src = "images/minus.jpg";
		document.getElementById('sub_menus_' + id).style.display = "block";
	} else {
		img.src = "images/plus.jpg";
		document.getElementById('sub_menus_' + id).style.display = "none";
	}
}


BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "<table style='font-size:28px' class='fontmpi' "+">"+"<"+"tr"+">"+"<"+"td width='61' style='padding-left:21px;' "+">"+"%%D%%"+"<"+"/td"+">"+"<"+"td width='45' "+">"+"%%H%%"+"<"+"/td"+">"+"<"+"td width='45' "+">"+"%%M%%"+"<"+"/"+"td"+">"+"<"+"td  width='45' "+">"+"%%S%%"+"<"+"/"+"td>"+"<"+"/"+"tr>"+"<"+"/"+"table"+"> ";
FinishMessage = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size:28px' class='fontmpi >VÉGE!</span>";
var TIMERTIMERTIMER;


function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
	//if(s=="NaN") s ='';
  return "<b>" + s + "<"+"/b>";
}

function CountBack(secs) {
  if (secs < 0) {
    $(".cntdwn").html(FinishMessage); 
    return;
  }
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  $(".cntdwn").html(DisplayStr); 
  if(TIMERTIMERTIMER)window.clearTimeout(TIMERTIMERTIMER);
  if (CountActive)
   TIMERTIMERTIMER = setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}



