function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
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=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function windowpopper(url, pop_width, pop_height, scrolling) {
        var sb = "";
                if (scrolling == 1) { sb = 'yes'; } else { sb = 'no'; }
                window.open(url, 'PopupWindow', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=' + sb + ',resizable=no,titlebar=no,width=' + pop_width + ',height=' + pop_height);
}

function printandgoback() {
    window.print();
    history.go(-1);
                }

function doselectAll(theBox) {
	xState=theBox.checked;
	elm=theBox.form.elements;
	for(i=0;i<elm.length;i++)
	  if(elm[i].type=="checkbox")
	    elm[i].checked=xState;
}

//global vars for rotate image
var xmlHttp;
var current = "none";
var currentImage;
var newimg;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function stateChanged()
{
	if(xmlHttp.readyState == 4)
	{
		//parse img src and index
		var props = xmlHttp.responseText.split(',');
	
		currentImage = document.getElementById('rotateImg');
		if(!currentImage)
		{
			setTimeout("rotate()",1000);
			return;
		}
		newimg = document.createElement('img');

		newimg.onload = function (evt)
						{
								try
								{
									//ie blend
									currentImage.style.filter="blendTrans(duration=2)";
									// Make sure filter is not playing.
									if ((currentImage.filters.blendTrans.status != 2)) {
										currentImage.filters.blendTrans.Apply();
										currentImage.src = this.src;
										currentImage.filters.blendTrans.Play();
									}
									
								} catch(e) {
									//non-ie fade out	
									var speed=7;
									var timer=0;
							
										for(i=100;i>0;i-=2) 
											setTimeout('changeOpac('+i+')',timer++ * speed);

										setTimeout('swapimg()', timer * speed);

										//non-ie fade in
										for(i=0;i<=100;i+=2) 
											setTimeout('changeOpac('+i+')',timer++ * speed);
								}
						}

		newimg.src = props[0];//set the img source
		if(document.getElementById('rotateAnchor'))
		document.getElementById('rotateAnchor').href = props[1];
		current = props[2];//set the img index

	}
}

function rotate()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
		  //alert ("Your browser does not support AJAX!");
		  return;
	  }
	var url = "/includes/rotate.php?imgnum="+current;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function changeOpac(opacity){
	var obj = document.getElementById('rotateImg').style;
	obj.opacity=(opacity/101);
	obj.MozOpacity=(opacity/101);
	obj.KhtmlOpacity=(opacity/101);
}

function swapimg()
{
		currentImage.src = newimg.src;
}

function start()
{
	rotate();
	self.setInterval("rotate()",12000);
}

//document.getElementsByTagName('body').onload=start();
start();