


// browser detection
/*var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();*/

function showEmpPic(id)
{
	var image = document.getElementById("emp" + id)
	if(image){
		image.style.opacity = 1;
		image.style.mozOpacity = 1;
		image.style.filter = "alpha(opacity=100)";
	}
}

function coverEmpPic(id)
{	
	var image = document.getElementById("emp" + id)
	if(image){
		image.style.opacity = 0;
		image.style.mozOpacity = 0;
		image.style.filter = "alpha(opacity=0)";
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


function validate(form,findclass)
{
	var tag=document.body.getElementsByTagName('*');
	var errormsg = document.getElementById('errormsg')
	var txt = ''
	for(var i=0; i<tag.length; i++) 
	{
		if(tag[i].className == findclass)
			{
				//tag[i].style.className = 'ERROR'
					//confirm(tag[i].name)
				if(tag[i].value == '')
				{
					errormsg.style.display = "block"
					tag[i].style.border = '#C00 solid 3px'
					tag[i].focus();
					return false;
				}
			}
	}
	//sendForm()
}

function viewPress(id){
	
	window.location = "press.asp?id=" + id;
}



//Effect functions

var widthCount = 0;
var totalWidth = 0;
var opacityCount = 100;
var t;
//Side menu
var gblElement;
//Work examples
var gblElement2;


function navOut(id){
	if(gblElement != 'sub_' + id&&gblElement != id){
		//alert('fire');
		var hide = document.getElementById(gblElement);
		if(!hide){
			hide = document.getElementById("sub_" + gblElement);
		}
		if(document.getElementById('sub_'+id)){
			clearTimeout(t);	
						
			if(hide){hide.style.display = 'none';}
						
		
			var over = document.getElementById('sub_' + id);
			widthCount = 0;
			over.style.display = 'block';
	
				
			var a = getByClass("subtier");
			totalWidth = 0;
	
			
			
			//loop through all of the subtiers div and get an accurate width to loop to
			//not all browsers support getbyclassname, so make sure it the array is defined before we loop
			if(a){
				for( i=0; i<a.length;i++ ){
					totalWidth = totalWidth + a[i].offsetWidth;
					//alert('offestLoop ' + a[i].offsetWidth);
				}
			//less efficient loop for browsers that dont support getbyclassname
			}else{
				i = 0;
  				a = document.getElementsByTagName("div");
 				 while (element = a[i++]) {
    				if (element.className == "subtier") {
       					 totalWidth = totalWidth + a[i].offsetWidth;
      				}
    			}
			
			}
			
			
			//alert(over.offsetWidth);
			slideOut(id);
		
		}else{
			if(hide){
				hide.style.display = 'none';gblElement = '';
			}
		}
	} 	
	
}

function slideOut(element){
	
	gblElement = element;
	subNavDiv = document.getElementById("innerContainer" + element);
	subNavCell = document.getElementById("subLeft_" + element);
	
	widthCount = widthCount + 10;
	
	//set the new width value
	if(subNavDiv&&subNavCell){
		subNavDiv.style.width = widthCount + "px";
		subNavCell.style.width = widthCount + "px";
	
		//if we have not reached full width, then keep calling function and incrementing
		if(widthCount < (totalWidth + 10)){
			t = setTimeout("slideOut(gblElement);",.000000001);
		}
		//once we reach one then stop incrementing the width and return and reset the width value
		else{
			gblElement = "sub_" + element;
			clearTimeout(t);
			return;
		}
	}
	
	
}

function fadeIn(element){
	
	gblElement2 = element;
	image = document.getElementById(element);
	
	opacityCount = opacityCount + 5;
	if(opacityCount>100){opacityCount=100}
	
	if(image){
		//IE opacity
 		if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4){
    		image.style.filter = "alpha(opacity=" + opacityCount + ")";
		}
		//Normal opacity
		else{
			image.style.opacity = (opacityCount/100);
			image.style.mozOpacity = (opacityCount/100);
		}
	}
	
	if(opacityCount < 100){
		t = setTimeout("fadeIn(gblElement2);",10);
	}
	else{
		clearTimeout(t);	
	}
	
}

function fadeOut(element){
	gblElement2 = element;
	image = document.getElementById(element);
	
	
	opacityCount = opacityCount - 5;
	if(opacityCount<0){opacityCount=0}
	
	if(image){
		//IE opacity
 		if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4){
    		image.style.filter = "alpha(opacity=" + opacityCount + ")";
		}
		//Normal opacity
		else{
			image.style.opacity = (opacityCount/100);
			image.style.mozOpacity = (opacityCount/100);
		}

	}
	
	if(opacityCount > 0){
		t = setTimeout("fadeOut(gblElement2);",10);
	}
	else{
		//After the fade out has completed begin the ajax
		clearTimeout(t);
		//make sure ajax is supported
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
		
		//Get the current id
		var current = document.getElementById('currentWork');
		
		//Send http request
		var url="workExampleImage.asp?";
		url=url+"id=" + current.value;
		url=url+"&op=image&move=" + movement

		//Call the stateChangedImage function when the server side script responds
		xmlHttp.onreadystatechange=stateChangedImage;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
	}
	
	
}

