// JavaScript Document
var pFlag = window.print;

function lightboxPage(){

/*var scrollY = 0;
var scrollX = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
	scrollX = document.documentElement.scrollLeft;
    scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && document.body.scrollTop ) {
	  scrollX = document.body.scrollLeft;
    scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
	  scrollX = window.pageXOffset;
    scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
	scrollX = window.scrollX;
    scrollY = window.scrollY;
  }
  
  */
//alert(scrollY);
//	document.getElementById('lightbox').style.top = scrollY+'px';
//	document.getElementById('lightbox').style.left = scrollX+'px';
var x,y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
	x = document.body.scrollWidth;
	y = document.body.scrollHeight;
}
else // Explorer Mac;
     //would also work in Explorer 6 Strict, Mozilla and Safari
{
	x = document.body.offsetWidth;
	y = document.body.offsetHeight;
}
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
if(myHeight-3 > y){
	y = myHeight-3;	
}
	document.getElementById('lightbox').style.width = x+"px";
	document.getElementById('lightbox').style.height = y+"px";
	document.getElementById('lightbox').style.display = 'block';
	var so = new SWFObject("../gfx/tools/lightbox.swf", "preloader", "100%", "100%", "8", "#FFFFFF", true);
	so.addParam("wmode", "transparent");
	so.addParam("scale", "exactfit"); 
	so.write("lightbox")
	window.onfocus = window.onscroll = function(){
		window.onfocus = null;
		window.onscroll = null;
		document.getElementById('lightbox').style.display = 'none';
	}
}

function printPage(){
  if (pFlag){
	window.print();
  }else if(navigator.userAgent.indexOf('Mac') != -1){
    alert('To print this page, press Command+P on your keyboard\nor choose \'print\' from your browser\'s File Menu.');
  }else{
    alert('To print this page, press Ctrl+P on your keyboard\nor choose \'print\' from your browser\'s File Menu.');
  }
}
pageLoaded = false;

function showTitle(name){
	if(pageLoaded === true){
var myString = new String(name);

document.getElementById('popOver').style.display = 'block';
document.getElementById('popOverContent').innerHTML = document.getElementById(myString).innerHTML;
var oLink = document.getElementById(name);
var oLinkWid = parseInt(oLink.offsetWidth);
var oLinkHei = parseInt(oLink.offsetHeight);
  if( oLink.offsetParent ) {
  	for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
    	posX += oLink.offsetLeft;
    	posY += oLink.offsetTop;
    }
  }
  document.getElementById('popOver').style.left = eval(posX+oLinkWid-1)+'px';
  document.getElementById('popOver').style.top = eval(posY+oLinkHei)+'px';
}
}

function hideTitle(){
	if(pageLoaded === true){
		document.getElementById('popOverContent').innerHTML = "";
		document.getElementById('popOver').style.display = 'none';
	}
}


zoomObj = new Array();

function ZoomObject(target, src, type, regWid, regHei, myLrgWid, myLrgHei, anchorId){
	this.target = target;
	this.lrgWid = myLrgWid;
	this.lrgHei = myLrgHei;
	this.regWid = regWid;
	this.regHei = regHei;
	this.active = 0;
	addAry = new Array(src+"."+type, src+"_l."+type, anchorId, false);
	this.mult = [addAry];
	this.addZoom = function(src, type, anchorId){
		addAry = new Array(src+"."+type, src+"_l."+type, anchorId, false);
		this.mult.push(addAry);
	}
	zoomObj.push(this);
}

function hideDiv(){
	document.getElementById('zoomTool').style.display = 'none';
}

curZoomObj = "";

function loadZoomImg(myObj, myIndex){
	regWid = myObj.regWid;
	regHei = myObj.regHei;
	lrgWid = myObj.lrgWid;
	lrgHei = myObj.lrgHei;

	document.images['fullZoomImg'].src = myObj.mult[myIndex][0];
	document.images['fullZoomImg'].width = myObj.lrgWid;
	document.images['fullZoomImg'].height = myObj.lrgHei;
	
	myZoomImg2 = new Image();
	myZoomImg2.src = myObj.mult[myIndex][1];
	curZoomObj = myObj;
	curZoomIndex = myIndex;
	zoomLoadInt = setInterval("testLoad()", 200);
	//onload fails in certain browsers when image is cached
}

function testLoad(){
	if(myZoomImg2.complete === true){
	clearInterval(zoomLoadInt);
	myObj = curZoomObj;
	myObj.mult[curZoomIndex][3]=true;
	swapImages();
	}
}


