var inter = null;
var currentRange =0;
var ack;
var menu;
var winHeight;
var winWidth;
var selectedbullet=null;
var origincolorbullet;
var currentmenuid=-1;
var currentsubmenuid=-1;
var announce = null;
var areas = new Array("header","menu","casimage","casmovie","castitle","body","casworldpicture");
var contents = new Array("caswebhead","casmenu","casimage","casmovie","castitle","casbody","casworldpicture");	
var obj1;	
	
	window.onresize = doresize;
	function sizeforeground(width,height,forcesize)
	{
		
		var obj1 = document.getElementById("picture");
		obj1.style.height = height +"px";
		if((!document.getElementById("forepict"))&&(forcesize==0))
		{
			
			obj1.style.width = 50+"px"
		}
		else
		{
			
			obj1.style.width = width+"px";
		}
	}
	
	
	function doresize()
	{
		{
		
			setFooterloc();
			if (winHeight != getHeight())
			{
				setPageHeight();
				winHeight = getHeight();
			}
			if(winWidth!=getWidth())
			{
				setPageWidth(-1);
				winWidth = getWidth();
			}
			reloadfunc();
		}
	}
	
	function announcerotate(timespan)
	{
		
		if(!announce)
		{
			
			//getHtml("get","","includes/announce.asp?ID="+document.getElementById("currentAnnounce").value,"blendTrans","logospace");
			announce =setInterval("announcements()",timespan);
			
		}
	}
	
	function announcements()
	{
		var announceid =document.getElementById("currentannounce").value
		
		getHtml("get","","includes/casannounce.asp?ID="+(announceid),"blendTrans","announce");
		
	}
	
	function startrotate(i,timespan)
	{
		var quoteid = document.getElementById("currentquote").value
		if (!menu)
			menu = i;
		if(( menu !=i) && (inter!=null))
		{
			
			menu = i;
			stoprotate();
		}
		if(!inter)
		{
			getHtml("get","","includes/changeForeGroundimage.asp?menu="+i+"&ID="+(quoteid-1),"blendTrans","picture");
			inter =setInterval('rotateinfo('+i+')',timespan);
			
		}
	}
	
	function rotateinfo(id)
	{
		
		
		/*var obj = document.getElementById("quote");*/
		var quoteid = document.getElementById("currentquote").value
		
		
		getHtml("get","","includes/changeForeGroundimage.asp?menu="+id+"&ID="+quoteid,"blendTrans","picture");
		getHtml("get","","includes/quote.asp?menu="+id+"&ID="+quoteid,"blendTrans","quote");
		/*if (items ==2)
		{
			var obj1 = document.getElementById("picture"); 
			getHtml("get","","includes/picture.asp?ID="+document.getElementById("currentpicture"),"","picture");	
		}*/
	}
	
	function stoprotate()
	{
		
		clearInterval(inter);
		inter = null;
	}
	
	function resetpage()
	{
		for(var i=0;i<8;i++)
		{
			getHtml("get","","includes/"+contents[i]+".asp","",areas[i]);
		}
	}
	
	function stopinsanity()
	{
		clearInterval(inter);
	}	
		
	function doint()
	{
		inter = setInterval('randomareas()',200);
		
	}
	
	function randomareas()
	{
		
		for (var my =0; my<8;my++)
		{
			var i=Math.floor(Math.random()*6);
			var j=Math.floor(Math.random()*6);
			getHtml("get","","includes/"+contents[i]+".asp","",areas[j]);
		}
	}
	
	function changecaption(wH)
	{
		
		var left = document.getElementById("mainbody").offsetLeft;
		if(wH == 0)
		{

			document.getElementById("caption").style.fontSize = "50px";
			document.getElementById("caption").style.left = left + 200+"px";	
			
		}
		else if(wH == 1)
		{

			document.getElementById("caption").style.fontSize = "40px";
			document.getElementById("caption").style.left = left + 175+"px";	
			
		}
		else if(wH == 2)
		{
			
			document.getElementById("caption").style.fontSize = "30px";
			document.getElementById("caption").style.left = left + 150+"px";	
			
		}
		else
		{
			
			document.getElementById("caption").style.fontSize = "20px";
			document.getElementById("caption").style.left = left + 75+"px";	
			
		}
				
	}

	function changeImage(wH)
	{
		//alert("changeimage");
		if(wH != currentRange)
			if (wH ==0)
			{
				
				changecaption(0);
				if (document.getElementById("image1"))
					document.getElementById("casbody").style.background = "url("+document.getElementById("image1").value+") no-repeat";	
				else
				{
					document.getElementById("casbody").style.background = "";
				}
				currentRange = 0;
			}
			else if (wH ==1)
			{
				
				changecaption(1);
				if (document.getElementById("image1"))
					document.getElementById("casbody").style.background = "url("+document.getElementById("image1").value+") no-repeat";	
				else
				{
					
					document.getElementById("casbody").style.background = "";
				}
				currentRange = 1;
			}
			else if (wH ==2)
			{
				changecaption(2);
				if (document.getElementById("image2"))
					document.getElementById("casbody").style.background = "url("+document.getElementById("image2").value+") no-repeat";	
				else
				
				{
					
					document.getElementById("casbody").style.background = "";
				}
				
				currentRange = 2;
			}
			else
			{
				changecaption(3);
				
				if (document.getElementById("image3"))
					document.getElementById("casbody").style.background = "url("+document.getElementById("image3").value+") no-repeat";	
				else
				{
					
					document.getElementById("casbody").style.background = "";
				}
					
				currentRange = 3;
			}
	}
	
	function setPageWidth(np)
	{
		
	
		if(np == -1)
		{
			currentRange=-1;
			
		}
		
		winW = getWidth();
		//alert(winW);
		if (winW > 1400)
		{
			setarea(1280,1);
			
		}
		
		else if (winW > 1100)
		{
			setarea(1100,1);
			
		}
		else if ((winW <=1100)&&(winW >900))
		{
			setarea(900,2);
			
			
		}
		else
		{	
			setarea(winW,3);
			
			
		}
		currentWinWidth = winW;
	}
	
	function setarea(num,range)
	{
		var mainbody = document.getElementById("mainbody");
		var picture = document.getElementById("picture");
		var casbody = document.getElementById("casbody");
		var content = document.getElementById("content");
		var logo = document.getElementById("logo");
		var menu = document.getElementById("menu");
		var footer = document.getElementById("footer");
		var announce = document.getElementById("announce");
		var quote = document.getElementById("quote");
		winW = getWidth();
		
		if(picture)
			 	picture.style.left = 1+"px";
			if (casbody)
			{
				casbody.style.width = num + "px";
				
			}
			
			menu.style.width = num+"px";
			announce.style.width =num+"px";
			if (content)
			{
				content.style.width = num-20+"px";
				
			}
			if (document.getElementById("forepict"))
			{
				sizeforeground(224,225,0);
				getHtml("get","","includes/picture.asp?imageid="+document.getElementById("forepict").name+"&size="+getHeight(),"","picture");
			}
			//alert(winW);
			
			logo.style.left = mainbody.offsetLeft;
			menu.style.left = mainbody.offsetLeft;
			announce.style.left = mainbody.offsetLeft;
			footer.style.width = (winW-50)+"px";
			//footer.style.width = num+"px";
			if (quote)
			{
				quote.style.width = content.offsetWidth-180+"px";
				
			}
			changeImage(range);
	}
	
	function setBullet()
	{
		//alert("setBullet");
		var content = document.getElementById("content");
		var pict1 = document.getElementById("picture");
		var bullets = document.getElementById("bullets");
		var quote =  document.getElementById("quote");
		var statement =document.getElementById("statement");
		var casbody = document.getElementById("casbody");
		
		
		if (((content.style.pixelWidth - pict1.offsetWidth-50)<100)|| (content.style.pixelHeight-(quote.offsetHeight + statement.offsetHeight-50)<100))
		{
			return;
		}
		else	
		{
			if(navigator.appName == "Netscape")
			{
				bullets.style.width = ((content.offsetWidth - pict1.offsetWidth)-50)+"px" ;
				bullets.style.height = (content.offsetHeight-(quote.offsetHeight + statement.offsetHeight)-50) +"px" ;
				
			}
			else
			{
				bullets.style.width = ((content.style.pixelWidth - pict1.offsetWidth)-50)+"px" ;
				bullets.style.height = (content.style.pixelHeight-(quote.offsetHeight + statement.offsetHeight)-50) +"px" ;
				//alert("BH/"+quote.offsetHeight + statement.offsetHeight);
				//alert("BHfin"+content.offsetHeight);
			}
		}
	}
	
	function setBulletWidth()
	{
		
		var fadeh = document.getElementById("casbody").offsetWidth;
		var picth = document.getElementById("picture").offsetWidth;
		
		
		document.getElementById("bullets").style.width = (fadeh - picth)-10+"px" ;
				
	}
	
	function setPageHeight()
	{
		
		var winH = 0;
		var headh = 0;
		var footh = 0;
		headh = document.getElementById("logo").offsetHeight;
		footh = 75;
		
		winH = getHeight();
	
		
		var gh = winH-(footh+30);
		
			
		if (isNaN(gh))
			return(80);
		document.getElementById("casbody").style.height =gh+'px';
		
		if( document.getElementById("content"))
		{
			
			document.getElementById("content").style.height = (gh-30)+'px';
			
		}
		
	
	return (gh);
	}	
	function setFooterloc()

	{
		//alert("setFoot");
		var winH;
		winH=getHeight();
		var menu =document.getElementById("menu");
		var footobj = document.getElementById("footer");
		var pocobj = document.getElementById("caspoc");
		var statement = document.getElementById("statement");

		pocobj.style.top = winH - 80+"px"; 
		footobj.style.top = winH - 70+"px";
		
		
		if (statement)
		{
			if(navigator.appName == "Netscape")
			{
				statement.style.width = footobj.offsetWidth*.80+"px";
				
			}
			else
			{
				statement.style.width = footobj.offsetWidth*.80 +"px";//* .80
				//alert("width"+getWidth()+"foot"+footobj.offsetWidth+"state"+statement.style.width);
			statement.style.left = footobj.offsetLeft+"px";
			}
		}
	}
	function resizefade()
	{
		
		var casbody = document.getElementById("casbody");
		var fade = document.getElementById("fade");
		var mainbody = document.getElementById("mainbody");
		
		fade.style.left = mainbody.offsetLeft +'px';
		

		if ((document.getElementById("content").offsetHeight -document.getElementById("footer").offsetHeight)<10)
		{	
			
			return;
		}
		else
		{
			
			fade.style.height = casbody.offsetHeight-50 +'px'; //style.pixelHeight
			fade.style.width = casbody.offsetWidth+50+'px';
		}

	}
	
	function openwindow(url)
	{
		window.open(url,"_blank");	
	}
	

	
	function updatepagecontents(id)
	{
		if (document.getElementById("content"))
		{
			getHtml("get","","bullets.asp?menu="+ id,"","bullets");
			getHtml("get","","quote.asp?menu="+ id,"","quote");
			getHtml("get","","statement.asp?menu="+ id,"","statement");
			getHtml("get","","image.asp?menu="+ id,"","image");
			
		}
		else
			getHtml("get","","page1.asp?menu="+ id,"","casbody");
		
	}
	function changebg(str)
	{
		
		var strval = "images/"+str;
		

		var bkgnd = document.getElementById("casbody");
		bkgnd.style.backgroundImage = 'url('+strval+')';
	}
	
	function getsubmenu(field,action,menuID)
	{
		currentsubmenuid=-1;
		if(menuID != currentmenuid)
		{
			currentmenuid = menuID;
			document.getElementById("cassubmenu").innerHTML = "";
		}
		if (action == "load")
		{			
			if(menuID ==6)
			{
				var div1 = document.getElementById("cassubmenu");
				div1.style.top = '50px';
				div1.style.left = '100px';
			}
			else
			{
				var pT = 0;
				var pR = 0;
				pR=field.parentNode.offsetWidth;
				
				while(field)
				{
					pT+=field.offsetTop;
					pR+=field.offsetLeft;
					field=field.offsetParent;
				}
				

				var div1 = document.getElementById("cassubmenu");
				var menuitem = document.getElementsByName("menuitem");

				div1.style.top = (pT+menuitem[1].offsetHeight-2)+"px";
				div1.style.left = (pR-menuitem[1].offsetWidth)+"px";	
			}
			
			
		getHtml("get","","includes/cassubmenu.asp?cmd="+action+"&menu="+menuID,"","cassubmenu");
		}		
	}
	
	function getsubsubmenu(field,action,menuID)
	{
		
		if(menuID != currentsubmenuid)
		{
			currentsubmenuid = menuID;
			
			document.getElementById("cassubsubmenu").innerHTML = "";
		}
		
		if (action == "load")
		{			
			var pT = 0;
			var pR = 0;
			pR=field.parentNode.offsetWidth;
			
			while(field){
				pT+=field.offsetTop;
				pR+=field.offsetLeft;
				field=field.offsetParent;
			}
			
			var div1 = document.getElementById("cassubsubmenu");
			
			div1.style.top = pT+'px';
			div1.style.left = pR+'px';
			
			
			getHtml("get","","includes/cassubsubmenu.asp?cmd="+action+"&menu="+menuID,"","cassubsubmenu");	
		}		
	}

// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
function setpict()
{
	if(document.Category.javaimg)
		setInterval("nextSlide()",5000);
}
// -->

/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2001-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/
var str; 
var directory;
var imagearray;
var currentimage = 0;
var imgnum;
var imgarray = new Array();
function loadimages()
{
	imgfolder = "images/";
	//imagearray = document.all.images.value.split(",");
	/*for(i=0;i<imagearray.length-1;i++)
	{*/
		imgarray[0] = new Image();
		imgarray[0].src = "images/image1.jpg";
		imgarray[1] = new Image();
		imgarray[1].src = "images/image2.jpg";
		imgarray[2] = new Image();
		imgarray[2].src = "images/image3.jpg";
		imgarray[3] = new Image();
		imgarray[3].src = "images/image4.jpg";
		imgarray[4] = new Image();
		imgarray[4].src = "images/image5.jpg";
		imgarray[5] = new Image();
		imgarray[5].src = "images/image6.jpg";
		imgarray[6] = new Image();
		imgarray[6].src = "images/image7.jpg";
		imgarray[7] = new Image();
		imgarray[7].src = "images/image1blk.jpg";
		imgarray[8] = new Image();
		imgarray[8].src = "images/image2blk.jpg";
		imgarray[9] = new Image();
		imgarray[9].src = "images/image3blk.jpg";
		//imgarray[i] = new Image();
		//imgarray[i].src = imgfolder+imagearray[i];
	//}	
	startintro();
}

