//header functions
function initHeader() {
	document.getElements('.nav_hover').each(function(btn) {
		btn.setStyle('opacity','0');
	});
	document.getElements('.nav_hover').each(function(btn) {
		btn.set('tween',{duration:150, onComplete:function(btn) {btn.setStyle('visibility','visible')}});
		btn.setStyle('visibility','visible');
		btn.onmouseover = function() {
			$(this).get('tween').cancel();
			$(this).tween('opacity',1);
		}
		btn.onmouseout = function() {
			$(this).get('tween').cancel();
			$(this).tween('opacity',0);
		}
	});
}


//intro functions
function initIntro() {
	intro = {actIntroSlide:0, contentsTween:'', arrowsTween:'', bgTween:'', bubbleTween:''};
	$('left_intro_arrowleft').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('left_intro_arrowleft').onmouseover = function() {this.tween("left",0)}
	$('left_intro_arrowleft').onmouseout = function() {this.tween("left",5)}
	$('left_intro_arrowleft').onclick = function() {showIntro(intro.actIntroSlide - 1 > 0 ? intro.actIntroSlide - 1 : $('left_intro_contents').getElements('div.left_intro_content').length)}
	$('left_intro_arrowright').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('left_intro_arrowright').onmouseover = function() {this.tween("right",0)}
	$('left_intro_arrowright').onmouseout = function() {this.tween("right",5)}
	$('left_intro_arrowright').onclick = function() {showIntro(intro.actIntroSlide + 1 > $('left_intro_contents').getElements('div.left_intro_content').length ? 1 : intro.actIntroSlide + 1)}
	showIntro(1);
}	

function loadIntroImage(num) {
	if ($defined($("intro_image_"+num))) {
		$("intro_image_"+num).inject('left_intro_images');
		new Fx.Tween($("intro_image_"+num)).set('opacity', 0);
		$("intro_image_"+num).tween('opacity', 1);
	} else {
		var div = new Element('div');
		div.inject('left_intro_images');
		var s = $('left_intro_contents').getElements('div.left_intro_content')[num-1];
		var imgsrc = s.getElement('div.imgsrc').get('text');
		var myImage = new Asset.image('/includes/phpThumb/phpThumb.php?w=620&h=350&zc=1&q=90&fltr[]=usm|80|0.5|2&src=../../upload/bevezeto/'+imgsrc, { 
  			onload: function() {
  				div.set("id","intro_image_"+num);
  				div.addClass("left_intro_image");
  				this.inject(div);
  				new Fx.Tween(div).set('opacity', 0);
  				div.tween('opacity', 1);
 			} 
		});
	}
}

function showIntro(num) {
	var s = $('left_intro_contents').getElements('div.left_intro_content')[num-1];
	
	if (intro.contentsTween != '') intro.contentsTween.cancel();
	intro.contentsTween = new Fx.Morph($('left_intro_contents'), {transition: Fx.Transitions.Quart.easeOut, duration: 500 });
	intro.contentsTween.start({ "left":-s.offsetLeft.toInt(), "height":s.offsetHeight.toInt() });
	
	if (intro.bgTween != '') intro.bgTween.cancel();		
	intro.bgTween = new Fx.Tween($('left_intro_bg'), { transition: Fx.Transitions.Quart.easeOut, duration: 500 });
	intro.bgTween.start("height",315+s.offsetHeight.toInt());
	
	if (intro.bubbleTween != '') intro.bubbleTween.cancel();
	intro.bubbleTween = new Fx.Morph($('left_intro_bubble'), {  transition: Fx.Transitions.Quart.easeOut, duration: 500 });
	intro.bubbleTween.start({ "top":314+s.offsetHeight.toInt(), "left":(((num-1)%4)*155)+105 });
	
	if (intro.arrowsTween != '') intro.arrowsTween.cancel();
	intro.arrowsTween = new Fx.Tween($('left_intro_arrows'), { transition: Fx.Transitions.Quart.easeOut, duration: 500 });
	intro.arrowsTween.start("margin-top",70+Math.round(s.offsetHeight.toInt()/2));
	
	loadIntroImage(num);
	intro.actIntroSlide = num;
}



