// JavaScript Document

var xmlHttp;
var xmlHttp2;
var profile_nav_active = false;
var projects_nav_active = false;
var features_nav_active = false;
var contact_nav_active = false;
var xmlHttpslideshow;

function MainSelect(value, divname) 
{
	xmlHttp=GetXmlHttpObject();
		
			if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 

					
		url = "pullmenu.asp?id=" + value + "&div=" + divname;
		alert(url);
		xmlHttp.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttp.readyState==4)
				{ 
				document.getElementById(divname).innerHTML=xmlHttp.responseText;
				//switchDiv('updatemenu'+autonum, 'menu'+autonum);
				//alert("done");
				}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

}

function PictureBoxActivate(divid) 
{
	if (divid != '' && divid != 'images/img_current.gif')
		{
			
			var imagefield = document.getElementById(divid);
			if (imagefield.src.search('img_current.gif') == -1)
				{			
					imagefield.src = 'images/img_over.gif';
				}
		}
}

function PictureBoxDeActivate(divid) 
{
	if (divid != '' && divid != 'images/img_current.gif')
		{
			
			var imagefield = document.getElementById(divid);
			if (imagefield.src.search('img_current.gif') == -1)
				{			
					imagefield.src = 'images/img_init.gif';
				}
		}
}

function SelectPictureBox(divid) 
{
	if (divid != '')
		{
			var imagefield = document.getElementById(divid);
			imagefield.src = 'images/img_current.gif';
		}
}

function ShowPicture(imagesrc) 
	{
		if (imagesrc != '')
			{
				var imagefield = document.getElementById('mainimageimage');
				imagefield.src = imagesrc;
			}
	}

function DetailSelect(value, divname) 
	{
		xmlHttp=GetXmlHttpObject();
			
				if (xmlHttp==null)
				  {
					  alert ("Your browser does not support AJAX!");
					  return;
				  } 
	
						
			url = "pullmenu.asp?id=" + value + "&div=" + divname;
			//alert(url);
			xmlHttp.onreadystatechange=function stateChanged() 
			{ 
					if (xmlHttp.readyState==4)
					{ 
					document.getElementById(divname).innerHTML=xmlHttp.responseText;
					//switchDiv('updatemenu'+autonum, 'menu'+autonum);
					//alert("done");
					}
			}
	
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
	
	}


function PullTextDetail(textid) 
	{
		document.getElementById("profileimage").src = "";
		document.getElementById("ScrollingAreaText").innerHTML = "";
	
	clearbox();
	document.getElementById('profiles').style.display = 'block';
	
	if (textid == '' || textid == null)
		{
			textid = 1;
			alert("textid reset to 1 for being null");
		}
	
	
	
	xmlHttp=GetXmlHttpObject();
		
			if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 

					
		url = "ajax/pulltext.asp?textid=" + textid;
		//alert(url);
		xmlHttp.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttp.readyState==4)
				{ 
				pullImage('mdeastext', textid);

				document.getElementById("ScrollingAreaText").innerHTML=xmlHttp.responseText;
				document.getElementById("profiles").style.display="block";	
				initScrollLayer();

				
				
				//switchDiv('updatemenu'+autonum, 'menu'+autonum);
				//alert("done3");
				}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

}


function pullImage(table, id) 
	{
		
	if (id == '' || id == null)
		{
			id = 1;
			alert("textid reset to 1 for being null");
		}
	
	
	
	xmlHttp2=GetXmlHttpObject();
		
			if (xmlHttp2==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 

		if (table == 'mdeastext')
			{url = "ajax/pulltextimage.asp?textid=" + id;
			}
		if (table == 'mdeasprofile')
			{url = "ajax/pullprofileimage.asp?profileid=" + id;}
			
			
			//alert(url);
		xmlHttp2.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttp2.readyState==4)
				{
					if (xmlHttp2.responseText == 'none')
						{//alert(xmlHttp2.responseText);
						document.getElementById("profileimage").src="";
						document.getElementById("profiles_left").style.display="none";

						}
					else
						{//alert("good");
						//alert(xmlHttp2.responseText);
				document.getElementById("profileimage").src=xmlHttp2.responseText;
				document.getElementById("profileimage").style.display="block";
				document.getElementById("profiles_left").style.display="block";
						}
				
				
				//switchDiv('updatemenu'+autonum, 'menu'+autonum);
				//alert("done");
				}
		}

		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);

}

