// JavaScript Document

Object.extend(String.prototype, {
  to_i: function(){
    return parseFloat(this)
  }
})


function popmeup(){
	var links = $$('.popup')
	var offset = 20;
	var _width = 1024+offset;
	var _height = 768+offset;

	var popUpWin = 0;
	function popUpWindow(URLStr, left, top, width, height)
	{
		if(popUpWin)
		{
			if(!popUpWin.closed) popUpWin.close();
		}
		popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	}


	function popup (url, w, h){
		x = w || _width;
		y = h || _height;
		sx = screen.width
		sy = screen.height
		x += offset;
		y += offset;
		
		if(y>sy){
				o = x/y;
				y -= y-sy+50;
				x = Math.floor(o*y);
				sy = y
		}	

		var winl = (sx - x) / 2;
		var wint = (sy - y) / 2;
		
		popUpWindow(url, winl, wint, x, y);
	}
	
	

	links.each(function(s){					
			s.onclick = function(){
				img = this.href.toQueryParams();
				if(img.size){
					size = img.size.split(',');				
					popup(this.href, size[0].to_i(), size[1].to_i())
				}
				else{
					popup(this.href)
					}
				return false;
			};		
	})	
}

Event.observe(window,'load', popmeup);