//menu functions
function initMenu() {
	menu = {actMenuItem:'undefined', actMenuContent:'undefined', menuSlider : 'undefined'};
	$('right_menu_container').getElements('div.menucontent').each(function(mc) { mc.set('opacity',0); });
	$('right_menu_tabs').getElement('a').onclick();
}

function showMenu(obj) {
	if (menu.actMenuItem == obj) return;
	var ext;
	if (menu.actMenuItem != "undefined") {
		ext = menu.actMenuItem.getElement("img").get('src').substr(menu.actMenuItem.getElement("img").get('src').lastIndexOf(".")+1);
		menu.actMenuItem.getElement("img").set("src", "/images/"+menu.actMenuItem.get('id')+"."+ext);
	}
	var img = obj.getElement("img");
	var src = obj.get("id");
	ext = img.get('src').substr(img.get('src').lastIndexOf(".")+1);
	img.set("src", "/images/"+src+"_selected."+ext);
	menu.actMenuItem = obj;
	var ida = obj.get('id').split("_");
	showMenuContent(ida[ida.length-1]);
}

function showMenuContent(id) {
	if (menu.actMenuContent != "undefined") {
		menu.actMenuContent.tween('opacity', 0);
		menu.actMenuContent.removeEvent('mousewheel');
	}
	menu.actMenuContent = $('menucontent_'+id);
	menu.actMenuContent.tween('opacity', 1);
	if (menu.actMenuContent.offsetHeight.toInt() > $('right_menu_container').getStyle('height').toInt() - 20) {
		$('right_menu_scrollbarbg').setStyle('visibility','visible');
		menu.actMenuContent.setStyle("top",0);
		$('right_menu_scrollbar').setStyle("top",0);
		initScroll($('right_menu_container').getStyle('height').toInt() + 20, menu.actMenuContent, $('right_menu_scrollbarct'), $('right_menu_scrollbar'));
	} else {
		$('right_menu_scrollbarbg').setStyle('visibility','hidden');
	}
}



//mesageboard functions
function initMsgb() {
	msgb = { actItem: 0, contentsTween:"", arrowsTween:"", maxChars:300, loadedItems:0};
	$('messageboard_arrowleft').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('messageboard_arrowleft').onmouseover = function() {this.tween("left",-2)}
	$('messageboard_arrowleft').onmouseout = function() {this.tween("left",3)}
	$('messageboard_arrowleft').onclick = function() {showMsgbItem(msgb.actItem - 1 > 0 ? msgb.actItem - 1 : 0)}
	
	$('messageboard_arrowright').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('messageboard_arrowright').onmouseover = function() {this.tween("right",-2)}
	$('messageboard_arrowright').onmouseout = function() {this.tween("right",3)}
	$('messageboard_arrowright').onclick = function() {
		showMsgbItem(msgb.actItem + 1 < msgb.loadedItems - 3 ? msgb.actItem + 1 : msgb.actItem);
		if (msgb.actItem == msgb.loadedItems - 4 && loading == false) {
			loadMsgbItems(msgb.actItem);
		}
	}
	
	$('messageboard_msgpanel').getElement('textarea').onkeypress = this.charCounter;
	$('messageboard_msgpanel').getElement('textarea').onkeyup = this.charCounter; //ie hack
	
	loadMsgbItems(0);
}

