// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_effectAppearFade(targetElement, duration, from, to, toggle) {
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

AC_FL_RunContent = 0;
var timeout	= 500;
var closeTimer	= 0;
var activeMenu	= 0;
var blnInTransition = false;
var currentID;
var AC_FL_RunContent = 0;

var blnLoadedFlash=0;
var blnLoadedPage=0;
var theTimer;
var blnPageStarted=0;
// close layer when click-out
document.onclick = closeMenu; 

function openMenu(id)
{	
	// cancel close timer
	cancelMenuCloseTimer();
	if (!activeMenu) {
		// close old layer
		closeMenu();
		
		// get new layer and show it
		activeMenu = document.getElementById(id);
		//shimit(activeMenu);
		//blnInTransition = true;
		//setTimeout('blnInTransition=false;', 550);
		activeMenu.style.visibility = 'visible';
		//MM_effectAppearFade(activeMenu, 500, 0, 100, false);
		//activeMenu.style.visibility = 'visible';
	}
}

// close showed layer
function closeMenu()
{
	if(activeMenu) {
		//check to see if in transition, if it is, retry in 100ms
		closeMenuID(activeMenu.id);
		if (activeMenu.id == 'galleries_popup') {
			MM_swapImage('imgGalleries','','images/galleries.png',1);
			activeMenu.style.visibility = 'hidden';
		}
		activeMenu= null;
	}
	
}

function closeMenuID(id) {
	//if (blnInTransition) {
		//at least make it disapear
		document.getElementById(id).style.visibility = 'hidden';
		//setTimeout("closeMenuID('"+id+"')", 100);
	//}else{
		//MM_effectAppearFade(document.getElementById(id), 50, 100, 0, false);
		//document.getElementById(id).style.visibility = 'visible';
	//}
}
// go close timer
function startMenuCloseTimer()
{
	closeTimer = window.setTimeout(closeMenu, timeout);
}

// cancel close timer
function cancelMenuCloseTimer()
{
	if(closeTimer)
	{
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}

function UnCryptMailto( s )
{
	var n = 0;
	var r = "";
	for( var i = 0; i < s.length; i++)
	{
		n = s.charCodeAt( i );
		if( n >= 8364 )
		{
			n = 128;
		}
		r += String.fromCharCode( n - 1 );
	}
	return r;
}

function linkTo_UnCryptMailto( s )
{
	location.href=UnCryptMailto( s );
}
	
function flashDone() {
	blnLoadedFlash=1;
	//showPage();
	location.href = gSiteURL;
}
function pageDone() {
	blnLoadedPage=1;
	showPage();
}

function skipIntro() {
	if (!blnLoadedFlash) {
		blnLoadedFlash=1;
		blnLoadedPage=1;
		showPage();
	}
}
var varTimer=0;
function showPage() {
	//check to see if cookie exists, if it does then just load the page instead
	if (getCookie('pageloaded') != '') {
		blnLoadedFlash=1;
		blnLoadedPage=1;
	}
		
	if ((blnLoadedFlash && blnLoadedPage) &&(!blnPageStarted)) {
		blnPageStarted=1;
		//MM_effectAppearFade('bodydiv', 1000, 25, 100, false);
		elem = document.getElementById('overlay');
		elem.style.visibility='hidden';
		elem = document.getElementById('bodydiv');
		elem.style.visibility='visible';
		//MM_effectAppearFade('overlay', 1000, 100, 0, false);
		//setTimeout("document.getElementById('overlay').style.visibility='hidden';", 1200);
		clearTimeout(varTimer);
		setCookie('pageloaded','true', 1);
		if (document.getElementById('content') && currentID=='home') {
			window.frames[0].StartSlideshow();
		}
		return;
	} else {
		clearTimeout(varTimer);
		varTimer = 0;
		varTimer = setTimeout('showPage();', 100);
	}
}

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 showPopup(id) {
    
	MM_effectAppearFade(id, 500, 0, 70, true);
	//setTimeout("MM_effectAppearFade('" + id + "', 500, 70, 0, false)", 3000);
	setTimeout("hidePopup('" + id + "')", 5000);

}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}
function hidePopup(id) {
	if (document.getElementById(id).style.opacity != 0) {
		MM_effectAppearFade(id, 500, 0, 70, true);
	}
}
function showContent(id) {
	var x;
	x = document.getElementById('content');
	currentID = id;
	document.getElementById('imgHome').src = '/images/home.png';
	document.getElementById('imgLive').src = '/images/live.png';
	document.getElementById('imgWork').src = '/images/work.png';
	document.getElementById('imgAspire').src = '/images/aspire.png';
	document.getElementById('imgBios').src = '/images/bios.png';
	document.getElementById('imgBlog').src = '/images/blog.png';
	document.getElementById('imgResources').src = '/images/resources.png';
	if (id == 'home') {
		x.src = 'home.asp';
		document.getElementById('imgHome').src = '/images/home_there.png';
	}else if (id =='live') {
		x.src='live.asp';
		document.getElementById('imgLive').src = '/images/live_there.png';
	}else if (id=='work') {
		x.src='work.asp';
		document.getElementById('imgWork').src = '/images/work_there.png';
	}else if (id=='aspire') {
		x.src='aspire.asp';
		document.getElementById('imgAspire').src = '/images/aspire_there.png';
	}else if (id=='bios') {
		x.src='bios.asp';
		document.getElementById('imgBios').src = '/images/bios_there.png';
	}else if (id=='blog') {
		x.src='blog.asp';
		document.getElementById('imgBlog').src = '/images/blog_there.png';
	}else if (id=='resources') {
		x.src='resources.asp';
		document.getElementById('imgResources').src = '/images/resources_there.png';
	}
}

