// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}
//------------------------------
var selected_id = null;
var dom = document.getElementById;

function swapIt(id, newclass) {
	if (dom) {
		if(selected_id != id) {
			el = document.getElementById(id);
			el.className = newclass;
			el.style.cursor = "hand";
			el.style.cursor = "pointer";
		}
	}
}
function down (id,oldclass,newclass){
	if (dom) {
		if(selected_id != null) {
			document.getElementById(selected_id).className = oldclass;
		}
	el.className = newclass;
	selected_id = id;
}
}
//---------------------------
//Paveiksliuko zoome efektas
function zoomImage(id){
	
  var dimensions  = id.getDimensions();
  var width       = dimensions.width  * 2;
  var height      = dimensions.height * 2;
  
  var bigImage    = new Image(width,height);
 
  var bigImageSrc = "./images/uploads/"+id.readAttribute("alt");
  
  
  bigImage.width  = dimensions.width;
  bigImage.height = dimensions.height;
 
  //Pirma uzkrauname, panaikinamas mirksejimo efektas
  bigImage.onload = function() {
	  
  id.insert({before:bigImage});
  
  $(bigImage).absolutize();
  position = bigImage.positionedOffset();
 
  
  var leftPosition = position.left - (width/2);
  var positionTop  = position.top - height;
  
  if (leftPosition < 0) {
	  position.left = 0;
  } else {
	  position.left = leftPosition;
  }

  var docWidth = $('docs').getWidth()+280;
  var browserDims = getPageSize();
  var arrayPageScroll = getPageScroll();
  
  if (browserDims[2] > docWidth) {
	  browserDims[2] = docWidth;
  }
  
  var bigWidth  = id.readAttribute('w');
  var bigHeight = id.readAttribute('h');
  
  //Skaiciuojame paveiksliuko vieta, langas+scroll pozicija - paveiksliuko aukstis /2
  var y = ((browserDims[3]+arrayPageScroll[1]*2) - bigHeight) / 2;
  var x = (browserDims[2] - bigWidth) / 2;
  
  new Effect.Morph(bigImage, {
	  style: 'width:'+bigWidth+'px; height:'+bigHeight+'px; left:'+x+'px; top:'+y+'px;', 
	  duration: 0.8 
  });

  $(bigImage).addClassName('zoomed'); //Paveiksl. padidintas
  var currentElement = bigImage.identify(); //Priskiriame sugeneruota id ir gauname elemento varda
  
  //Pasalinam visus atidarytus paveiksl
  $$('img.zoomed').each(function(ids){
      if (ids.identify() != currentElement) {
	      ids.remove();			
	  }
  });
  
  //uzdarymo eventas
  Event.observe(bigImage, 'click', function(event){ 
      id.show();
	  bigImage.remove();	 
  },false);
  }
  
  //Image kelias
  bigImage.src    = bigImageSrc;
  
}
//gauti puslpio dydi, taip pat matomos zonos dydi
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;

	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;
	}	

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
//gauti puslapio scroll pozicija
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
function initScripts(){

 $$('img.zoom').each(function(id){
	Event.observe(id, 'click', function(event){
	    zoomImage(id);
	},false);
 }); 
}


Event.observe(window, 'load', initScripts, false);


		 