function loadMsgbItems(from) {
	loading = true;
	var req = new Request.HTML({ 
		url: 'msgb_getmessages.php?rnd='+Math.round(Math.random()*1000000000),
		method: 'post',
		onSuccess: function(res) {
			loading = false;				
			if (from == 0) {
				$('messageboard').getElement('.messages').empty();
				$('messageboard').getElement('.messages').adopt(res);
				$('messageboard').getElement('.messages').setStyle('left',0);
			} else {
				$('messageboard').getElement('.messages').adopt(res);
			}
			
			msgb.loadedItems = $('messageboard').getElements('.message').length;
			
			$('messageboard').getElement('.messages').setStyle('width',msgb.loadedItems*235);
			var mbHeight = $('messageboard').getElement('.messages').offsetHeight;
			if (mbHeight < 170) mbHeight = 170;
			$('messageboard').getElement('.messages').setStyle('height',mbHeight);
			$('messageboard').getElement('.container').setStyle('height',mbHeight+25);
			$('messageboard').getElements('.message').each(function(m){
				m.setStyle("height",$('messageboard').getElement('.messages').offsetHeight);
			});
			
			$('messageboard_arrows').get('tween').cancel();
			$('messageboard_arrows').set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 200});
			$('messageboard_arrows').tween("margin-top",$('messageboard').offsetHeight.toInt()/2+10);
			$('messageboard_arrows').setStyle("visibility","visible");
		},
		onFailure: function(e) {
			loading = false;
			ShowMessage('Szerver hiba','#a34b1b');
		}
	}); 
	req.send('from='+from);
}

function showMsgbItem(num) {
	var s = $('messageboard').getElements('.message')[num];
	if (msgb.contentsTween != "") msgb.contentsTween.cancel();
	msgb.contentsTween = new Fx.Morph($('messageboard').getElement('.messages'), { transition: Fx.Transitions.Quart.easeOut, duration: 400 });
	msgb.contentsTween.start({ "left":-s.offsetLeft.toInt() });
	msgb.actItem = num;
}

function charCounter() {
	var ta = $('messageboard_msgpanel').getElement('textarea');
	if (ta.value.length > msgb.maxChars) {
		ta.value = ta.value.substring(0, msgb.maxChars);
	} else {
		$('messageboard_msgpanel').getElement('span.counter').set('text', '('+msgb.maxChars+'/' + ta.value.length + ' karakter)');
	}
}

function showMsgPanel() {
	hideActPanel();
	actPanel = $('messageboard_msgpanel');
	charCounter();
	$('messageboard_msgpanel').set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 400});
	$('messageboard_msgpanel').tween('opacity',0,1);
	setTimeout("$('messageboard_msgpanel').getElement('input[name=nick]').focus()",200);
}

function sendMsg() {
	
	if ($('msgb_nick').value != "" && $('msgb_msg').value !="") {
		var req = new Request({ 
		url: 'messagebox'+'_sendmessage.php?rnd='+Math.round(Math.random()*1000000000), 
		method: 'post', 
		onSuccess: function(response) {
			loadMsgbItems(0);	
			$('msgb_nick').value = "";
			$('msgb_msg').value = "";
			hideActPanel();
		}});
		req.send('nick='+$('msgb_nick').value+
		"&msg="+$('msgb_msg').value);
	} else {
		alertMsg("A csillaggal jelAslt mezL?k kitAsltAŠse kAstelezL?!",'#47042d');
	}
}



//gallery functions
function initGallery() {
	gallery = {actX:0, container : '', actImage: '', bgTween:''};
	$('gallery_arrowleft').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('gallery_arrowleft').onmouseover = function() {this.tween("left",2)}
	$('gallery_arrowleft').onmouseout = function() {this.tween("left",7)}
	$('gallery_arrowleft').onclick = function() {
		gallery.container.set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 500});
		gallery.actX = gallery.actX + 440 > 0 ? 0 : gallery.actX + 440;
		gallery.container.tween("left",gallery.actX);
	}
	
	$('gallery_arrowright').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('gallery_arrowright').onmouseover = function() {this.tween("right",3)}
	$('gallery_arrowright').onmouseout = function() {this.tween("right",9)}
	$('gallery_arrowright').onclick = function() {
		gallery.container.set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 500});
		gallery.actX = gallery.actX - 440 < -gallery.container.getStyle('width').toInt() + 440 ? -gallery.container.getStyle('width').toInt() + 440 : gallery.actX - 440;
		gallery.container.tween("left",gallery.actX);
	}
	
	$('gallery_thumbnails_container').getElements('img').each(function(img) {
		img.onclick = function() { loadGalleryImage(this); }
	});
	
	gallery.container = $('gallery_thumbnails_container').getElement('.thumbnails');
	gallery.container.setStyle('left',0);
	gallery.container.tween('opacity',0,1);
	loadGalleryImage();
}
	