function RemoveProfileDetail()
	{
		document.getElementById("profileimage").style.display = 'none';
		document.getElementById("profileimage").src = '';
		document.getElementById("ScrollingAreaText").innerHTML = '';
		//clearbox();
	}

function PullProfileDetail(profileid) 
	{	
		RemoveProfileDetail();
		clearbox();
		imageid = 'images/profile/ProfilePic' + profileid + '.jpg';
		

	if (profileid == '' || profileid == null)
		{
			profileid = 1;
			//alert("profileid reset to 1 for being null");
		}
	
	
	
	xmlHttp=GetXmlHttpObject();
		
			if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 

					
		url = "ajax/pullprofile.asp?profileid=" + profileid;
		//alert(url);
		xmlHttp.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttp.readyState==4)
				{ 
				pullImage('mdeasprofile', profileid);
				//document.getElementById("profileimage").src = imageid;
				document.getElementById('profiles').style.display = 'block';
				document.getElementById("ScrollingAreaText").innerHTML=xmlHttp.responseText;
				initScrollLayer();
				//switchDiv('updatemenu'+autonum, 'menu'+autonum);
				//alert("done");
				}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

}

function PullProjects(categoryid) 
	{	var newimagepath = '/images/slider/SliderImage_' + categoryid + '.jpg';
		loadSlider(newimagepath)
		document.getElementById('menu_projectdetail').innerHTML='';
		clearmenus();
		
		
		//var t=setTimeout("loadSlider("+newimagepath+")",1000);
		
		//loadSlider(newimagepath);
		//document.getElementById('sliderimage').src = newimagepath;
		
		
		document.getElementById('menu_projectdetail').style.display = 'block';

		

	if (categoryid == '' || categoryid == null)
		{
			categoryid = 1;
			//alert("profileid reset to 1 for being null");
		}
	
	
	
	xmlHttp=GetXmlHttpObject();
		
			if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 

					
		url = "/ajax/pullprojectsmenu.asp?categoryid=" + categoryid;
		//alert(url);
		xmlHttp.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttp.readyState==4)
				{ 
				document.getElementById("menu_projectdetail").innerHTML=xmlHttp.responseText;
				//document.getElementById("profileimage").src = imageid;
				//switchDiv('updatemenu'+autonum, 'menu'+autonum);
				//alert("done");
				}
		}

		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

	}
		
		

	function GetXmlHttpObject()
		{
			var xmlHttp=null;
				try
				  {
					  // Firefox, Opera 8.0+, Safari
					  xmlHttp=new XMLHttpRequest();
				  }
				catch (e)
				  {
					  // Internet Explorer
					  try
					    {
						    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					    }
					  catch (e)
					    {
					    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					    }
				  }
			return xmlHttp;
		}

	function stateChanged() 
		{ 
				if (xmlHttp.readyState==4)
				{ 
				document.getElementById("alertness").innerHTML=xmlHttp.responseText;
				//alert("done");
				}
		}

function switchDiv(newDiv) 
	{
		var newArea = document.getElementById(newDiv);
	
			clearmenus();
			newArea.style.display = 'block';
			newArea.style.visibility = 'visible';
			
	}

function startSlideShow(projectid_var) 
{	
	//deInitializeGallery();
	clearbox();
	hideSlider();
	document.getElementById('mainImage').src = '';
	document.getElementById('detail').innerHTML= '';
	document.getElementById('detail').style.display = 'block';
	document.getElementById('images').style.display = 'block';

			xmlHttpslideshow=GetXmlHttpObject();
			if (xmlHttpslideshow==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 
			url = "ajax/pullslideshow.asp?projectid=" + projectid_var;
			//alert(url);
			xmlHttpslideshow.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttpslideshow.readyState==4)
				{ 
					document.getElementById("detail").innerHTML=xmlHttpslideshow.responseText;
					
					InitializeGallery();
					gSlideShowControl.start();
				}
		}

		xmlHttpslideshow.open("GET",url,true);
		xmlHttpslideshow.send(null);
}

