// JavaScript Document

// Copyright 2000-2009, DataCom/OTA, Inc.
        
// Setup
var theSImages = new Array()
theSImages[0] = "/images/index/eggS.jpg"
theSImages[1] = "/images/index/fishS.jpg"
theSImages[2] = "/images/index/glassS.jpg"
theSImages[3] = "/images/index/insectS.jpg"
theSImages[4] = "/images/index/lshoeS.jpg"
theSImages[5] = "/images/index/mshoeS.jpg"

var theMImages = new Array()
theMImages[0] = "/images/index/eggM.jpg"
theMImages[1] = "/images/index/fishM.jpg"
theMImages[2] = "/images/index/glassM.jpg"
theMImages[3] = "/images/index/insectM.jpg"
theMImages[4] = "/images/index/lshoeM.jpg"
theMImages[5] = "/images/index/mshoeM.jpg"

var theLImages = new Array()
theLImages[0] = "/images/index/eggL.jpg"
theLImages[1] = "/images/index/fishL.jpg"
theLImages[2] = "/images/index/glassL.jpg"
theLImages[3] = "/images/index/insectL.jpg"
theLImages[4] = "/images/index/lshoeL.jpg"
theLImages[5] = "/images/index/mshoeL.jpg"

online_on=new Image(70,70);
online_on.src="/images/small/menuonline_on.png";
video_on=new Image(70,70);
video_on.src="/images/small/menuvideo_on.png";
service_on=new Image(70,70);
service_on.src="/images/small/menuservice_on.png";
portfolio_on=new Image(70,70);
portfolio_on.src="/images/small/menuportfolio_on.png";
contact_on=new Image(70,70);
contact_on.src="/images/small/menucontact_on.png";

// Choose picture
function picPic() {
	var p = theSImages.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	preBuffer[i] = new Image()
	preBuffer[i].src = theSImages[i]
	}
	var whichImage = Math.round(Math.random()*(p-1));
	document.write('<div class="z_contentBoxSm"><p class="center"><a href="/small/"><img src="'+theSImages[whichImage]+'" alt="Small" id="small" onMouseOver="fadeOut(\'small\');" onMouseOut="fadeIn(\'small\');"></a></p></div>');
    document.write('<div class="z_contentBoxMed"><p class="center"><a href="/medium/"><img src="'+theMImages[whichImage]+'" alt="Medium" id="medium" onMouseOver="fadeOut(\'medium\');" onMouseOut="fadeIn(\'medium\');"></a></p></div>');
    document.write('<div class="z_contentBoxLg"><p class="center"><a href="/large/"><img src="'+theLImages[whichImage]+'" alt="Large" id="large" onMouseOver="fadeOut(\'large\');" onMouseOut="fadeIn(\'large\');"></a></p></div>');
}

// Picture fader
function fadeOut (pic, pos) {
	var obj = document.getElementById(pic);
	var pos = pos <= 100 ? pos : 100;
	var css = eval(pos*.01);
	obj.style.opacity = css;
	obj.style.filter = "alpha(opacity="+pos+")";
	pos = pos-5;
	if (pos>-1) { setTimeout(function(){fadeOut(pic, pos)}, 1); }	
}

function fadeIn (pic, pos) {
	var obj = document.getElementById(pic);
	var pos = pos <= 100 ? pos : 0;
	var css = eval(pos*.01);
	obj.style.opacity = css;
	obj.style.filter = "alpha(opacity="+pos+")";
	pos = pos+5;
	if (pos<101) { setTimeout(function(){fadeIn(pic, pos)}, 1); }	
}

// Set cookies
function setCookie(theName, theValue) {
	var expDate = new Date;
	expDate.setMonth(expDate.getMonth()+6);
	document.cookie = theName + "=" + theValue +";path=/;expires=" + expDate.toGMTString() +";"
}

// Read cookies
function getCookie(cookieName) {
  var cookieData = document.cookie;
  var i = 0;
  var cEnd;
  while (i < cookieData.length) {
    var j = i + cookieName.length;
    if (cookieData.substring(i, j) == cookieName) {
      cEnd = cookieData.indexOf(";", j);
      if (cEnd == -1)
        cEnd = cookieData.length;
      return decodeURIComponent(cookieData.substring(j + 1, cEnd));
    }
    i++;
  }
  return "";
}