function loadGalleryImage(thumb) {
	if (!$defined(thumb)) {
		thumb = gallery.container.getElements('img')[0];
	}
	if (gallery.actImage == thumb) {
		return;
	};
	if (gallery.actImage != "") {
		var n = gallery.actImage.get('alt').split("_")[1];
		$("gallery_image_"+n).get('tween').cancel();
		$("gallery_image_"+n).set('opacity',0);
	}
	gallery.actImage = thumb;
	var num = thumb.get('alt').split("_")[1];
	if ($defined($("gallery_image_"+num))) {
		$("gallery_image_"+num).inject('gallery_images');
		$("gallery_bg").tween('height',$("gallery_image_"+num).offsetHeight.toInt()+ 120);
		$("gallery_image_"+num).set('opacity',0);
		setTimeout(function(){showGalleryImage($("gallery_image_"+num))},500);
	} else {
		var div = new Element('div');
		div.inject('gallery_images');
		
		var imgsrc = thumb.get('src').split("upload/")[1];
		var myImage = new Asset.image('/includes/phpThumb/phpThumb.php?w=440&q=90&fltr[]=usm|90|0.9|1&src=../../upload/'+imgsrc, {
			onload: function() {
					div.set("id","gallery_image_"+num);
					div.addClass('gallery_image');
					this.inject(div);
					div.set('opacity',0);
					$("gallery_bg").tween('height',$("gallery_image_"+num).offsetHeight.toInt()+ 92);
					div.onclick = function() {
				}
				div.setStyle('cursor','pointer');
					setTimeout(function(){showGalleryImage(div)},500);
				}
		});
	}
	gallery.container.getElement(".gallery_selector").set('tween',{duration:500, transition: Fx.Transitions.Quart.easeOut});
	gallery.container.getElement(".gallery_selector").tween("left",thumb.offsetLeft.toInt());
}
	
function showGalleryImage(obj) {
	var n = gallery.actImage.get('alt').split("_")[1];
	if ("gallery_image_"+n == obj.get('id')) obj.tween('opacity', 0, 1);
}



//review functions
function initReviews() {
	var accordion = new Accordion($('reviews_accordion'), 'h3.toggler', 'div.element', {
		opacity: true,
			onActive: function(toggler, element){
			toggler.setStyle('color', '#bc471b');
			element.setStyle('background-color','#f7f4e5');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#56889f');
			element.setStyle('background-color','white')
		}
	});
}



//dictionary functions
function initDictionary() {
	initScroll($('dictionary').getStyle('height').toInt(), $('dict_container'), $('dict_scrollbarct'), $('dict_scrollbar'));
}



//team functions
function initTeam() {
	teamObj = {container: '', containerX: 0, actImage: ''};
	teamObj.container = $('team_members');
	$('team_arrowleft').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('team_arrowleft').onmouseover = function() {this.tween("left",-17)}
	$('team_arrowleft').onmouseout = function() {this.tween("left",-12)}
	$('team_arrowleft').onclick = function() {
		$('team_members').set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 500});
		teamObj.containerX = teamObj.containerX + 920 > 0 ? 0 : teamObj.containerX + 920;
		$('team_members').tween("left",teamObj.containerX);
	}
	$('team_arrowright').set('tween', {duration:200, transition: Fx.Transitions.Quart.easeOut});
	$('team_arrowright').onmouseover = function() {this.tween("right",-17)}
	$('team_arrowright').onmouseout = function() {this.tween("right",-12)}
	$('team_arrowright').onclick = function() {
		$('team_members').set('tween',{transition: Fx.Transitions.Quart.easeOut, duration: 500});
		teamObj.containerX = teamObj.containerX - 920 < -$('team_members').getStyle('width').toInt() + 920 ? -$('team_members').getStyle('width').toInt() + 920 : teamObj.containerX - 920;
		$('team_members').tween("left",teamObj.containerX);
	}
	$('team_members').getElements('img').each(function(img) {
		img.onclick = function() { loadTeamImage(this); }
	});
	$('team_members').setStyle('width',$('team_members').getElements('img').length * 93);
	loadTeamImage();
}
	
