var IE4 = (document.all) ? true : false;
var NN4 = (document.layers) ? true : false;
var NN6 = (document.getElementById && !document.all) ? true : false;
var iLayerX = 0;
var iLayerY = 0;
var iMouseX = 0;
var iMouseY = 0;
var bMouseDown = 0;
var iOpacity = 0;
var bFadeComplete = true;
var currDiv = 0;
var bSliderContent = false;
var iOldSliderX = "";
var iNewSliderX = "";
var bSliderComplete = true;
var iSlideInterval = (IE4) ? 5 : 10;
var iSlideSpeed = (IE4) ? 30: 30;
var iSimpleSliderX = "";

function updatePage(sInput, sDiv) {
	
	var oInput = document.getElementById(sInput);
	
	
	if(!oInput.checked) {
		hidelayer(sDiv);	
	}
	else {
		showlayer(sDiv);
	}
}

function swapImage(sID,sSrc) {
    
    var oImg = document.getElementById(sID);
    
    if(!oImg) {
        return;
    }
    
    oImg.src = sSrc;   

};

function hidelayer(layerName) {
 	var oDiv = document.getElementById(layerName);
	if(!oDiv)
		return;
		
    document.getElementById(layerName).style.visibility = "hidden";
	document.getElementById(layerName).style.display = "none";
};

function showlayer(layerName) {
	var oDiv = document.getElementById(layerName);
	if(!oDiv)
		return;
    document.getElementById([layerName]).style.display = "block";
    document.getElementById([layerName]).style.visibility = "visible";
};

function deletePhoto (the_form, value)
{
  document.forms[the_form].delete_photo_id.value = value;
  document.forms[the_form].submit();
};

function prepareMoveLayer(oDiv,oEvent) {
    
    var oDivProgress = document.getElementById(oDiv);
    //var oDivDebug = document.getElementById('debug');
    
    iLayerX = parseInt(oDivProgress.style.left);
    iLayerY = parseInt(oDivProgress.style.top);
    iMouseX = oEvent.clientX;
    iMouseY = oEvent.clientY;
    bMouseDown = 1;
    //oDivDebug.innerText = iLayerX + " " + iLayerY + " " +iMouseX + " " + iMouseY;
};

function moveLayer(oDiv,oEvent) {
    var oDivProgress = document.getElementById(oDiv);
    
    if(!bMouseDown) {
        return;
    }
    
    var iDiffX = oEvent.clientX - iMouseX;
    var iDiffY = oEvent.clientY - iMouseY;
    
    oDivProgress.style.left = (iLayerX + iDiffX) + "px";
    oDivProgress.style.top = (iLayerY + iDiffY) + "px";
    oDivProgress.style.cursor = "pointer";
    
};
    
function clearMove(oDiv) {
    bMouseDown = 0;
    iMouseX = iMouseY = iLayerX = iLayerY = 0;
    var oDivProgress = document.getElementById(oDiv);
    oDivProgress.style.cursor = "move";
};

function centerLayer(oDiv) {
    if(IE4) {
        var width = document.body.offsetWidth;
        var height = document.body.offsetHeight;
    }
    if(NN4 || NN6) {
        var width = parseInt(window.innerWidth);
        var height = parseInt(window.innerHeight);
    }
    var centerX = parseInt((width - oDiv.offsetWidth) / 2);
    var centerY = parseInt((height - oDiv.offsetHeight) / 2);
    if(centerX < 0) {
        centerX = 0;
    }
    if(centerY < 0) {
        centerY = 0;
    }
    oDiv.style.left = centerX + "px";
    oDiv.style.top = centerY + "px";
};

function fadeInLayer(sDiv) {
    
    if(bFadeComplete == false) {
        setTimeout("fadeInLayer('" + sDiv + "')",100);
        return;
    }
    
    var oDiv = document.getElementById(sDiv);

    bFadeComplete = false;
    iOpacity = 0;
    oDiv.style.opacity = iOpacity;
    oDiv.style.filter = "alpha(opacity=" + (iOpacity * 100) + ")"; 
 
    _fadeInLayer(sDiv);
};

function _fadeInLayer(sDiv) {
    
    var oDiv = document.getElementById(sDiv);

    iOpacity += (IE4) ? .15 : .10;

    if(iOpacity >= 1) {
        iOpacity = 1;
        oDiv.style.opacity = iOpacity;
        oDiv.style.filter = "alpha(opacity=" + (iOpacity * 100) + ")";
        bFadeComplete = true;
        return;
    }
    
    oDiv.style.opacity = iOpacity;
    oDiv.style.filter = "alpha(opacity=" + (iOpacity * 100) + ")"; 
    setTimeout("_fadeInLayer('" + sDiv + "');",(IE4) ? 5 : 25);    

};

function fadeOutLayer(sDiv) {
    
    if(bFadeComplete == false) {
        setTimeout("fadeOutLayer('" + sDiv + "')",100);
        return;
    }
    
    var oDiv = document.getElementById(sDiv);

    bFadeComplete = false;
    iOpacity = 1;
    oDiv.style.opacity = iOpacity;
    oDiv.style.filter = "alpha(opacity=" + (iOpacity * 100) + ")"; 
 
    _fadeOutLayer(sDiv);
    
};

