var onLoadMethods=new Array(setSwitcherBorders,setContentHeight,setFFMarquee);

function onResizer() {
	if (onLoadMethods) {
		for(var i=0;i<onLoadMethods.length;i++) {
			var func = onLoadMethods[i];
			func();
		}
	}
}
function onLoader() {
	onResizer();
}


function setFFMarquee() {
	if (typeof populate!="undefined" && isShownObj('ffmarquee')) {
		populate();
	}
} 

function setContentHeight() {
	var obj1=getObjfromIdorObj('mainframe-content-switcher');
	var obj2=getObjfromIdorObj('mainframe-content-content');
	if (obj1 && obj2 && obj1.offsetHeight>obj2.offsetHeight) {
		obj2.style.height=parseInt(obj1.offsetHeight)+"px";
	}
}

function setSwitcherBorders() {
	var switcher1=new Object();
	switcher1.button=getObjfromIdorObj('button[container]1');
	switcher1.content=getObjfromIdorObj('content[container]1');
	switcher1.buttons=switcher1.button.getElementsByTagName('h2');
	switcher1.buttonwidth=0;
	for (var i=0;i<switcher1.buttons.length;i++) {
		switcher1.buttonwidth+=parseInt( switcher1.buttons[i].offsetWidth );
	}
	switcher1.gap=parseInt(switcher1.content.offsetWidth) - parseInt(switcher1.buttonwidth);
	if (switcher1.gap>0) {
		switcher1.links=switcher1.buttons[i-1].getElementsByTagName('a');
		switcher1.lastlink=switcher1.links[0];
		switcher1.lastlink.style.paddingRight=7+switcher1.gap+"px";
	}
	
	var switcher1=new Object();
	switcher1.button=getObjfromIdorObj('button[container]2');
	switcher1.content=getObjfromIdorObj('content[container]2');
	if (switcher1.button && switcher1.content) {
		switcher1.buttons=switcher1.button.getElementsByTagName('h2');
		switcher1.buttonwidth=0;
		for (var i=0;i<switcher1.buttons.length;i++) {
			switcher1.buttonwidth+=parseInt( switcher1.buttons[i].offsetWidth );
		}
		switcher1.gap=parseInt(switcher1.content.offsetWidth) - parseInt(switcher1.buttonwidth);
		if (switcher1.gap>0) {
			switcher1.links=switcher1.buttons[i-1].getElementsByTagName('a');
			switcher1.lastlink=switcher1.links[0];
			switcher1.lastlink.style.paddingRight=7+switcher1.gap+"px";
		}
	}
}

var random_header_pictures=new Array();
var random_header_picture_index=0;
function randomHeaderImages() {
	clearTimeout(window.random_header_pictures_timeout);
	if (random_header_pictures.length) {
		if (!window.random_header_pictures_preloaded)preloadImages(random_header_pictures);
		else {
			var obj=getObjfromIdorObj('random-header-row');
			obj.className=random_header_pictures[random_header_picture_index];
			if (random_header_picture_index<random_header_pictures.length-1)random_header_picture_index++;
			else random_header_picture_index=0;
		}
	}
	window.random_header_pictures_timeout=setTimeout("randomHeaderImages()",5000);
}

function preloadImages(images) {
	var doc=document;
	if (!doc.preloadedImages) doc.preloadedImages=new Array();
	for (var i=0;i<images.length;i++) {
		doc.preloadedImages[i]=new Image;
		doc.preloadedImages[i].src="design/images/fejlec/fejlec_02_02_"+images[i].replace(/headerstyle\-/g,"")+".jpg";
	}
	window.random_header_pictures_preloaded=true;
}

function reAlignMapObjects() {
	var outer=getObjfromIdorObj("terkep");
	var inner=getObjfromIdorObj("map");
	var difference=new Object();
	if (outer && inner) {
		var pos=getAnchorPosition({tagid:'terkep'});
		
		//left állítása
		pos.x+=50;//balmargó miatt ez kellhet
		difference.x=inner.offsetLeft-pos.x;
		inner.style.left=parseInt(pos.x)+"px";
		inner.left=parseInt(pos.x)+"px";
		

		//top állítása
		pos.y+=130;//topmargó miatt ez kellhet
		difference.y=inner.offsetTop-pos.y;
		inner.style.top=parseInt(pos.y)+"px";
		inner.top=parseInt(pos.y)+"px";
		showObj(inner);

		var objects=outer.getElementsByTagName('div');
		for (var i=0;i<objects.length;i++) {
			if (objects[i]!=inner) {
/**/
				//left
 				objects[i].style.left=parseInt(objects[i].offsetLeft-difference.x)+"px";
				objects[i].left=parseInt(objects[i].offsetLeft-difference.x)+"px";
				objects[i].style.marginLeft="0px";
				//top
				objects[i].style.top=parseInt(objects[i].offsetTop-difference.y)+"px";
				objects[i].top=parseInt(objects[i].offsetTop-difference.y)+"px";
				objects[i].style.marginTop="0px";
				showObj(objects[i]);
/**/
			}
		}
	}
}

function showMapOverlib(obj) {	
    var obj=getObjfromIdorObj(obj);
	overlib(getMapObjectHTML(obj.id), BGCLASS, 'overdiv-bg', FGCLASS, 'overdiv-text', FIXX, getMapObjectLeft(obj), FIXY, getMapObjectTop(obj));
}

function getMapObjectHTML(obj) {
    var obj=getObjfromIdorObj(obj);
	if (obj && obj.id){
		var html=getInnerHTML(obj.id+"content");
		if (!html)return "";
		html=html.replace(/[\r\n]/g,"");
		return html;
	}
}
function getMapObjectTop(obj) {
    var obj=getObjfromIdorObj(obj);
    if (obj)return obj.offsetTop;
     
}
function getMapObjectLeft(obj) {
    var obj=getObjfromIdorObj(obj);
    if (obj)return obj.offsetLeft+obj.offsetWidth; 
}