function startintro()
{
	nextSlide('4','img2'); //dot
	setTimeout("nextSlide('0','img1')",3000); //this is our customer
	setTimeout("nextSlide('1','img2')",2000); //soldier
	setTimeout("nextSlide('2','img3')",4500); //we've got what it takes
	setTimeout("nextSlide('7','img1')",6500); //black
	setTimeout("nextSlide('9','img3')",6500); //black
	setTimeout("nextSlide('3','img3')",7500); //do you?
		
	setTimeout("nextSlide('8','img2')",8500);	//black
	setTimeout("nextSlide('9','img3')",8500); //black
	setTimeout("nextSlide('6','img2')",10000); //CAS logo
	setTimeout("nextSlide('8','img2')",13500);	//black
	
	obj1 = document.getElementById("intro");
	setTimeout("obj1.submit()",14500); //load page	
}	

function nextSlide(img,location) 
{
	//imgnum = imgarray.length-1;

	var image = document.getElementById(location);
	if (navigator.appName=="Netscape") 
	{
		image.src = imgarray[img].src;
	}
	else
	{
	image.filters["blendTrans"].apply();
	image.src = imgarray[img].src;
	image.filters["blendTrans"].play();
	}
	
}
document.onkeydown = getKey; 

function getKey(e) 
{
  
  var keyCode;
   if (window.event) { // checks which browser
		
		keyCode = window.event.keyCode; //assigns keycode to keycode var
	}
	else if (e){ // checks which browser
		
		keyCode = e.which;//assigns keycode to keycode var
	}
//   var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	if (keyCode == 113)
	{
		var obj = document.getElementById("acknowledge");
		obj.style.left = "100px";
		obj.style.top = getHeight()/2 - 100+"px";
		obj.style.visible = "display";
		ack = setInterval("acknowledge()",7000);
//		obj.style.filter = alpha(opacity=40);
		obj.style.opacity=.4;	
		//window.open("includes/writeabout.asp","blank");
	}
}
function acknowledge()
{
	
	getHtml("get","","includes/writeabout.asp?ID="+document.getElementById("currentack").value,"blendTrans","acknowledge");		
	
	
}
function quitacknowledge()
{



	clearInterval(ack);	
	document.getElementById("acknowledge").style.visible = "";
}

