			var picList=new Array();
			var textList=new Array();
			var rodomas = -1;
			var viso = 0;
			var imgno = 0;
			
			var textRotator=new Array();
			var textRotatorTemp=new Array();
			
			function loadRotator() {
				if (document.images)
			    {
					preload_image_object = new Image();
				}

				for (i=0;i<picList.length;i++)
				{
					if (document.images)
				    {
						preload_image_object.src = picList[i];
					}
					$('rotatorPreload').innerHTML += "<img src='"+picList[i]+"' width='1px' height='1px' />";					
				}
			}
			
			function activatePic(i) {
				preload_image_object.src= picList[i];
				$('main_pic_title').innerHTML = textList[i];
				preload_image_object.onload = function () {
					$('rotator_img1').src = $('rotator_img2').src;
					$('rotator_img2').hide();
					$('rotator_img2').src = preload_image_object.src;
					Effect.toggle('rotator_img2','appear');
					
				}
			}
			
		
			
			var rotatorpelyte = 0;
			function autorotator() {
				if(rotatorpelyte>0) {
					return true;
				}
				rotator();
			}
			
			
			function rotator() {
				if(rodomas==viso) {
					rodomas = 0;
				}
				else {
					rodomas++;
				}
				activatePic(rodomas);
			}
			

			
			
//////////////////////////////////////////////////////
		var v_menuids=["mainmeniu"];	
			