function bakonyCalendarIncDay() {
	var fromdate=getValue('fromdate');
	var fromdateArray=fromdate.match(/^([\d]{2,4})\-([\d]{1,2})\-([\d]{1,2})/);
	var date=new Date(fromdateArray[1],fromdateArray[2]-1,fromdateArray[3]);
	
	if (date) {
		date.setTime( date.getTime()+24*60*60*1000 );
		refreshEventCalendar('fromdate='+getDateString(date));
	}
}
function bakonyCalendarDecDay() {
	var fromdate=getValue('fromdate');
	var fromdateArray=fromdate.match(/^([\d]{2,4})\-([\d]{1,2})\-([\d]{1,2})/);
	var date=new Date(fromdateArray[1],fromdateArray[2]-1,fromdateArray[3]);
	
	if (date) {
		date.setTime( date.getTime()-24*60*60*1000 );
		refreshEventCalendar('fromdate='+getDateString(date));
	}
}
function bakonyCalendarSetDay(calendar, date) {
	 if (calendar.dateClicked) {
	    calendar.callCloseHandler(); // this calls "onClose" (see above)
	  }

	var fromdateArray=date.match(/^([\d]{2,4})\-([\d]{1,2})\-([\d]{1,2})/);
	var date=new Date(fromdateArray[1],fromdateArray[2]-1,fromdateArray[3]);

   	refreshEventCalendar("fromdate="+getDateString(date));
}
function refreshEventCalendar(PostData) {
 	PostData="action=refreshCalendar&"+PostData;

	var opts = {
		method: 'post',
		postBody:PostData,
		onSuccess: function(t) {
		},
		on404: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		},
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}
	new Ajax.Updater('calendar-rows', _site_url+'ajax.php', opts);
	return false;
} 

function MyCalendarSetup() {
	if (getObjfromIdorObj('calendar_button_date')) {
	Calendar.setup({
		inputField     :    "calendar_button_date",   // id of the input field
		ifFormat       :    "%Y-%m-%d %H:%M",       // format of the input field
		showsTime      :    false,
		timeFormat     :    "24",
		onSelect       :    bakonyCalendarSetDay
	});
	}
}


function detImageSizeWithRate(W,H,maxwidth,maxheight) {
		var newW,newH,resized;
		if (W>maxwidth && H>maxheight) {//mindkettő nagyobb
			if (W<H) {//álló
				newH=maxheight;
				newW=(maxheight/H)*W;
				resized=1;
			} else {//fekvő
				newW=maxwidth;
				newH=(maxwidth/W)*H;
				resized=1;
			}
		} else if (W>maxwidth && H<=maxheight) {//szélesebb
				newW=maxwidth;
				newH=(maxwidth/W)*H;
				resized=1;
		} else if (W<=maxwidth && H>maxheight) {//magasabb
				newH=maxheight;
				newW=(maxheight/H)*W;
				resized=1;
		} else {
				newW=W;
				newH=H;
				resized=0;
		}
		var picSizes=new Object();
		picSizes.x=newW;
		picSizes.W=newW;
		picSizes.y=newH;
		picSizes.H=newH;
		picSizes.resized=resized;
		return picSizes;
}
function setAllImageSize (maxWidth,maxHeight) {
	for (var i=0;i<document.images.length;i++) {
		if (document.images[i].name.match(/(imagelist-img)+/) && (document.images[i].height>maxWidth || document.images[i].width>maxHeight)) {
			var W=document.images[i].width,H=document.images[i].height,newW,newH;
			var sizes=detImageSizeWithRate(W,H,maxWidth,maxHeight);
			document.images[i].style.width=sizes.W;
			document.images[i].style.height=sizes.H;
			document.images[i].width=sizes.W;
			document.images[i].height=sizes.H;
		}
	}
}
function setImageSize(id,maxwidth,maxheight,withoutsizecheck) {
	var oldPicSizes=new Object(),resized;
	if (document.getElementById(id) && withoutsizecheck==1)  {
		var W=document.getElementById(id).width,H=document.getElementById(id).height;
		document.getElementById(id).style.width=maxwidth;
		document.getElementById(id).style.height=maxheight;
		document.getElementById(id).width=maxwidth;
		document.getElementById(id).height=maxheight;
		resized=1;
	} else if (document.getElementById(id) && (document.getElementById(id).height>maxheight || document.getElementById(id).width>maxwidth)) {
		var W=document.getElementById(id).width,H=document.getElementById(id).height,newW,newH;
		var sizes=detImageSizeWithRate(W,H,maxwidth,maxheight);
		document.getElementById(id).style.width=sizes.W;
		document.getElementById(id).style.height=sizes.H;
		document.getElementById(id).width=sizes.W;
		document.getElementById(id).height=sizes.H;
		var oldPicSizes=new Object();
		resized=sizes.resized;
	}
	oldPicSizes.x=W;
	oldPicSizes.W=W;
	oldPicSizes.y=H;
	oldPicSizes.H=H;
	oldPicSizes.resized=resized;
	return oldPicSizes;
}
function setAllImageSizeBy(resizeby) {
	for (var i=0;i<document.images.length;i++) {
		if (document.images[i].name=="imagelist-img" && ((document.images[i].height>32 && resizeby<0) || (document.images[i].height<100 && resizeby>0))) {
			var H=document.images[i].height;
			document.images[i].style.height=H+resizeby;
			document.images[i].height=H+resizeby;
		}
	}
}