function mouseOver(id) {
	var x;
	x = document.getElementById(id);
	if (id == 'imgHome') {
		if (!(currentID =='home')) {
			x.src = '/images/home_over.png';
		}
	}else if (id =='imgLive') {
		if (!(currentID =='live')) {
			x.src = '/images/live_over.png';
		}
	}else if (id=='imgWork') {
		if (!(currentID =='work')) {
			x.src = '/images/work_over.png';
		}
	}else if (id=='imgAspire') {
		if (!(currentID =='aspire')) {
			x.src = '/images/aspire_over.png';
		}
	}else if (id=='imgBios') {
		if (!(currentID =='bios')) {
			x.src = '/images/bios_over.png';
		}
	}else if (id=='imgBlog') {
		if (!(currentID =='blog')) {
			x.src = '/images/blog_over.png';
		}
	}else if (id=='imgResources') {
		if (!(currentID =='recources')) {
			x.src = '/images/resources_over.png';
		}		
	}
}

function mouseOut(id) {
	var x;
	x = document.getElementById(id);
	if (id == 'imgHome') {
		if (!(currentID =='home')) {
			x.src = '/images/home.png';
		}
	}else if (id =='imgLive') {
		if (!(currentID =='live')) {
			x.src = '/images/live.png';
		}
	}else if (id=='imgWork') {
		if (!(currentID =='work')) {
			x.src = '/images/work.png';
		}
	}else if (id=='imgAspire') {
		if (!(currentID =='aspire')) {
			x.src = '/images/aspire.png';
		}
	}else if (id=='imgBios') {
		if (!(currentID =='bios')) {
			x.src = '/images/bios.png';
		}
	}else if (id=='imgBlog') {
		if (!(currentID =='blog')) {
			x.src = '/images/blog.png';
		}
	}else if (id=='imgResources') {
		if (!(currentID =='resources')) {
			x.src = '/images/resources.png';
		}		
	}
}

function thumbClick(id) {
		//change classes of all id
		if (document.getElementById('thumb1')) {document.getElementById('thumb1').className='imgEffect';}
		if (document.getElementById('thumb2')) {document.getElementById('thumb2').className='imgEffect';}
		if (document.getElementById('thumb3')) {document.getElementById('thumb3').className='imgEffect';}
		if (document.getElementById('thumb4')) {document.getElementById('thumb4').className='imgEffect';}
		if (document.getElementById('thumb5')) {document.getElementById('thumb5').className='imgEffect';}
		if (document.getElementById(id)) {document.getElementById(id).className='imgEffectThere';}
}

function changeImage(src,width,height) {
	if (parent.document.getElementById('imgDisplay')) {
		parent.document.getElementById('imgDisplay').src = '/images/spacer.gif';
		parent.document.getElementById('imgDisplay').width = width; // +'px';
		parent.document.getElementById('imgDisplay').height = height; // +'px';
		parent.document.getElementById('imgDisplay').src = src;
	}
}

//slideshow functions

var lastImage = 1 ;
var currentDiv = 1;
var inTransistion = false;
var timerID = 0;
function StartSlideshow() {
	clearTimeout(timerID);
	timerID = 0;
	lastImage = 1 ;
	MM_swapImage('img1','','/images/home1.jpg',1); //image is swapped with the correct img
	MM_swapImage('img2','','/images/home1.jpg',1); //image is swapped with the correct img
	timerID = setTimeout("NextSlide()", 2000);
}

function StopSlideshow(){
	if (timerID) {
		clearTimeout(timerID);
		timerID = 0;
	}
}

function NextSlide() {
	if (timerID) {
		clearTimeout(timerID);
		if (!inTransistion) {
			//change image
			lastImage = lastImage +1
			if (lastImage > 4) {lastImage = 1}
			changeSlideshowImage('/images/home' + lastImage + '.jpg');
		}
		if (!(lastImage==1)) {
			timerID = setTimeout("NextSlide()", 4000);
		} else {
			timerID = setTimeout("NextSlide()", 6000);
		}
	}
}

function changeSlideshowImage(imgPath) {
		if (currentDiv==1) {
			MM_swapImage('img2','',imgPath,1); //image is swapped with the correct img
			inTransistion = true;
			MM_effectAppearFade('div1', 2200, 100, 0, false);
			MM_effectAppearFade('div2', 2200, 20, 100, false);
			setTimeout("inTransistion=false", 2300);
			currentDiv = 2;
		}else {
			MM_swapImage('img1','',imgPath,1); //image is swapped with the correct img
			inTransistion = true;
			MM_effectAppearFade('div2', 2200, 100, 0, false);
			MM_effectAppearFade('div1', 2200, 20, 100, false);
			setTimeout("inTransistion=false", 2300);
			currentDiv = 1;
		}
}

