﻿
function setGalleryImage(btnFirePopup, imgLarge, strUrl, intImage, intTotal){
       
    var btnFirePopup=document.getElementById? document.getElementById(btnFirePopup) : eval('document.all.') + btnFirePopup;
    var imgLarge=document.getElementById? document.getElementById(imgLarge) : eval('document.all.') + imgLarge;
    var labCaption=document.getElementById? document.getElementById(labCaption) : eval('document.all.') + labCaption;
    
    var btnPrev=document.getElementById? document.getElementById('btnPrev') : eval('document.all.btnPrev');
    var btnNext=document.getElementById? document.getElementById('btnNext') : eval('document.all.btnNext');
    
    var prefix = imgLarge.id.substr(0,imgLarge.id.indexOf("imgLarge"));
    var intPrev = intImage-1;
    var intNext = intImage+1;
    
    var imgThis = document.getElementById? document.getElementById(prefix + 'img' + intImage) : eval(prefix + 'img' + intImage);
    var imgPrev = document.getElementById? document.getElementById(prefix + 'img' + intPrev) : eval(prefix + 'img' + intPrev);
    var imgNext = document.getElementById? document.getElementById(prefix + 'img' + intNext) : eval(prefix + 'img' + intNext);  
    
    if (intImage == 1){
        btnPrev.style.display = 'none';
    } else {   
        btnPrev.style.display = 'inline';
        btnPrev.onclick = new Function("setGalleryImage('" + btnFirePopup.id + "', '" + imgLarge.id + "', '" + imgPrev.src + "', " + eval(intImage-1) + "," + intTotal + ");");
    }
    if (intImage == intTotal){
        btnNext.style.display = 'none';
    } else {   
        btnNext.style.display = 'inline';
        btnNext.onclick = new Function("setGalleryImage('" + btnFirePopup.id + "', '" + imgLarge.id + "', '" + imgNext.src + "', " + eval(intImage+1) + "," + intTotal + ");");
    }
    
    imgLarge.src = "loading.png";
    imgLarge.alt = "Just loading it up for you!"
    imgLarge.title = "Just loading it up for you!"
       
    imgLarge.src = strUrl;
    imgLarge.alt = imgThis.alt;
    imgLarge.title = imgThis.alt;
    //labCaption.innerHTML = strCaption;
    pausecomp(1000);
    btnFirePopup.click();
}

function xsetLargeGalleryImage(btnFirePopup, imgLarge, strUrl, strAlt, labCaption, strCaption){
    
    var btnFirePopup=document.getElementById? document.getElementById(btnFirePopup) : eval('document.all.') + btnFirePopup;
    var imgLarge=document.getElementById? document.getElementById(imgLarge) : eval('document.all.') + imgLarge;
    var labCaption=document.getElementById? document.getElementById(labCaption) : eval('document.all.') + labCaption;
    
    imgLarge.src = "loading.png";
    imgLarge.alt = "Just loading it up for you!"
    imgLarge.title = "Just loading it up for you!"
       
    imgLarge.src = strUrl;
    imgLarge.alt = strAlt;
    imgLarge.title = strAlt;
    labCaption.innerHTML = strCaption;
    pausecomp(1000);
    btnFirePopup.click();
}

function pausecomp(millis)
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 

/* stuff for the scrolling div */

var iedom=document.all||document.getElementById
var scrollySpeed=3
var moving=""

var actualwidth=''
var scrolly
var isLoaded=0

function goLeft() {
    if (isLoaded) {
        moving="lefty"
        if (iedom&&parseInt(scrolly.style.left)<0) {
            scrolly.style.left=parseInt(scrolly.style.left)+scrollySpeed+"px"
        }
    }
    lefttime=setTimeout("goLeft()",10)
}

function goRight() {
    if (isLoaded==0) {doIt()}
    
    if (isLoaded) {
        moving="righty"
        if (iedom&&parseInt(scrolly.style.left)>(menuwidth-actualwidth)) {
            scrolly.style.left=parseInt(scrolly.style.left)-scrollySpeed+"px"
        }
    }
    righttime=setTimeout("goRight()",10)
}

function stopIt(){
    moving=""
    if (window.lefttime) clearTimeout(lefttime)
    if (window.righttime) clearTimeout(righttime)
}

function doIt(){
    var leftArrow=document.getElementById? document.getElementById("imgLeftArrow") : document.all.imgLeftArrow;
    var rightArrow=document.getElementById? document.getElementById("imgRightArrow") : document.all.imgRightArrow;
        
    if (iedom){
        var crossmain=document.getElementById? document.getElementById("outerContainer") : document.all.outerContainer
        menuwidth=parseInt(crossmain.style.width)
        scrolly=document.getElementById? document.getElementById("imageGallery") : document.all.imageGallery
        actualwidth=document.all? scrolly.offsetWidth : document.getElementById("imageContainer").offsetWidth
    }
    isLoaded=1
   
    if (actualwidth==0){
        isLoaded=0;
        leftArrow.style.display = 'block';
        rightArrow.style.display = 'block';
    }
    if(actualwidth > menuwidth){
        leftArrow.style.display = 'block';
        rightArrow.style.display = 'block';
    }
        
}

/* */

function changeImage(strImage, strTaken, strAlt){
    var theImage=document.getElementById? document.getElementById("imgLarge") : document.all.imgLarge;
    var spanImgTaken=document.getElementById? document.getElementById("spanImgTaken") : document.all.spanImgTaken;
    
    theImage.src = strImage;
    theImage.alt = strAlt;
    theImage.title = strAlt;
    
    spanImgTaken.innerHTML  = strTaken;
}

function changeColor(){
    var theColor1=document.getElementById? document.getElementById("txtColor1") : document.all.txtColor;   
    var theColor2=document.getElementById? document.getElementById("txtColor2") : document.all.txtColor;   
        
    changecss('.leftNav a', 'color', theColor1.value)
    
    changecss('.bodyContent', 'background-color', theColor2.value)
    changecss('.header', 'background-color', theColor2.value)
    changecss('.footer', 'background-color', theColor2.value)
}

function changecss(theClass,element,value) {
//Last Updated on May 21, 2008
//documentation for this script at
//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 var added = false;
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
    if(document.styleSheets[S][cssRules][R].style[element]){
    document.styleSheets[S][cssRules][R].style[element] = value;
    added=true;
	break;
    }
   }
  }

  if(!added){
  if(document.styleSheets[S].insertRule){
		  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
		} else if (document.styleSheets[S].addRule) {
			document.styleSheets[S].addRule(theClass,element+': '+value+';');
		}
  }
 }
}