function _fadeOutLayer(sDiv) {

    var oDiv = document.getElementById(sDiv);
    
    iOpacity -= (IE4) ? .15 : .10;

    if(iOpacity <= 0 ) { 
        iOpacity = 0;
        bFadeComplete = true;
        return;
    }
    
    oDiv.style.opacity = iOpacity;
    oDiv.style.filter = "alpha(opacity=" + (iOpacity * 100) + ")"; 
    setTimeout("_fadeOutLayer('" + sDiv + "');",(IE4) ? 5 : 25);   
    
};

function _wait(millis)
{
    var date = new Date();
    var curDate = null;
    
    do { 
        var curDate = new Date(); 
    } while(curDate-date < millis);
};


function getTopPos(inputObj) {		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
};

function getLeftPos(inputObj) {
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
};

function getRightPos(inputObj) {
    
    var leftPos = getLeftPos(inputObj);
    var rightedge= inputObj.offsetWidth+leftPos;

    return rightedge;  

};

function positionLayer(inputObj,x,y) {
    
    inputObj.style.left = x + "px";
    inputObj.style.top = y + "px";
    
};

function initializeSlider(sContainer,sDivPrefix,sContent) {
    
    currDiv = (currDiv) ? 0 : 1;
    
    var oContainer = document.getElementById(sContainer);
    var oNewDiv = document.createElement('DIV');
    
    oContainer.innerHTML = "";
    oNewDiv.style.position = 'relative';
    oNewDiv.id = sDivPrefix + currDiv;
    oNewDiv.innerHTML = sContent;
    oContainer.appendChild(oNewDiv);
    
    bSliderContent = true;
       
};

function slideLayer(sContainer,sDivPrefix,sContent,cDirection) {

    if(bSliderComplete == false) {
        setTimeout("slideLayer('" + sContainer + "','" + sDivPrefix + "','" + sContent + "','" + cDirection + "',')",100);
        return;
    }
     
    var sOldDiv = sDivPrefix + currDiv;   
    var newDiv = (currDiv) ? 0 : 1;
    var sNewDiv = sDivPrefix + newDiv;

    var oNewDiv = document.getElementById(sNewDiv);
    var oContainer = document.getElementById(sContainer);
    var oOldDiv = document.getElementById(sOldDiv);
    
    if(!oNewDiv) {
        oNewDiv = document.createElement('DIV');
        oNewDiv.style.position = 'absolute';
        
        oNewDiv.id = sNewDiv;
        oNewDiv.innerHTML = sContent;
        oContainer.appendChild(oNewDiv);
    }
    
    if(cDirection == "l") {
        iNewSliderX = oContainer.offsetWidth + 5;
    }
    else {
        iNewSliderX = -1 * (oNewDiv.offsetWidth + 5);    
    }
    
    iOldSliderX = 0;
    oNewDiv.style.left = iNewSliderX + "px";
    oNewDiv.style.top = "0px";
    currDiv = (currDiv) ? 0 : 1;
    bSliderComplete = false;
    _slideLayer(sOldDiv,sNewDiv,sContainer,cDirection);
       
};

function _slideLayer(sOldDiv,sNewDiv,sContainer,cDirection) {
    
    var oContainer = document.getElementById(sContainer);
    var iContainerWidth = oContainer.offsetWidth;
    var oNewDiv = document.getElementById(sNewDiv);
    var oOldDiv = document.getElementById(sOldDiv);
    
    if(cDirection == "l") {
        iOldSliderX -= iSlideSpeed;
        iNewSliderX -= iSlideSpeed;
        if(iNewSliderX < 0) {
            iNewSliderX = 0;
            bSliderComplete = true;
            oContainer.removeChild(oOldDiv);
        }
    }
    else {
        iOldSliderX += iSlideSpeed;
        iNewSliderX += iSlideSpeed;
        if(iNewSliderX > 0) {
            iNewSliderX = 0;
            bSliderComplete = true;
            oContainer.removeChild(oOldDiv);
        }    
    }
    oOldDiv.style.left = iOldSliderX + "px";
    oNewDiv.style.left = iNewSliderX + "px";
    if(bSliderComplete == false) {
        setTimeout("_slideLayer('" + sOldDiv + "','" + sNewDiv + "','" + sContainer + "','" + cDirection +"')",iSlideInterval);
    }
};

function simpleSlideRight(sDivContainer,sDiv) {
    
    if(bSliderComplete == false) {
        setTimeout("simpleSlideRight('" + sDivContainer + "','" + sDiv + "')",100);
        return;
    }
    
    bSliderComplete = false;      
    iSimpleSliderX = 0;
    _simpleSlideRight(sDivContainer,sDiv);
};

function _simpleSlideRight(sDivContainer,sDiv) {
    
    var oDivContainer = document.getElementById(sDivContainer);
    var oDiv = document.getElementById(sDiv);
    var elementW = 275;
    
    iSimpleSliderX += iSlideSpeed;
    if(iSimpleSliderX > elementW) {
        bSliderComplete = true;
        bGoodbyeMsg = true;
        return;   
    }
    oDiv.style.left = iSimpleSliderX + "px";

        if(bSliderComplete == false) {
        setTimeout("_simpleSlideRight('" + sDivContainer + "','" + sDiv + "')",iSlideInterval);
    }
};