function buildsubmenus_vertical(){
for (var i=0; i<v_menuids.length; i++){
if(document.getElementById(v_menuids[i])) {
  var ultags=document.getElementById(v_menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==v_menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
}
  }
}
			
		///////////////////////////////////////////////	
	

	
	
		
		
	function checkdateformat(inputas) {	
		var re = new RegExp(/^(19|20)\d\d([- //.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$/);
		var m = re.exec(inputas.value);
		if (m == null) {
			alert('Date format must be YYYY-MM-DD');
			inputas.focus();
		}
	}
		
		
function inittextrotator(roid, count, speed) {
	new PeriodicalExecuter(function(){textrotator(roid, count);}, speed);
}


function textrotator(roid, count) {
	//alert('change text rotator #'+roid+' num:'+textRotatorTemp[roid]);
	if(textRotatorTemp[roid]==count) {
		textRotatorTemp[roid]=0;
		$('rotatorchild_'+count).hide();
		//Effect.toggle('rotatorchild_'+count,'appear');
	}
	else {
		$('rotatorchild_'+textRotatorTemp[roid]).hide();
	//	Effect.toggle('rotatorchild_'+textRotatorTemp[roid],'appear');
	}
	textRotatorTemp[roid]++;
	//$('rotatorchild_'+textRotatorTemp[roid]).show();
	Effect.toggle('rotatorchild_'+textRotatorTemp[roid],'appear');
}
	
		
		function start_js(){
			if(v_menuids.length>0) {
				buildsubmenus_vertical();
			}
			viso = picList.length-1;
			if (picList.length>1) {
				if($('mainpic')) {
					loadRotator();
					autorotator();
					new PeriodicalExecuter(autorotator, picrotatortime);
				}
			}
			
			if(textRotator.length>0) {
				for (var i=0; i<textRotator.length; i++){
					if(!textRotatorTemp[textRotator[i][0]]) {
						textRotatorTemp[textRotator[i][0]] = 1;
					}
					inittextrotator(textRotator[i][0], textRotator[i][1], textRotator[i][2]);
				}
			}
			
			
			new Proto.Menu({
			  selector: '.menuitem', // context menu will be shown when element with id of "contextArea" is clicked
			  className: 'menu desktop', // this is a class which will be attached to menu container (used for css styling)
			  menuItems: myMenuItems // array of menu items

			})
			new Proto.Menu({
			  selector: '.scontentitem', // context menu will be shown when element with id of "contextArea" is clicked
			  className: 'menu desktop', // this is a class which will be attached to menu container (used for css styling)
			  menuItems: myContentItems // array of menu items

			})
			new Proto.Menu({
			  selector: '.newscontentitem', // context menu will be shown when element with id of "contextArea" is clicked
			  className: 'menu desktop', // this is a class which will be attached to menu container (used for css styling)
			  menuItems: myNewsContentItems // array of menu items

			})
			
			
			
		}

		if (window.addEventListener) {
			window.addEventListener("load", start_js, false);
		}
		else if (window.attachEvent) {
			window.attachEvent("onload", start_js);
		}
		
		
		window.onresize = function (){
			if($('adminWindow').style.display!='hidden') {
			var psizes = getPageSize();
				$('adminWindow').style.width = psizes[0] +"px";
				$('adminWindow').style.height = psizes[1] +"px";
				$('adminWindowEdit').style.width = psizes[0]-100 +"px";
				$('adminWindowEdit').style.height = psizes[1]-100 +"px";
				$('adminWindowMainFrame').style.width = psizes[0]-120 +"px";
				$('adminWindowMainFrame').style.height = psizes[1]-120 +"px";
			}
		}
		
		
var myMenuItems = [
  {
    name: 'Redaguoti',
    className: 'edit',
    callback: function(e) {
		//e.target.className.match('subfolderstyle') ? alert(e.target.id+' yra tėvinis meniu punktas') : alert(e.target.id+' NĖRA tėvinis meniu punktas');
		adminWindow('menu', 'edit', e.target.id);
    }
  },
  {
    separator: true
  },
   {
    name: 'Naujas punktas',
    className: 'new',
    callback: function(e) {
		//	var oid = (e.target.id) ? e.target.id.split("_") : null;
		//	window.location='http://www.tourismcatalog.eu/?adm=menu&edit=new';
			adminWindow('menu', 'edit', 'new');
	}	
    
  },
  {
    separator: true
  },
  {
    name: 'Ištrinti',
    className: 'delete',
	disabled: false,
    callback: function(e) {
		if(e.target.className.match('subfolderstyle')) {
			alert('Šis meniu punktas turi submeniu punktų.\nŠio meniu punkto ištrinti negalima.');
		}		
		else {
			var liuks=confirm('Ar tikrai noreite ištrinti šį meniu punktą?'); 
			if(liuks) {
			var oid = (e.target.id) ? e.target.id.split("_") : null;
			window.location='http://maratonas.turistas.lt/?adm=menu&menudel='+oid[1]+'&delmenu='+oid[1];
			}
		}
	}
  },
  {
    separator: true
  },
  {
    name: 'Keisti meniu eiliškumą',
    className: 'edit',
    callback: function(e) {
		adminWindow('menu');
    }
  }
  
]

var myContentItems = [
  {
    name: 'Redaguoti tekstą',
    className: 'edit',
    callback: function(e) {
		//e.target.className.match('subfolderstyle') ? alert(e.target.id+' yra tėvinis meniu punktas') : alert(e.target.id+' NĖRA tėvinis meniu punktas');
		adminWindow('scontent', 'edit', e.target.id);
    }
  }
]

var myNewsContentItems = [
  {
    name: 'Redaguoti naujieną',
    className: 'edit',
    callback: function(e) {
		//e.target.className.match('subfolderstyle') ? alert(e.target.id+' yra tėvinis meniu punktas') : alert(e.target.id+' NĖRA tėvinis meniu punktas');
		adminWindow('news', 'edit', e.target.id);
    }
  },
  {
    separator: true
  },
   {
    name: 'Naujas naujienų įrašas',
    className: 'new',
    callback: function(e) {
		//	var oid = (e.target.id) ? e.target.id.split("_") : null;
		//	window.location='http://www.tourismcatalog.eu/?adm=menu&edit=new';
			adminWindow('news', 'edit', 'new');
	}	
    
  },
   {
    separator: true
  },
  {
    name: 'Ištrinti',
    className: 'delete',
	disabled: false,
    callback: function(e) {
		var liuks=confirm('Ar tikrai noreite ištrinti šią naujieną?'); 
		if(liuks) {
			var oid = (e.target.id) ? e.target.id.split("_") : null;
			window.location='http://maratonas.turistas.lt/?adm=news&textdel='+oid[1]+'&deltext='+oid[1];
		}
		
	}
  }
]

function adminWindow(objektas, veiksmas, objid) {
	var psizes = getPageSize();
	$('adminWindow').style.width = psizes[0] +"px";
	$('adminWindow').style.height = psizes[1] +"px";
	$('adminWindowEdit').style.width = psizes[0]-100 +"px";
	$('adminWindowEdit').style.height = psizes[1]-100 +"px";
	$('adminWindowMainFrame').style.width = psizes[0]-200 +"px";
	$('adminWindowMainFrame').style.height = psizes[1]-200 +"px";
	
	//$('adminWindowMain').innerHTML='Palaukite...';
	var veiksm = '';
	if(objid!='new') {
		var oid = (objid) ? objid.split("_") : null;
	}
	else {
		var oid = new Array('new', 'new');
	}
	
	if(veiksmas && oid[1]) {
		veiksm = veiksmas+"="+oid[1]+"&";
	}
	//$('adminWindowMainFrame').innerHTML = 'Palaukite...';
	$('adminWindowMainFrame').src = "http://maratonas.turistas.lt/admajax.php?adm="+objektas+"&"+veiksm+"html="+unikalusSk();
	
//	var pars = "adm="+objektas+"&"+veiksm+"html="+unikalusSk();
//	var url = "http://www.tourismcatalog.eu/admajax.php";
	//$('adminWindowEdit').innerHTML+='URL: '+url+'?'+pars;
//	var myAjax = new Ajax.Updater(
//	{success: 'adminWindowMain'},
//	url, 
//		{
//			method: 'get',
//			parameters: pars,
//			onFailure: reportError,
//			evalScripts: true
//		}
//	);
	
	
	$('adminWindow').show();  
}


function hideAdminWindow() {
	$('adminWindow').hide();
	 $('adminWindowMainFrame').src = 'http://maratonas.turistas.lt/admajax.php?adm=palaukite';
	//$('adminWindowMain').innerHTML='';
}

function unikalusSk () {
	var Data = new Date();
	var mo= Data.getMonth();
	var da= Data.getDay();
	var ho= Data.getHours();
	var mi= Data.getMinutes();
	var se= Data.getSeconds();
	var uni = mo+''+da+''+ho+''+mi+''+se;
	return uni;
}

function reportError(request) {
	$('adminWindowMain').innerHTML += '<div class=\"error\">Sisteminė klaida: Įvyko klaida parsiunčiant reitingavimo duomenis į serverį. Balsas nėra užskaitytas, bandykite vėliau...</div>';
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
	
function reloadAfterSave() {
	 
	setTimeout(reloadPage ,1250);
}

function reloadPage() {
	$('adminWindowMainFrame').src = 'http://maratonas.turistas.lt/admajax.php?adm=palaukite';
	window.location = window.location;
	$('adminWindow').hide();
}

		
