var swfUrl = "http://su27.org/work/flashbox/flashbox.swf";
var infoxml = "";
var thishref = "";
var fwidth;
var fheight;
var fdiv = document.createElement('div');
function imginfo(e){
	infostr = "<x thishref='"+thishref+"' fwidth='"+fwidth+"' fheight='"+fheight+"'>"+infoxml+"</x>";
	//alert(infostr);
	return infostr;
}
function initlinks() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a");
	var na = anchors.length; 
	for (var i=0; i<na; i++) { 
		var anchor = anchors[i]; 
		if (anchor.rel == "flashbox"){ 
			anchor.onclick = playfbox;
    		var infothumb = "";
    		var infotitle = "";
    		if(anchor.childNodes[0].nodeName == "IMG"){
    			infothumb = anchor.childNodes[0].src;
    		}
    		if(anchor.title != 'undefined'){
    			infotitle = anchor.title;
    		}
    		infoxml += "<i title='"+infotitle+"' thumb='"+infothumb+"' href='"+anchor.href+"'/>";
		}
 	}
}
function playfbox(event){
    event = event || window.event;
	var ev = event.target?event.target:event.srcElement; 
	while(ev.tagName != "A"){
		ev = ev.parentNode;
	}
	thishref = ev.href;
	makefbox();
	return false;
}
function addLoadListener(fn){
  if (typeof window.addEventListener != 'undefined'){
    window.addEventListener('load', fn, false);
  }else if (typeof document.addEventListener != 'undefined'){
    document.addEventListener('load', fn, false);
  }else if (typeof window.attachEvent != 'undefined'){
    window.attachEvent('onload', fn);
  }else{
    var oldfn = window.onload;
    if (typeof window.onload != 'function'){
      window.onload = fn;
    }else{
      window.onload = function(){
        oldfn();
        fn();
      };
    }
  }
}

function getViewportSize(){
  var size = [0, 0];
  if (typeof window.innerWidth != 'undefined'){
    size = [window.innerWidth, window.innerHeight];
  }else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth != 'undefined'
      && document.documentElement.clientWidth != 0){
    size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
  }else{
    size = [
        document.body.clientWidth,
        document.body.clientHeight
    ];
  }
  return size;
}

function getspos()
{
  var position = [0, 0];

  if (typeof window.pageYOffset != 'undefined')
  {
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  else if (typeof document.documentElement.scrollTop != 'undefined'
      && (document.documentElement.scrollTop > 0 ||
      document.documentElement.scrollLeft > 0))
  {
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  else if (typeof document.body.scrollTop != 'undefined')
  {
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  return position;
}

function makefbox(){
    document.body.style.overflow='hidden';
	fdiv.style.position = "absolute";
    spos = getspos();
	fdiv.style.left = spos[0]+'px';
	fdiv.style.top = spos[1]+'px';
	winsize = getViewportSize();
	fwidth = fdiv.style.width = winsize[0];
	fheight = fdiv.style.height = winsize[1];
	var swfHtml = "";
	swfHtml += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'; 
	swfHtml += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' +fwidth+ '" height="'+fheight+'" id="demo" align="middle">';
	swfHtml += '<param name="allowScriptAccess" value="always" /><param name="movie" value="' + swfUrl + '" />';
	swfHtml += '<param name="quality" value="high" /><param name="wmode" value="transparent" />';
	swfHtml += '<embed src="' + swfUrl + '" wmode="transparent" quality="high" width="' +fwidth+ '" height="'+fheight+'" name="demo" align="middle" allowScriptAccess="always"'; 
	swfHtml += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	document.getElementsByTagName("body")[0].appendChild(fdiv);
	fdiv.innerHTML = swfHtml;
}
function closefbox(){
	setTimeout(function(){fdiv.parentNode.removeChild(fdiv);document.body.style.overflow='auto'}, 10);
}

addLoadListener(initlinks);