function swapImages(){
	document.images['fullZoomImg'].src = myZoomImg2.src;
	document.getElementById('zoomLoadW').style.display = 'none';
}

function switchZoom(myObj, myIndex){
	for(i=0; i<myObj.mult.length; i++){
		document.getElementById(myObj.mult[i][2]).className = 'zoomBtn';	
	}
	document.getElementById(myObj.mult[myIndex][2]).className = 'zoomBtnSel';
	document.myElement.src = myObj.mult[myIndex][0];
	myObj.active = myIndex;
	if(myObj.mult[myIndex][3] === false){
		document.getElementById('zoomLoadW').style.display = 'block';
		loadZoomImg(myObj, myIndex);
	} else {
		myZoomImg2.src = myObj.mult[myIndex][1];
		swapImages();
	}
}

activeZoom = "myElement";
//c=0;
function doSomething(evt){
if(evt){posX = evt.pageX; posY = evt.pageY;}else if(window.event.clientX){posX = window.event.clientX; posY = window.event.clientY;}
/*document.getElementById('zoomCover').onmousemove = function(){


document.getElementById('homeBtn').innerHTML = c;
c++;
}*/

		/*
		//For multiple instances
		for(var i=0; i<zoomObj.length; i++){
			if(this.id == zoomObj[i].target && document.images['fullZoomImg'].src !== zoomObj[i].mult[zoomObj[i].active][1] && zoomObj[i].mult[zoomObj[i].active][3] === true){
				document.images['fullZoomImg'].src = zoomObj[i].mult[zoomObj[i].active][1];
				document.images['fullZoomImg'].width = zoomObj[i].lrgWid;
				document.images['fullZoomImg'].height = zoomObj[i].lrgHei;
				activeZoom = this.id;
			} else if (this.id == zoomObj[i].target && document.images['fullZoomImg'].src !== zoomObj[i].mult[zoomObj[i].active][1]) {
				
				activeZoom = this.id;
			}
		}
			curZoomObj = this;
		*/





 var oLink = document.getElementById(activeZoom);
  if( oLink.offsetParent ) {
  	for( var imgX = 0, imgY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
    	imgX += oLink.offsetLeft;
    	imgY += oLink.offsetTop;
    }
  }   

if (window.event){
	posXRel = window.event.offsetX;
	posYRel = window.event.offsetY;
	posY += document.documentElement.scrollTop;
	posYRel -= document.documentElement.scrollTop;
} else if (evt.target) {
	var coords = {x: 0, y: 0 };
	var el = evt.target;
	do {
 		coords.x += el.offsetLeft;
 		coords.y += el.offsetTop;
    }
    while ((el = el.offsetParent));
		
		posXRel = evt.clientX - coords.x;
		posYRel = evt.clientY - coords.y;
}
if(document.documentElement.scrollTop){
	posYRel += document.documentElement.scrollTop;
}
	 
	 if(posX < imgX || posX > eval(imgX+regWid) || posY < imgY || posY > eval(imgY+regHei)){ 
	// document.getElementById('homeBtn').innerHTML = "POSX"+posX+"    IMGX+WID"+eval(imgX+regWid);
	 
	 hideDiv(); } else {
		 if(document.getElementById('zoomTool').style.display !== 'block'){
			document.getElementById('zoomTool').style.display = 'block';
			document.getElementById('zoomTool').style.visibility = 'visible';
		}
	 position(posX, posY, posXRel, posYRel);
	 }		 
} 
function position(posX, posY, posXRel, posYRel){
 var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Not IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	var store = posX+295;

	var myOffset = -5;
	var myOffsetY = -5;
	if(store > myWidth){myOffset = store - myWidth;}
	var perWid = posXRel/regWid;
	var perHei = posYRel/regHei;
	var perTool = -5;
	
	document.getElementById('zoomTool').style.top = eval(posY-myOffsetY+3)+'px';
	document.getElementById('zoomTool').style.left = eval(posX-myOffset)+'px';

	
	var perX = lrgWid*perWid;
	perX = Math.round(eval((perX*-1)+125));
	
	var perY = lrgHei*perHei;
	perY = Math.round(eval((perY*-1)+125));
	document.getElementById('zoomImgSpan').style.left = perX+'px';
	document.getElementById('zoomImgSpan').style.top = perY+'px';
}


