/**
* LAST MOD: APR 04 2009
* ---------------------
*/
//DISPLAY BODY COVER TO FADE BACKGROUND
function cover() {
	var scrolled=(document.body.scrollTop+document.documentElement.scrollTop);
	var hh=(document.documentElement.clientHeight)+scrolled;
	try{
		var makeObj=document.createElement('<div style="position: absolute; z-index: 998; width: 100%; height: '+hh+'px; top: 0px; left: 0px; background-color: #505050; filter: alpha(opacity=90);)">');
	}catch(er) {
		var makeObj=document.createElement('div');
		with(makeObj.style) {
			position="absolute";
			zIndex="998";
			width="100%";
			height=hh+"px";
			top="0px";
			left="0px";
			backgroundColor="#505050";
			opacity=0.9;
		}
	}
	makeObj.setAttribute('id','coverDiv');
	document.body.appendChild(makeObj);
}
//FETCH OUR SELECTED IMAGE ID
function pullImage(t,r) {
	var rq=xmlObject(2500);
	if(typeof(rq)!="object") {
		alert(rq);
		return false;
	}
	var theURL=baseURL+"dir_arts/images.php";
    var params="session="+session+"&rowid="+r+"&nocache"+parseInt(Math.random()*999999);
    rq.open('POST',theURL,true);
    rq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    rq.setRequestHeader("Content-Length",params.length);
    rq.setRequestHeader("Connection","close");
    rq.send(params);
    //
    rq.onreadystatechange=function() {
        if(rq.readyState==4) {
            if(rq.status==200) {
                myInfo=rq.responseText;
                if(myInfo.indexOf('||')!=-1 && myInfo.replace(/ /g,'')!="") {
                	var attributes=myInfo.split('||');
                	//LET'S CREATE THE IMAGE
                	var parentObj=document.getElementById('imgViewerBody');
                	//first incase there's content in our viewer, remove it
                	try{
                		parentObj.removeChild(document.getElementById('imgHolder'));
                	}catch(er) {
                		//do nothing
                	}
                	//
                	createBox(attributes[3],((attributes[4]*1)+50),attributes,parentObj);
					//
                }else if(myInfo=="") {
                	alert("Sorry buddy, I couldn't find this image.\nRefresh your page and try again.");
                }
                //document.getElementById('imgViewer').innerHTML=myInfo;
            }
            //KILL THE TIMER IF IT EXISTS
            try{
                window.clearTimeout(xmlTimer);
            }catch(er) {
                //do nothing
            }
        }
    }
}
//CREATE OUR IMAGE DISPLAY BOX
var timer=null;//---->control animation
var speed=15;//------>animation speed in miliseconds
var increment=20;//-->pixels per speed
var min=10;//-------->min x & y to start at
var maxW=0;//-------->max width to grow
var maxH=0;//-------->max height to grow
var ww=0;//---------->current position in x
var hh=0;//---------->current position in y
var runOnce=true;
function createBox(x,y,a,p) {
	if(runOnce==true) {
		cover();
		maxW=x;
		maxH=y;
		ww=(document.body.clientWidth/2);
		var scrolled=(document.body.scrollTop+document.documentElement.scrollTop);
		hh=((document.documentElement.clientHeight/2)+scrolled);
		document.getElementById('imgViewer').style.display="block";
		runOnce=false;
	}
	var viewer=document.getElementById('imgViewer');
	//find our measurements
	var isWidth=(viewer.style.width=="" ? min+"px" : viewer.style.width);
	if(isWidth.indexOf('px')!=-1) {
		isWidth=(isWidth.substring(isWidth,(isWidth.length-2)))*1;
	}
	var isHeight=(viewer.style.height=="" ? min+"px" : viewer.style.height);
	if(isHeight.indexOf('px')!=-1) {
		isHeight=(isHeight.substring(isHeight,(isHeight.length-2)))*1;
	}
	//do our equations
	var diffWidth=(isWidth+increment);
	var diffHeight=(isHeight+increment);
	//grow our animation
	if(isWidth<maxW) {
		viewer.style.width=diffWidth+"px";
		timer=window.setTimeout((function(){createBox(x,y,a,p);}),speed);
	}else if(isWidth!=maxW) {
		viewer.style.width=maxW+"px";
		timer=window.setTimeout((function(){createBox(x,y,a,p);}),speed);
	}else if(isWidth==maxW && isHeight<maxH) {
		viewer.style.height=diffHeight+"px";
		timer=window.setTimeout((function(){createBox(x,y,a,p);}),speed);
	}else{
		viewer.style.height=(maxH-increment)+"px";
		try{
			window.clearTimeout(timer);
		}catch(er) {
			//do nothing
		}
		//Now create our objects so we can view our image
		try{
			createObjects(a,p);
		}catch(er) {
			//do nothing
		}
	}
	//reposition x & y coords as animation grows
	with(viewer.style) {
		left=(ww-(diffWidth/2))+"px";
		top=(hh-(diffHeight/2))+"px";
	}
}
//CREATE OUR IMAGE OBJECT
function createObjects(a,p) {//a=array of attributes
	var attributes=a;
	var parentObj=p;
	try{
        //next create the container div object
        var divObj=document.createElement('<div id="imgHolder" style="position: relative; width: '+attributes[3]+'px; height: '+attributes[4]+'px;">');
		//now create the img
		var imgObj=document.createElement('<img id="imgLoaded" src="'+attributes[5]+'" border="0" width="'+attributes[3]+'" height="'+attributes[4]+'" />');
		divObj.appendChild(imgObj);
	}catch(er) {
		//first create the container div object
		var divObj=document.createElement('div');
		divObj.setAttribute('id','imgHolder');
		with(divObj.style) {
			position="relative";
			width=attributes[3]+"px";
			height=attributes[4]+"px";
		}
		//now create the img
		var imgObj=document.createElement('img');
		imgObj.setAttribute('width',attributes[3]);
		imgObj.setAttribute('height',attributes[4]);
		imgObj.setAttribute('border',0);
		imgObj.setAttribute('src',attributes[5]);
		divObj.appendChild(imgObj);
		//imgObj.style.border="solid 1px #ff0000";
	}
	//finally, slap it together
	parentObj.appendChild(divObj);
	document.getElementById('imgHolder').style.background="url('"+attributes[1]+"') no-repeat";
	document.getElementById('imgViewerHead').innerHTML="<div class=\"floatR\"><a onclick=\"closeViewer();\"><img src=\"images/icon_exit.jpg\" border=\"0\" /></a> </div>TITLE::: &nbsp; "+attributes[0]+"";
	//to help in preventing img theft, let's disable a couple things. Of course, there's still a million other ways around it
	try{
		//document.getElementById('imgViewer').oncontextmenu = function() { return false; }
		//document.getElementById('imgViewer').ondragstart   = function() { return false; }
	}catch(er) {
		//do nothing
	}
}
//CLOSE THE IMAGE VIEWER
function closeViewer() {
	//first reset our viewer div to defaults
	with(document.getElementById('imgViewer').style) {
		width="10px";
		height="47px";
		display="none";
		top="0px";
		left="0px";
	}
	//now clean up the generated viewer content
	document.getElementById('imgViewerHead').innerHTML="";
	try{
		document.getElementById('imgViewerBody').removeChild(document.getElementById('imgHolder'));
	}catch(er) {
		document.getElementById('imgViewerBody').innerHTML="";
	}
	//reset all our values that pertain to our animation
	maxW=0;
	maxH=0;
	ww=0;
	hh=0;
	runOnce=true;
	//remove cover if it exists
	try{
		document.body.removeChild(document.getElementById('coverDiv'));
	}catch(er) {
		//do nothing
	}
}