//If the sidenav is showing this function hides the side navigation when your mouse goes over the body
function removeNav(){
	
	var remove = document.getElementById(gblElement);
	
	if(remove){
		if(remove.style.display!='none'){
			remove.style.display = 'none';
			gblElement = '';
		}
	}
	return;
}

function getByClass(theClass){
	
	var allDivTags = new Array();
	var allDivTags=document.getElementsByTagName("div");
	var tempArray = new Array();
	var tempCounter = 0;
	
	for (i=0; i<allDivTags.length; i++) {
		if(allDivTags[i].className == theClass){
			tempArray[tempCounter] = allDivTags[i];
			tempCounter++;
		}
	}
	
	return tempArray;
}




//AJAX functions for the work examples
var xmlHttp
var movement

function moveWorkExample(move){
	
	movement = move;
	
	//make sure the user is not trying to view the work example that is already visible
	var current = document.getElementById('currentWork');
	
	if(current.value!=movement){
		fadeOut('containerCenter');
		
		//Get the old nav
		var oldNav = document.getElementById("workNav" + current.value);
		
		//Remove the selected class from the old navigation
		oldNav.className = '';
	}
	
}

function stateChangedImage() { 
	if(xmlHttp.readyState==4){ 
		//update the images
		if(xmlHttp.responseText != ""){
			document.getElementById("ieSux").innerHTML = xmlHttp.responseText;
			//Make sure the element is opaque so we dont get a flicker
			var container = document.getElementById("containerCenter");
			
			//IE opacity
 			if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4){
    			container.style.filter = "alpha(opacity=0)";
			}
			//Normal opacity
			else{
				container.style.opacity = 0;
				container.style.mozOpacity = 0;
			}
			
			//update the bottom information
			moveInfo();
			
		}
		
	}
}

function moveInfo(){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var current = document.getElementById('currentWork');
	
	//Send http request
	var url="workExampleImage.asp?";
	url=url+"id=" + current.value;
	url=url+"&op=info&move=" + movement

	
	xmlHttp.onreadystatechange=stateChangedInfo;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
	
	
}


function stateChangedInfo(){
	if(xmlHttp.readyState==4){ 
		var image = document.getElementById("workInfo").innerHTML = xmlHttp.responseText;
		fadeIn('containerCenter');
		//update the id variable
		moveID();
	}
}