var newWindow = "";
function popUp(URL) {
	myString = new String(window.location);
		var result = '';
		var hitExtension = false;
		var numI = 0;
		for(var i=0; i<myString.length; i++) {
			var c = myString.charAt(i);
			if(c == '/'){numI++;}
		}
		var numI2 = 0;
		for(var i=0;i<=myString.length;i++) {
    		var c= myString.charAt(i);
			if(c == '/'){if(eval(numI-1) == numI2){break;}else{numI2++;}}
			result += c;
	  		}
var popTitle = document.myElement.alt+' Zoom - TWiseDesign.com';
if (!newWindow.closed && newWindow.location){newWindow.close();}
newWindow = window.open(result+"/popup.php?filePath="+myZoomImg2.src+"&docTitle="+popTitle, "myPop", "left=0, top=0, toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+eval(lrgWid+20)+",height="+eval(lrgHei+70)+"");
if (!newWindow.opener){newWindow.opener = self};
if (window.focus) {newWindow.focus();}
return false;
}


/* Begin CSS Swap*/

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function checkIt(string){ 
       return navigator.userAgent.toLowerCase().indexOf(string) + 1;  
} 

function setStyleSheet(){
	var cookie2 = readCookie("size");
	var size = cookie2 ? cookie2 : "14px";
	setBodySize(size);
}
function setBodySize(num){
	document.getElementsByTagName("BODY")[0].style.fontSize = num;
	document.getElementById('changeReg').className = 'changeA';
    document.getElementById('changeLrg').className = 'changeA';  
    document.getElementById('changeLgt').className = 'changeA';

	if(num == "14px"){document.getElementById('changeReg').className = 'changeASel';}
    else if(num == '16px'){document.getElementById('changeLrg').className = 'changeASel';}
	else if(num == '21px'){document.getElementById('changeLgt').className = 'changeASel';}
}
window.onunload = function(e) {
  createCookie("size", document.getElementsByTagName("BODY")[0].style.fontSize, 365);
pageLoaded = false;
}



/* Begin Form Handling */
	function sendAjax(targetForm, submitTo){
	urlString = "";
	target = document.getElementById("emailForm");
    for (var i = 0; i<target.elements.length; i++) {
	 	urlString += target.elements[i].name + "=" + target.elements[i].value;
		if(i < eval(target.elements.length -1 )){ urlString += "&";}
	  }
	 document.getElementById("emailWrap").innerHTML = "<div class='loadingAjax'></div>";
	 xmlhttpPost(urlString, submitTo);
	}
	
	
function xmlhttpPost(strURL, submitTo) {
	strURL = submitTo+"?"+strURL;
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
            updatepage(self.xmlHttpReq.responseText);
        }
    }

    self.xmlHttpReq.send(strURL);
}

function updatepage(stri){
	document.getElementById("emailWrap").innerHTML = stri;
}
function toggleSEHL(){
	document.getElementById('sehl').style.display = "none";
	var x = document.getElementsByTagName('span');
			for (var i=0;i<x.length;i++){
				if(x[i].className == "hl0" || x[i].className == "hl1" || x[i].className == "hl2" || x[i].className == "hl3" || x[i].className == "hl4"){x[i].className = 'sehlOff';}
	}
}

function changecss(theClass,element,value) {
	var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';''
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
		  alert(selectorText);
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;

	   }
	  }
	 }

}

function init(){
pageLoaded = true;
	var x = document.getElementsByTagName('a');
	for (var i=0;i<x.length;i++){
        if (x[i].getAttribute('type') == 'popup'){
                x[i].onclick = function () {
                        return popUp(this.href)
                }
        } else if (x[i].getAttribute('type') == 'externalpop'){
			x[i].target = "_blank"; 
			x[i].onmouseover = function () { if(showTitle){showTitle(this.id);} }
			x[i].onmouseout = function () {  if(hideTitle){hideTitle();} }
		}  else if (x[i].getAttribute('type') == 'pop'){
			x[i].onmouseover = function () {  if(typeof(showTitle=='function')){showTitle(this.id);} }
			x[i].onmouseout = function () { if(typeof(hideTitle=='function')){ hideTitle(); } }
		} else if (x[i].getAttribute('type') == 'external'){
			x[i].target = "_blank"; 
		}
	}
	
	for(var i=0; i<zoomObj.length; i++){
		loadZoomImg(zoomObj[i],0);
		//loadZoomImg(myObj, 0);	
	}
	if(zoomObj[0]){ document.onmousemove = doSomething; }
 setStyleSheet();
}

window.onload = init;