function startSlideShowlite(projectid_var) 
{	
	//deInitializeGallery();
	clearbox();
	hideSlider();
	document.getElementById('mainImage').src = '';
	document.getElementById('detail').innerHTML= '';
	document.getElementById('detail').style.display = 'block';
	document.getElementById('images').style.display = 'block';

			xmlHttpslideshow=GetXmlHttpObject();
			if (xmlHttpslideshow==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 
			url = "ajax/pullslideshow.asp?projectid=" + projectid_var;
			//alert(url);
			xmlHttpslideshow.onreadystatechange=function stateChanged() 
		{ 
				if (xmlHttpslideshow.readyState==4)
				{ 
					document.getElementById("detail").innerHTML=xmlHttpslideshow.responseText;
					
					InitializeGallery();
					gSlideShowControl.stop();
				}
		}

		xmlHttpslideshow.open("GET",url,true);
		xmlHttpslideshow.send(null);
}


function switchpicture(id, src)
	{
		var newArea = document.getElementById(id);
		newArea.src = src;
	}

//Image Controls for Side Navigation
function activateProfilePic()
	{
		var activeDiv = document.getElementById('nav_profile');
		activeDiv.src = 'images/nav_profile_over.jpg';
		profile_nav_active = true;
		deactivateProjectsPic();
		//deactivateFeaturesPic();
		deactivateContactPic();
	}

function activateProjectsPic()
	{
		var activeDiv = document.getElementById('nav_projects');
		activeDiv.src = 'images/nav_projects_over.jpg';
		projects_nav_active = true;
		deactivateProfilePic();
		//deactivateFeaturesPic();
		deactivateContactPic();
		//alert("done with projects pic activation");
	}

function activateFeaturesPic()
	{
		var activeDiv = document.getElementById('nav_features');
		activeDiv.src = 'images/nav_features_over.jpg';
		features_nav_active = true;
		deactivateProjectsPic();
		deactivateProfilePic();
		deactivateContactPic();
	}

function activateContactPic()
	{
		var activeDiv = document.getElementById('nav_contact');
		activeDiv.src = 'images/nav_contact_over.jpg';
		contact_nav_active = true;
		deactivateProjectsPic();
		//deactivateFeaturesPic();
		deactivateProfilePic();
	}

function deactivateProfilePic()
	{
		var activeDiv = document.getElementById('nav_profile');
		activeDiv.src = 'images/nav_profile.jpg';
		profile_nav_active = false;
	}

function deactivateProjectsPic()
	{
		var activeDiv = document.getElementById('nav_projects');
		activeDiv.src = 'images/nav_projects.jpg';
		projects_nav_active = false;
	}

function deactivateFeaturesPic()
	{
		var activeDiv = document.getElementById('nav_features');
		activeDiv.src = 'images/nav_features.jpg';
		features_nav_active = false;
	}

function deactivateContactPic()
	{
		var activeDiv = document.getElementById('nav_contact');
		activeDiv.src = 'images/nav_contact.jpg';
		contact_nav_active = false;
	}


function ImageHover(id, direction)
	{
		if (direction == 'over')
		{
			if (id == 'nav_profile') 
				{
					if (profile_nav_active == false)
					document.getElementById(id).src = 'images/nav_profile_over.jpg';
				}
			if (id == 'nav_projects') 
				{
					if (projects_nav_active == false)
					document.getElementById(id).src = 'images/nav_projects_over.jpg';
				}
			if (id == 'nav_features') 
				{
					if (features_nav_active == false)
					document.getElementById(id).src = 'images/nav_features_over.jpg';
				}
			if (id == 'nav_contact') 
				{
					if (contact_nav_active == false)
					document.getElementById(id).src = 'images/nav_contact_over.jpg';
				}
		}
		if (direction == 'out')
		{
			if (id == 'nav_profile') 
				{
					if (profile_nav_active == false)
					document.getElementById(id).src = 'images/nav_profile.jpg';
				}
			if (id == 'nav_projects') 
				{
					if (projects_nav_active == false)
					document.getElementById(id).src = 'images/nav_projects.jpg';
				}
			if (id == 'nav_features') 
				{
					if (features_nav_active == false)
					document.getElementById(id).src = 'images/nav_features.jpg';
				}
			if (id == 'nav_contact') 
				{
					if (contact_nav_active == false)
					document.getElementById(id).src = 'images/nav_contact.jpg';
				}
		}
	}
	


function clearmenus() 
{
	clearbox();
	document.getElementById('menu_profile').style.display = 'none';
	document.getElementById('menu_principals').style.display = 'none';
	document.getElementById('menu_office').style.display = 'none';
	document.getElementById('menu_projects').style.display = 'none';
	document.getElementById('menu_projectdetail').style.display = 'none';
	document.getElementById('detail').style.display = 'none';

}

function clearthumbs() 
{
		var i=1;
		do 
		{
			document.getElementById('thumb' + i).src = 'images/img_init.gif';
			//alert(i);
			i=i+1;
		}
		while (i<11)
}



//Code for activating picture boxes
function clearbox()
	{
		document.getElementById("profileimage").src = ""
		document.getElementById('images').style.display = 'none';
		document.getElementById('text').style.display = 'none';
		document.getElementById('profiles').style.display = 'none';
			
	}

function ShowPicture(src_var, thumbnum)
	{
		clearbox();
		clearthumbs();
		//alert(src_var);
		document.getElementById('images').style.display = 'block';
		document.getElementById('mainimageimg').src = src_var;
		document.getElementById('thumb' + thumbnum).src = 'images/img_current.gif';
	}
function ShowText()
	{
		clearbox();
		document.getElementById('images').style.display = 'block';
		document.getElementById('text').src = src_var;
		//document.getElementById('thumb' + thumbnum).src = 'images/img_current.gif';
	}
function activateContact()
	{	
		document.getElementById("profileimage").src = ""
		clearmenus(); 
		activateContactPic(); 
		PullTextDetail(6);	
		hideSlider();

	}

function hideSlider()
	{	
		if (document.getElementById("motioncontainer").style.display == "block" || document.getElementById("motioncontainer").style.display == "")
			document.getElementById("motioncontainer").style.display = "none";
		if (document.getElementById("motiongallery").style.display == "block" || document.getElementById("motiongallery").style.display == "")
			document.getElementById("motiongallery").style.display = "none";
		if (document.getElementById("trueContainer").style.display == "block" || document.getElementById("trueContainer").style.display == "")
			document.getElementById("trueContainer").style.display = "none";
	}

function showSlider()
	{	
		if (document.getElementById("motioncontainer").style.display == "none")
			document.getElementById("motioncontainer").style.display = "block";
		if (document.getElementById("motiongallery").style.display == "none")
			document.getElementById("motiongallery").style.display = "block";
		if (document.getElementById("trueContainer").style.display == "none")
			document.getElementById("trueContainer").style.display = "block";
	}

function resetSlider()
	{

		
		if (document.getElementById("motioncontainer").style.display == "none")
			document.getElementById("motioncontainer").style.display = "block";
		if (document.getElementById("motiongallery").style.display == "none")
			document.getElementById("motiongallery").style.display = "block";
		if (document.getElementById("trueContainer").style.display == "none")
			document.getElementById("trueContainer").style.display = "block";
		
		if (document.getElementById("sliderimage").src != "http://www.mdeas.com/images/slider/mainslider.jpg")
			{
				document.getElementById('sliderimage').src = '';
				var t=setTimeout(function() {document.getElementById('motiongallery').style.left = '0px';}, 300);
				mainimage = '/images/slider/mainslider.jpg';
				var t=setTimeout(function() {document.getElementById('sliderimage').src = mainimage;}, 1000);
			}
	}



function loadSlider(image)
	{
		document.getElementById('sliderimage').src = '';
			var t=setTimeout(function() {document.getElementById('motiongallery').style.left = '0px';}, 600);
			var t=setTimeout(function() {document.getElementById('sliderimage').src = image;}, 1000);
	}

function showLoadingImage()
	{
		document.getElementById("loadingimage").style.display = "block";
	}
	
function hideLoadingImage()
	{
		document.getElementById("loadingimage").style.display = "none";
	}

function resethome()
	{
		deactivateProfilePic();
		deactivateProjectsPic();
		deactivateContactPic();
		clearmenus();
		clearbox();
		resetSlider();
		
	}


