var changeOpacity;
var httpRequestObject;
var mainimage;
var xpos = 0;
var ypos = 0;

function init(){
	httpRequestObject=getHTTPObject();
	window.document.body.onmousedown=function(theEvent){setPos(theEvent?theEvent:event)};
}


function getHTTPObject() {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	return xmlhttp;
}

function switchback() {
    var container = document.getElementById('containerimg').style;
    container.opacity = 100;
    container.MozOpacity = 100;
    container.KhtmlOpacity = 100;
    container.filter = "alpha(opacity=100)";
    clearTimeout(changeOpacity);
    restoreimg();
}

function opacity(id, oStart, oEnd, speed) {
    var numopacity=-1;
    
    if(oStart > oEnd) {
      numopacity = oStart - 10;
    }
    else if(oStart < oEnd) {
      numopacity = oStart + 10;
    }
    if(numopacity<0 || numopacity>100) {
	var ajax = document.getElementById('loader');
	ajax.style.display="none";
	ajax.style.top = 0+"px";
	ajax.style.left= 0+"px";
	}
    else {
      changeOpacity = setTimeout("opacity('"+id+"', "+numopacity+", "+oEnd+", "+speed+")", speed);
      var object = document.getElementById(id).style;
      object.opacity = numopacity/100;
      object.MozOpacity = numopacity/100;
      object.KhtmlOpacity = numopacity/100;
      object.filter = "alpha(opacity=" + numopacity + ")";
    }
}

function imgopacity(id, oStart, oEnd, speed) {
    var numopacity=-1;
    
    if(oStart > oEnd) {
      numopacity = oStart - speed;
    }
    else if(oStart < oEnd) {
      numopacity = oStart + speed;
    }
    if(numopacity<0 || numopacity>100) {
    var ajax = document.getElementById('loader');
	ajax.style.display="none";
	ajax.style.top = 0+"px";
	ajax.style.left= 0+"px";

    }
    else {
      var changeOpacity2 = setTimeout("imgopacity('"+id+"', "+numopacity+", "+oEnd+", "+speed+")", speed);
      var object = document.getElementById(id).style;
      object.opacity = numopacity/100;
      object.MozOpacity = numopacity/100;
      object.KhtmlOpacity = numopacity/100;
      object.filter = "alpha(opacity=" + numopacity + ")";
    }
}

function homeswitch() {
    var container = document.getElementById('bgcontainer');
    container.src = "images/body_home.jpg";
    opacity('containerimg', 100, 0, 20);
    dimimg("home");
}

function mainpic(num) {
	var homepic = document.getElementById('pic');
	homepic.style.display="none";
	homepic.opacity = 0;
    homepic.MozOpacity = 0;
    homepic.KhtmlOpacity = 0;
    homepic.filter = "alpha(opacity=0)";
	homepic.src=imagearray[num-1];
	var ajax = document.getElementById('loader');
	ajax.style.display="block";
	ajax.style.top = 100+"px";
	ajax.style.left= 300+"px";
	nextimg(num);
	hires(num);
}

function hires(num) {
	var link = document.getElementById('ahref');
	link.href=hiresarray[num-1];
}


function hidepopup() {
	var popup = document.getElementById('thumbnailbox');
	popup.style.display="none";
}

function thumbshow(thumb, name) {
	var popup = document.getElementById('thumbnailbox');
	popup.style.display="block";
	var ie7=document.all && window.XMLHttpRequest && !window.opera;
	if( ie7 ){
	
	popup.style.top = (parseInt(thumb.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop) + parseInt(thumb.offsetParent.offsetParent.offsetTop) + parseInt(thumb.offsetTop) - 70) + "px";
		popup.style.left = thumb.offsetParent.offsetParent.offsetLeft + thumb.offsetLeft - 20 + "px";
	}
	else {
		popup.style.top = thumb.offsetTop - 70 + "px";
		popup.style.left = thumb.offsetLeft - 20 + "px";
	}
	var popupimg = document.getElementById('thumbnailpopup');
	popupimg.src = name;

} 


function imgLoaded() {
	var ajax = document.getElementById('loader');
	ajax.style.display="none";
	ajax.style.top = 0+"px";
	ajax.style.left= 0+"px";

	var homepic = document.getElementById('pic');
	imgopacity('pic', 0, 100, 4);
	homepic.style.display="block";
}

function smallpic(img) {
	var smallpicture = document.getElementById('smallpicture');
	smallpicture.opacity = 0;
    smallpicture.MozOpacity = 0;
    smallpicture.KhtmlOpacity = 0;
    smallpicture.filter = "alpha(opacity=0)";
	smallpicture.style.display="none";
	smallpicture.src=img;
}

function imgLoaded2() {
	var smallpicture = document.getElementById('smallpicture');
	imgopacity('smallpicture', 0, 100, 4);
	smallpicture.style.display="block";
}

function nextimg(num) {
	curnum = num -1;
	if(parseInt(num) == imagearray.length)
		num = 0;
	var link = document.getElementById('nexti');
	link.onclick = new Function("mainpic('"+(parseInt(num)+1)+"')");
}

function openemail() {
	var emailbox = document.getElementById('emailbox');
	if(xpos != 0)
		emailbox.style.display = "block";
	emailbox.style.left=xpos+"px";
	emailbox.style.top=ypos+"px";
}

function closeemail() {
	var emailbox = document.getElementById('emailbox');
	emailbox.style.display = "none";
	emailbox.style.left="0px";
	emailbox.style.top="0px";
}

function setPos(e) {
	xpos = e.clientX-50;
	ypos = e.clientY;
}

onload=init;