function loadTeamImage(thumb) {
	if (!$defined(thumb)) {
		thumb = teamObj.container.getElements('img')[0];
	}
	if (teamObj.actImage == thumb) {
		return;
	} else if (teamObj.actImage != "") {
		var n = teamObj.actImage.get('id').split("_")[2];
		$("team_image_"+n).get('tween').cancel();
		$("team_image_"+n).set('opacity',0);
		$("team_bio_"+n).get('tween').cancel();
		$("team_bio_"+n).set('opacity',0);
	}
	teamObj.actImage = thumb;
	var num = thumb.get('id').split("_")[2];
	if ($defined($("team_image_"+num))) {
		$("team_image_"+num).inject('team_images');
		$("team_image_"+num).set('opacity',0);
		$("team_bios_container").tween('height',$("team_image_"+num).offsetHeight.toInt());
		setTimeout(function() {showTeamImage($("team_image_"+num))},500);
	} else {
		var div = new Element('div');
		div.inject('team_images');
		var imgsrc = thumb.get('src').split("upload/csapat/")[1];
		var image = new Asset.image('/includes/phpThumb/phpThumb.php?w=460&h=698&zc=1&q=90&fltr[]=usm|90|0.9|1&src=../../upload/csapat/'+imgsrc, { 
  			onload: function() {
  				div.set("id","team_image_"+num);
  				div.addClass('team_image');
  				this.inject(div);
  				div.set('opacity',0);
  				$("team_bios_container").tween('height',$("team_image_"+num).offsetHeight.toInt());
  				setTimeout(function(){showTeamImage(div)},500);
 			} 
		});
	}
	$('team_members').getElement(".team_selector").set('tween',{duration:500, transition: Fx.Transitions.Quart.easeOut});
	$('team_members').getElement(".team_selector").tween("left",thumb.offsetLeft.toInt());
}
	
function showTeamImage(obj) {
	var n = teamObj.actImage.get('id').split("_")[2];
	if ("team_image_"+n == obj.get('id')) {
		obj.tween('opacity', 0, 1);
		$('team_bio_'+n).tween('opacity', 0, 1);
	}
}



//reservation functions
function initReservation(){
	$('reservation').set('tween', {duration:300, transition: Fx.Transitions.Quart.easeOut});
}
	
function	showReservation(resdate,restime) {
	hideActPanel();
	actPanel = $('reservation');
	$('reservation').tween('opacity',0,1);
	//alert($('reservation_date').getElement('option[value='+date+']').get('value'));
	$('reservation_date').getElement('option[value='+resdate+']').set('selected','selected');
	$('reservation_time').getElement('option[value='+restime+']').set('selected','selected');
}