//Image zoom in/out script- by javascriptkit.com
//Visit JavaScript Kit (http://www.javascriptkit.com) for script
//Credit must stay intact for use

var zoomfactor=0.05 //Enter factor (0.05=5%)

function zoomhelper(){
if (parseInt(whatcache.style.width)>10&&parseInt(whatcache.style.height)>10){
whatcache.style.width=parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix
whatcache.style.height=parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix
}
}

function zoom(originalW, originalH, what, state){
if (!document.all&&!document.getElementById)
return
whatcache=eval("document.images."+what)
prefix=(state=="in")? 1 : -1
if (whatcache.style.width==""||state=="restore"){
whatcache.style.width=originalW
whatcache.style.height=originalH
if (state=="restore")
return
}
else{
zoomhelper()
}
beginzoom=setInterval("zoomhelper()",30)
}

function clearzoom(){
if (window.beginzoom)
clearInterval(beginzoom)
}

function imagefront(field)
{
	var obj = field.parentElement;
	
	var objs = obj.getElementsByTagName("DIV");
	for(i=0;i<objs.length;i++)
	{
		objs[i].style.zIndex = 1;
		
	}
	field.style.zIndex = 4;		
	
}
function imageval(field)
{
	var obj = field.parentElement;
	var objs = obj.getElementsByTagName("DIV");
	var num = obj.offsetWidth-obj.offsetLeft ;
	var top = obj.offsetTop;
	
	for(i=0;i<objs.length;i++)
	{
		objs[i].style.left = num-(i*50);
		objs[i].style.top = top+(i*30);
	}
	
}
function getsubbullets(id)
{
	var obj1= document.getElementById("sub"+id);
	var parent = obj1.parentElement;
	
	var obj = document.getElementById("image"+id);

	var num = obj.src.lastIndexOf("/");
	var str= obj.src.substr(num+1);
	if (str =="closed.jpg")
	{
		obj.src = "images/open.jpg";
		getHtml('get','','includes/bullets.asp?parent='+id,'','sub'+id);
		//if(obj1.style.left)
//			obj1.style.left =(obj1.style.left +12)+"px";
//		else	
//			obj1.style.left= 12+"px"
}
	else
	{	
		obj.src = "images/closed.jpg";
		obj1.innerText =""
	}
}

function replaceText(textid,id)
{
	
	var text = document.getElementById(textid).value;
	document.getElementById("text"+id).innerHTML = text;
	
}
function selectfield(id)
{
	
	//var obj = document.getElementById(id.id) = true;
	//setSelectedElement(id.id);
	
	

	if (id != selectedbullet)
	{
		if(selectedbullet !=null)
			selectedbullet.style.backgroundColor = origincolorbullet
		
		origincolorbullet = id.style.backgroundColor;
		selectedbullet = id;
		id.style.backgroundColor = "red";
	}
}

function validatebullet(menu,parent)
{
	//alert(menu);
	//alert(parent);
	if (menu!="")
		if (menu != document.getElementById("menunum"))
			if (confirm("You are about to remove this Bullet from under this menuitem"))
				document.getElementById("bulletparent").value ="";
				
	//if (parentdocument.getElementById(parent
	
}