function moveID(){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var current = document.getElementById('currentWork');
	
	//Send http request
	var url="workExampleImage.asp?";
	url=url+"id=" + current.value;
	url=url+"&op=id&move=" + movement;
	
	xmlHttp.onreadystatechange=stateChangedID;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChangedID(){
	if(xmlHttp.readyState==4){
		//Get the old id
		var id = document.getElementById("currentWork");
		
		//Set the id value to the new id
		id.value = xmlHttp.responseText;
		
		//Add the selected class to the new navigation
		var newNav = document.getElementById("workNav" + xmlHttp.responseText);
		newNav.className = 'workNavSelected';
		
		//reset the image variable
		document.getElementById("currentImage").value = 1;
	}
}


//Function for changing the large image via clicking one of the thumbnails
function changeWorkImage(imageNumber){
	
	//Make sure the thumbnail that has been clicked is different that the image that is currently visible
	var currentImage = document.getElementById("currentImage");
	if(currentImage.value == imageNumber){
		return;
	}else{
		
		var oldImage = document.getElementById("workImage" + currentImage.value);
		var newImage = document.getElementById("workImage" + imageNumber);
		
		oldImage.style.display = "none";
		newImage.style.display = "block";
		currentImage.value = imageNumber;
	}
		
	
	
	
}


//Function for the rollovers on the our clients page
function changeClientImage(id){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	//Get current value
	var current = document.getElementById("currentClient");
	
	if(current.value!=id){
		
		//update css classes...
		//get old client link
		var oldClient = document.getElementById("client" + current.value);
		oldClient.className = null;
		//get new client link
		var newClient = document.getElementById("client" + id);
		newClient.className = 'selected';
		//update value
		current.value = id;
	
		//Send http request
		var url="clientLogo.asp?";
		url=url+"id=" + id;
	
		xmlHttp.onreadystatechange=stateChangedClientImage;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function stateChangedClientImage(){
	if(xmlHttp.readyState==4){
		document.getElementById("clientLogo").src = "/imagesDir/" + xmlHttp.responseText;
		
	}
	
}

function showAlbumPic(id){
	
	hidePhotos('selectedPhoto');
	var showPic = document.getElementById("pic_" + id);	
	if(showPic){
		showPic.className = 'selectedPhoto';
	}
	hideCaptions('selectedCaption');
	var showCaption = document.getElementById("caption_" + id);
	if(showCaption){
		showCaption.className = 'selectedCaption';
	}
}

/*function hideAlbumPic(id){
	
	var hidePic = document.getElementById("pic_" + id);	
	if(hidePic){
		hidePic.className = 'photo';
	}
	var hideCaption = document.getElementById("caption_" + id);
	if(hideCaption){
		hideCaption.className = 'caption';
	}
}*/


function changeAlbum(id){
	if(document.getElementById("album_" + id).className == 'selectedAlbum'){
		alert('already');
		return;
	}
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	xmlHttp2=GetXmlHttpObject();
	if(xmlHttp==null||xmlHttp2==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var url="changePhotoAlbum.asp";
	url+="?id=" + id;
	var url2 = "changePhotoAlbumThumbs.asp";
	url2+="?id=" + id;
	
	xmlHttp.onreadystatechange=stateChangedPhotoAlbumBig;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	xmlHttp2.onreadystatechange=stateChangedPhotoAlbumThumbs;
	xmlHttp2.open("GET",url2,true);
	xmlHttp2.send(null);
	
}

function stateChangedPhotoAlbumBig(){
	if(xmlHttp.readyState==4){
		//alert(xmlHttp.responseText);
		document.getElementById("photoFrame").innerHTML = xmlHttp.responseText;
	}	
}

function stateChangedPhotoAlbumThumbs(){
	if(xmlHttp2.readyState==4){
		//alert(xmlHttp2.responseText);
		document.getElementById("copybox").innerHTML = xmlHttp2.responseText;
	}
}



function hidePhotos(theClass) {
	//Create an array 
	var allPageTags = new Array(); 
	//Populate the array with all the page tags
	var allPageTags=document.getElementsByTagName("div");
	//Cycle through the tags using a for loop
	for (i=0; i<allPageTags.length; i++) {
		//Pick out the tags with our class name
		if (allPageTags[i].className==theClass) {
			//Manipulate this in whatever way you want
			allPageTags[i].className='photo';
		}
	}
}

function hideCaptions(theClass) {
	//Create an array 
	var allPageTags = new Array(); 
	//Populate the array with all the page tags
	var allPageTags=document.getElementsByTagName("div");
	//Cycle through the tags using a for loop
	for (i=0; i<allPageTags.length; i++) {
		//Pick out the tags with our class name
		if (allPageTags[i].className==theClass) {
			//Manipulate this in whatever way you want
			allPageTags[i].className='caption';
		}
	}
}