function sendReservation() {
	if ($('reservation_name').value != "" && $('reservation_phone').value !="" && $('reservation_email').value !="" && $('reservation_date').value !="" && $('reservation_time').value !="" && $('reservation_person').value !="" && $('reservation_where').value !="" ) {
	var req = new Request({ 
		url: 'reservation'+'_sendmessage.php?rnd='+Math.round(Math.random()*1000000000), 
		method: 'post', 
		onSuccess: function(response) {
			var res = JSON.decode(response);
			if (res.error == 1) {
				alertMsg("A megadott e-mail cA­m hibAAs! EllenL?rizd a megadott cA­m helyessAŠgAŠt!",'#47042d');
				$('reservation').getElement('input[name=email]').focus();
			} else if (res.error == 2) {
				alertMsg("A foglalAAs sorAAn hiba lAŠpett fel. PrAlbAAld Asjra kAŠsL?bb!",'#47042d');
			} else {
				alertMsg("KAsszAsnjAzk a foglalAAst! MunkatAArsunk hamarosan felkeres adategyeztetAŠs cAŠljAAbAll!",'#888b35');
				$('reservation_name').value = "";
				$('reservation_phone').value = "";
				$('reservation_email').value = "";
				$('reservation_date').value = "";
				$('reservation_time').value = "";
				$('reservation_person').value = "";
				$('reservation_where').value = "";
				hideActPanel();
			}
		}});
		req.send('name='+$('reservation_name').value+
		"&phone="+$('reservation_phone').value+
		"&email="+$('reservation_email').value+
		"&date="+$('reservation_date').value+
		"&time="+$('reservation_time').value+
		"&person="+$('reservation_person').value+
		"&where="+$('reservation_where').value);
	} else {
		alertMsg("A csillaggal jelAslt mezL?k kitAsltAŠse kAstelezL?!",'#47042d');
	}
}



//offer functions
function initOffer(){
	$('offer').set('tween', {duration:300, transition: Fx.Transitions.Quart.easeOut});
}
	
function	showOffer() {
	hideActPanel();
	actPanel = $('offer');
	$('offer').tween('opacity',0,1);
}

function sendOffer() {
	if ($('offer_name').value != "" && $('offer_phone').value !="" && $('offer_email').value !="" && $('offer_msg').value !="") {
	var req = new Request({ 
		url: 'offer'+'_sendmessage.php?rnd='+Math.round(Math.random()*1000000000), 
		method: 'post', 
		onSuccess: function(response) {
			var res = JSON.decode(response);
			if (res.error == 1) {
				alertMsg("A megadott e-mail cA­m hibAAs! EllenL?rizd a megadott cA­m helyessAŠgAŠt!",'#47042d');
				$('reservation').getElement('input[name=email]').focus();
			} else if (res.error == 2) {
				alertMsg("Az Azzenet kAzldAŠse sorAAn hiba lAŠpett fel. PrAlbAAld Asjra kAŠsL?bb!",'#47042d');
			} else {
				alertMsg("KAsszAsnjAzk a megkeresAŠst! MunkatAArsunk hamarosan felkeres adategyeztetAŠs cAŠljAAbAll!",'#888b35');
				$('offer_name').value = "";
				$('offer_phone').value = "";
				$('offer_email').value = "";
				$('offer_msg').value = "";
				hideActPanel();
			}
		}});
		req.send('name='+$('offer_name').value+
		"&phone="+$('offer_phone').value+
		"&email="+$('offer_email').value+
		"&msg="+$('offer_msg').value);
	} else {
		alertMsg("A csillaggal jelAslt mezL?k kitAsltAŠse kAstelezL?!",'#47042d');
	}
}




//map functions
function initMap() {
	$('map').set('tween',{duration:300, ease:Fx.Transitions.Quart.easeOut});
	$('map').onmouseout = hideActPanel;
}
function showMap() {
	hideActPanel();
	actPanel = $('map');
	$('map').tween('opacity',0,1); 
}


//popup functions
function turnPage (pageNumber) {
	$$('#events-menu a').removeClass('active');
	$('article-' + pageNumber).addClass('active');
	
	if (typeof(currentPage) != "undefined") {
		$('event-'+currentPage).tween('opacity',0);
		$('event-'+currentPage).getElement('.event-content').removeEvent('mousewheel');
	}
	$('event-'+pageNumber).tween('opacity',1);
	
	if ($('event-'+pageNumber).getElement('.event-content').offsetHeight.toInt() > $('events-container').getStyle('height').toInt()) {
		$('events-scroll').setStyle('visibility','visible');
		$('event-'+pageNumber).setStyle("top",0);
		$('events-scrollbar').setStyle("top",0);
		initScroll($('events-container').getStyle('height').toInt(), $('event-'+pageNumber).getElement('.event-content'), $('events-scrollbarct'), $('events-scrollbar'));
	} else {
		$('events-scroll').setStyle('visibility','hidden');
	}
	
	currentPage = pageNumber;
}