// Delete Cookie
function deleteCookie (name, path, domain) {
	if (getCookie(name))
    	document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// Check and set current type size
function typeSize() {
	var setTypeSize = getCookie('aSize');
	if(setTypeSize == "smallt") { setSize('smallt'); }
	if(setTypeSize == "mediumt") { setSize('mediumt'); }
	if(setTypeSize == "larget") { setSize('larget'); }
	if(setTypeSize == "") {
		setCookie('aSize','smallt');
		setSize('smallt');
	}
}

// Change type size
function setSize(size) {
	document.getElementById('smallt').disabled = true;
	document.getElementById('mediumt').disabled = true;
	document.getElementById('larget').disabled = true;
	document.getElementById(size).disabled = false;
	setCookie('aSize', size);
}

function setPage(currentPage) {
	setCookie('cPage', currentPage);
	try { document.getElementById(currentPage).src=eval(currentPage + "_on.src"); }
	catch(e) { }
}

//Find ans set column heights
function setLayout() {
	var maxHt = 0;
	
	var leftHt = leftBox()
	var centerHt = centerBox();
	var rightHt = rightBox();
	
	maxHt = Math.max(eval(leftHt),eval(centerHt));
	maxHt = Math.max(eval(maxHt),eval(rightHt));
	
	if (leftHt != 0) {document.getElementById('leftCol').style.height=eval(maxHt-150) + "px"; }
	if (centerHt != 0) { document.getElementById('centerCol').style.height=eval(maxHt-150) + "px";	 }
	if (rightHt != 0) { document.getElementById('rightCol').style.height=eval(maxHt) + "px"; }
}

function leftBox() {
	var myLeft = document.getElementById('leftCol');
	try { return (myLeft.offsetHeight - 2); }
	catch(err) { return (0); }
}

function centerBox() {
	var myCenter = document.getElementById('centerCol');
	try { return (myCenter.offsetHeight - 2); }
	catch(err) { return (0); } 
}

function rightBox() {
	var myRight = document.getElementById('rightCol');
	try { return (myRight.offsetHeight - 2); }
	catch(err) { return (0); }
}

// Apple icon anumation
function getBig (id, pic, pos) {
	var runIt = getCookie('cPage');
	if (runIt != pic) {
	document.getElementById(id).style.color='#990000';
	var obj = document.getElementById(pic);
	var pos = pos <= 125 ? pos : 70;
	var css = eval(pos+5);
	obj.style.width = css + "px";
	obj.style.height = css + "px";
	pos = pos+5;
	if (pos<125) { setTimeout(function(){getBig(id, pic, pos)}, 1); }	
	}
}

function getSmall (id, pic, pos) {
	var runIt = getCookie('cPage');
	if (runIt != pic) {
	document.getElementById(id).style.color='#708580';
	var obj = document.getElementById(pic);
	var pos = pos <= 125 ? pos : 125 ;
	var css = eval(pos-5);
	obj.style.width = css + "px";
	obj.style.height = css + "px";
	pos = pos-5;
	if (pos>70) { setTimeout(function(){getSmall(id, pic, pos)}, 1); }
	}
}

// Show/hide
function sh(theItem) {
	if ( document.getElementById(theItem).style.display == "block") {
	  document.getElementById(theItem).style.display = "none";
	} else {
	  document.getElementById(theItem).style.display = "block";
	}
}

// Open Files
function openFile(theFile) {
    window.open (theFile);
}

function openFileA(theFile, theWindow, theBar, theSize, theWidth, theHeight) {
    window.open (theFile, theWindow,"status=no,location=no,toolbars="+theBar+",menubar="+theBar+",directories=no,scrollbars=yes,resizable="+theSize+",width="+theWidth+",height="+theHeight);
}

// AJAX File Request
function getFile(theFile, theDiv) {
	var pageReq = false;
	
    if (window.XMLHttpRequest) {
        pageReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
		try {
			pageReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				pageReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				pageReq = false;
			}
		}
	}
	
    pageReq.open('GET', theFile, true);
    pageReq.onreadystatechange = function() {
        if (pageReq.readyState == 4) {
			document.getElementById(theDiv).innerHTML = pageReq.responseText;
		}
    }
    pageReq.send(null);
}

//Process Forms
function sendForm(theCGI, theQuery, theDiv) {
	var pageReq = false;
	
    if (window.XMLHttpRequest) {
        pageReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
		try {
			pageReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				pageReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				pageReq = false;
			}
		}
	}
	
    pageReq.open('POST', theCGI, true);
    pageReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    pageReq.onreadystatechange = function() {
        if (pageReq.readyState == 4) {
			document.getElementById(theDiv).innerHTML = pageReq.responseText;
            //updatepage(pageReq.responseText);
        }
    }
    pageReq.send(eval(theQuery)());
	document.getElementById(theDiv).innerHTML = "<h1 id=\"bfm\">Sending . . . </h1>";
}

// /contactUs.shtml form
function em() {
    var form = document.forms['contactUs'];
    var fn = form.Name.value;
    var em = form.Email.value;
	var ph = form.Phone.value;
    var fm = form.Message.value;
    qstr = 'Name=' + escape(fn) + '&Email=' + escape(em) + '&Phone=' + escape(ph) + '&Message=' + escape(fm);
    return qstr;
}

// blog visitor comment form
function bc() {
	var bform = document.forms['blogComment'];
	var ce = bform.Email.value;
	var cn = bform.Name.value;
	var ct = bform.Comments.value;
	qstr = 'Email=' + escape(ce) + '&Name=' + escape(cn) + '&Datestamp=d&Comments=' + escape(ct);
	return qstr;
}

