// JavaScript Document

//BROWSER SNIFF
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isDHTML = (isIE5 || isNS6);
var isPc = navigator.userAgent.indexOf("Windows") != -1;
var isMac = !isPc;

var obj = null;
var thePics = new Array();

thePics = new Array("nav_company","nav_case","nav_portfolio","nav_kitchens","nav_baths","nav_other","nav_tile","nav_fireplaces","nav_decks","nav_arbors","nav_exteriors","nav_cs_rissman","nav_cs_sado","nav_cs_ruth","nav_cs_fetto","nav_cs_brown","num_plus","num_1","num_2","num_3","num_4","num_5","num_6","num_7","num_8","num_9","num_10","arrow_prev","arrow_next","b_closesquare","nav_co_philosophy","nav_co_background","nav_co_personnel","nav_co_comfort","nav_co_building","nav_copy_duuplex","b_arrow_left","b_arrow_right","nav_copy_duuplex","nav_contact");

function swap(name,state) {
    if(thePics[name+state] && thePics[name+state].complete) {
        document.images[name].src = thePics[name+state].src;
    }
}

function preloadPics(thePics) {
	for (i=0;i<thePics.length;i++){
		thePics[thePics[i]] = new Image();
		thePics[thePics[i]].src = 'images/'+thePics[i]+'.gif';
		thePics[thePics[i]+'_on'] = new Image();
		thePics[thePics[i]+'_on'].src = 'images/'+thePics[i]+'_on.gif';
	}
}

preloadPics(thePics);

var thisPic = 0;

function picMainChange(picName,picNum) {

	var prevPic = thisPic - picNum;
	
    if (document.images)
        document.picMain.src = 'images/pic_'+picName+'_'+picNum+'_main.jpg';
		
		if (isIE4==true){
		obj = eval('document.all.portpic' + picNum + '.style');
        	obj.visibility = 'visible';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<7;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=picNum && (obj = eval('document.all.portpic' + i + '.style'))!=null){
					//obj = eval('document.all.pic' + i);
        			obj.visibility = 'hidden';
        		}
        	}
	} else if (isIE5==true){
        	obj = eval('document.all.portpic' + picNum);
        	obj.style.visibility = 'visible';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<7;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=picNum && (obj = eval('document.all.portpic' + i))!=null){
					//obj = eval('document.all.pic' + i);
        			obj.style.visibility = 'hidden';
        		}
        	}
   	} else if (isNS6==true){
        	obj = document.getElementById('portpic' + picNum);
        	obj.style.visibility = 'visible';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<7;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=picNum && (obj = document.getElementById('portpic' + i))!=null){
					//obj = eval('document.all.pic' + i);
        			obj.style.visibility = 'hidden';
        		}
        	}
    	}
}

var numCSPics = new Array();

numCSPics = new Array("num_plus","num_1","num_2","num_3","num_4","num_5","num_6","num_7","num_8","num_9","num_10");

function swapCS(name,state) {
    if(numCSPics[name+state] && numCSPics[name+state].complete) {
        document.images[name].src = numCSPics[name+state].src;
    }
}

function preloadPicsCS(numCSPics) {
	for (i=0;i<numCSPics.length;i++){
		numCSPics[numCSPics[i]] = new Image();
		numCSPics[numCSPics[i]].src = 'images/'+numCSPics[i]+'.gif';
		numCSPics[numCSPics[i]+'_on'] = new Image();
		numCSPics[numCSPics[i]+'_on'].src = 'images/'+numCSPics[i]+'_on.gif';
	}
}

preloadPicsCS(numCSPics);

function picCSChange(name,num) {
	var obj = null;
        document.picMain.src = 'images/pic_cs_'+name+'_'+num+'_main.jpg';
		//numCSPics[numCSPics[num]] = new Image();
		//numCSPics[numCSPics[num]].src = 'images/'+numCSPics[num]+'_on.gif';
		//alert(numCSPics[numCSPics[num]].src)
		document.links[7].href = 'javascript:popWin("cs_'+name+'_popup",'+num+')';
		document.links[8].href = 'javascript:popWin("cs_'+name+'_popup",'+num+')';

		if (isIE4==true){
		obj = eval('document.all.num_' + num + '.style');
				numCSPics[numCSPics[num]] = new Image();
				numCSPics[numCSPics[num]].src = 'images/'+numCSPics[num]+'_on.gif';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<numCSPics.length;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=num && (obj = eval('document.all.num_' + i + '.style'))!=null){
					numCSPics[numCSPics[i]] = new Image();
					numCSPics[numCSPics[i]].src = 'images/'+numCSPics[i]+'.gif';
        		}
        	}
	} else if (isIE5==true){
        	obj = eval('document.all.num_' + num);
				numCSPics[numCSPics[num]] = new Image();
				numCSPics[numCSPics[num]].src = 'images/'+numCSPics[num]+'_on.gif';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<numCSPics.length;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=num && (obj = eval('document.all.num_' + i))!=null){
					numCSPics[numCSPics[i]] = new Image();
					numCSPics[numCSPics[i]].src = 'images/'+numCSPics[i]+'.gif';
        		}
        	}
   	} else if (isNS6==true){
        	obj = document.getElementById('num_' + num);
				numCSPics[numCSPics[num]] = new Image();
				numCSPics[numCSPics[num]].src = 'images/'+numCSPics[num]+'_on.gif';
			//###################################################
        	//TURN OFF ALL OTHERS
        	//loop through all pics
        	for(i=1;i<numCSPics.length;i++) {
        		//if this one is NOT the one we are turning on AND if there is indeed a pic at this number, turn off (hide) this description
        		if(i!=num && (obj = document.getElementById('num_' + i))!=null){
					numCSPics[numCSPics[i]] = new Image();
					numCSPics[numCSPics[i]].src = 'images/'+numCSPics[i]+'.gif';
        		}
        	}
    	}
}

function popWin(location,thisNum) { 
	var dx=500;
	var dy=560;

	var w = window.open(location+'.htm?'+thisNum, 'popup', 'width=' + dx + ',height=' + dy + ',status=yes,resizable=yes,menubar=no,location=no,scrollbars=no,toolbar=no');
	w.focus();
}