function rotatePages() {
	var num = $('events-menu').getElements('a').length;
	var cp = currentPage < num-1 ? currentPage+1 : 0;
	turnPage(cp);
}

function setIcon(icon) {
	$$('#events-services span, #events-services p').tween('opacity', 0);
	$$('#events-services p').setStyle('display', 'none');
	$$('#events-services-' + icon + ' p').setStyle('display', 'block');
	$$('#events-services-' + icon + ' span, #events-services-' + icon + ' p').tween('opacity', 1);
}

function rotateIcons() {
	currentIcon = currentIcon == 6 ? 1 : currentIcon+1;
	setIcon(currentIcon); 
}

function showEvent(page) {
	$('events').tween('height','405');
	turnPage(page);
}

function initEvents() {
	$$('#events-container .event').setStyle('opacity','0');
	$$('#events-container .event').set('tween', {duration:300});
	$$('#events-menu .menu').each(function(article) { article.onclick = function() { turnPage($(this).get('id').split('-')[1]); clearInterval(rotateInterval);}; });
	turnPage(0);
	rotateInterval = setInterval(rotatePages, 8000);
	
	$$('#events-services span, #events-services p').set('tween', {duration:200});
	$$('#events-services div').each(function(icon) {
		icon.onmouseover = function() {setIcon($(this).get('id').split('-')[2]); clearInterval(iconInterval);};
		icon.onmouseout = function() {clearInterval(iconInterval); iconInterval = setInterval( rotateIcons, 4000)};
	});
	currentIcon = 1;
	setIcon(1);
	iconInterval = setInterval( rotateIcons, 4000 );
	
	$('events-close').onclick = function() {$('events').tween('height','0');};
}



//other functions
function scrollToElement(element,offsetY,offsetX,container) {
	if (offsetY === undefined) offsetY = -110;
	if (offsetX === undefined) offsetX = 0;
	if (container === undefined) container=document.body;
	var sc = new Fx.Scroll(container, {
		wait: false,
		duration: 1000,
		offset: {x:offsetX,y:offsetY},
		transition: Fx.Transitions.Quad.easeInOut
	});
	sc.toElement($(element));
}

function initScroll (containerHeight, content, scrollbar, handle) {
	var steps = content.getScrollSize().y - containerHeight;
	var cTween = new Fx.Morph(content, { transition: Fx.Transitions.Quart.easeOut, duration: 400 });
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: 'vertical',
		onChange: function(step){
			cTween.cancel();
			cTween.start({"top":-step});
		}
	}).set(0);
	$$(content, scrollbar).addEvent('mousewheel', function(e){	
		e = new Event(e).stop();
		var step = slider.step - e.wheel * 30;	
		slider.set(step);	
	});
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

function initAlertMsg() {
	MsgPanelSlide = new Fx.Slide('msg_panel',{duration: 100, transition: Fx.Transitions.Quart.easeOut});
	MsgPanelSlide.hide();
	if (ie6) {
		$('msg_panel').setStyles({'position':'absolute','z-index':'10'});
		window.onscroll = function() {
			$('msg_panel').setStyle('top',document.documentElement.scrollTop+'px');
		};
	}
}
	
function alertMsg(msg,bgColor) {
	MsgPanelSlide.slideIn();
	$('msg_panel').setStyle('background-color',bgColor)
	$('msg_panel_msg').set('text',msg);
	MsgPanelSlide.slideOut.delay(2500, this.MsgPanelSlide);
}

function hideActPanel() {
	if (actPanel != "undefined") {
		actPanel.tween('opacity',1,0);
		actPanel = "undefined";
	}
}

function initWebcam() {
	new Swiff('flash/webcam.swf?rnd='+Math.round(Math.random()*1000000000), {
   		id: 'webcam',
    	width: 300,
   		height: 170,
    	params: { wmode: 'opaque', bgcolor: '#000000' },
    	vars: {},
    	container: $('webcam')
	});
} 