var ajax = new AJAX();
function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xScrollTop(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
    e = xGetElementById(e);
    if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}
function xClientHeight()
{
  var v=0,d=document,w=window;
  if(d.compatMode == 'CSS1Compat' && !w.opera && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}
function xClientWidth()
{
  var v=0,d=document,w=window;
  if(d.compatMode == 'CSS1Compat' && !w.opera && d.documentElement && d.documentElement.clientWidth)
    {v=d.documentElement.clientWidth;}
  else if(d.body && d.body.clientWidth)
    {v=d.body.clientWidth;}
  else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
    v=w.innerWidth;
    if(d.height>w.innerHeight) v-=16;
  }
  return v;
}
var dx = 0;
var dy = 0;
var isopen = false;
function largeIm(url) {
	var t = document.getElementById('imgwin');
	if (t) {
		isopen = true;
		dx = 445; dy = 180;
		t.onclick = closeIm;
		t.style.left = Math.floor(xClientWidth() / 2 - dx) + 'px';
		t.style.top = Math.floor(xClientHeight() / 2 - dy + xScrollTop()) + 'px';
		t.style.background = '#333333 url('+url+') no-repeat 50% 50%';
		t.style.visibility = 'visible';
	}
}
function doneImg(params) {
	var t = document.getElementById('imgwin');
	if (t) t.innerHTML = params.responseText;
}
function loadImg(id, s) {
	var t = document.getElementById('imgwin');
	if (t) {
		isopen = true;
		dx = 391; dy = 300;
		t.style.left = Math.floor(xClientWidth() / 2 - dx) + 'px';
		t.style.top = Math.floor(xClientHeight() / 2 - dy + xScrollTop()) + 'px';
		t.style.visibility = 'visible';
		t.innerHTML = 
				'<img src="images/px.gif" width="1" height="7"/><br/><a href="#" onclick="closeIm(); return false;"><img src="images/close.gif" border="0"/></a><br/>' +
				'<img src="images/px.gif" width="1" height="280"/><br/><img src="images/loading.gif" width="123" height="6"/>';
	}
	ajax.send('index.php', {s: s, id: id, type: 'gallery'}, {callback: doneImg});
}
function closeIm() {
	var t = document.getElementById('imgwin');
	if (t) {
		t.style.background = '#333333';
		t.style.visibility = 'hidden';
		isopen = false;
	}
}
function reposition() {
	if (isopen) {
		var t = document.getElementById('imgwin');
		if (t) {
			t.style.left = Math.floor(xClientWidth() / 2 - dx) + 'px';
			t.style.top = Math.floor(xClientHeight() / 2 - dy + xScrollTop()) + 'px';
		}
	}
}
function top_overnout(a, id, sel, bo) {
	var t = document.getElementById('t'+id);
	if (t) t.className = 't'+(a==1?'s'+(sel=='s'?'':'s'):sel);
}
window.onscroll = reposition;
function overnout(a, id, sel, bo) {
	var t = document.getElementById('m'+id+'t');
	var m = document.getElementById('m'+id+'m');
	var b = document.getElementById('m'+id+'b');
	if (t && m && b) {
		t.className = 'mt'+(a==1?'s':sel);
		m.className = 'mm'+(a==1?'s'+(sel=='s'?'':'s'):sel);
		b.className = 'mb'+bo+(a==1?'s':sel);
	}
}
window.onscroll = reposition;
window.onresize = reposition;