//----------------------------------------------------------------------
// FUNCTION: Housekeeping
//----------------------------------------------------------------------
function houseKeeping() {
	checkBrowser();
	document.write('<style type="text/css" media="screen">#arrows {visibility:hidden}</style>');
}

/*  FOR THE SLIDE SHOW  */
var slideShowLoop, chainLoop, introSlideNum;
var fadeToColor = '#4f5052';
var fadeFromColor = "#ffffff";

//----------------------------------------------------------------------
// FUNCTION: FADESTUFF 
//   parameters: element name, 'from' opacity, 'to' opacity, duration, delay 
//----------------------------------------------------------------------
function fadeStuff(e,fromN,toN,duration,delay) {
	if (!delay) {
		var delay = 0;
	}
	var fadeInOut = new Fx.Tween($(e), {
		property: 'opacity',
		duration: duration
	});
	fadeInOut.start.pass([fromN,toN], fadeInOut).delay(delay);
		
}


//----------------------------------------------------------------------
// FUNCTION: for running thri the portfolio
//----------------------------------------------------------------------
function toggleImg(slideNum,direction){

	/*  Hide the client info and the arrows  */
	$('div1').fade('hide');
	$('client0').fade('hide');
	$('arrows').fade('hide');
	$('arrows').setStyle('background-color', fadeToColor);

	/*  set DIV1 to the next image, and show it  */
	var nextImg1 = "img"+slideNum.toString();
	var newSrc1 = $(nextImg1).get('src'); 
	$("img0a").set('src',newSrc1); 
	//$('div1').fade('show');
	fadeStuff('div1',0,1,0,100);

	/*  set DIV2 to the "fade in" image, and set opacity to zero */
	var nextImg2 = "img"+(slideNum+1).toString();
	var newSrc2 = $(nextImg2).get('src'); 
	$("img0b").set('src',newSrc2);
	$('div2').setStyle('opacity', 0);

		
	if (slideNum!=1) {   
		/*  cross fade the 2 images */
		fadeStuff('div1',1,0,2000,1000);
		fadeStuff('div2',0,1,2000,1000);
				
		/*  fade in the client info */
		var newClient =  'client'+(slideNum+1).toString(); 
		$('client0').set('html',$(newClient).get('html'));
		fadeStuff('client0',0,1,1000,2000);
	}
			
	/* figure out which arrows to display  */
	(slideNum > 1) ? $('prevArrow').removeClass('hidden') : $('prevArrow').addClass('hidden');
	//(slideNum+1 == numSlides) ? $('nextArrow').addClass('hidden') : $('nextArrow').removeClass('hidden');
			
	/*  fade in the arrows */
	fadeStuff('arrows',0,1,1000,2000);
}


//---------------------------------------------------------------------------
//  FUNCTION: Slideshow for the "intro" piece
//---------------------------------------------------------------------------
function introSlideShow() {
		
	var time = 2000;
	
	introSlideNum = 1;
	
	/*  hide the arrows  */
	$('arrows').fade('hide');
	
	/*  set the image for the first slide show and cross fade it  */
	var newSrc = $("introImg1").get('src'); 
	$("img0b").set('src',newSrc);
	$('div2').setStyle('opacity', 0);
	fadeStuff('div1',1,0,2000,0);
	fadeStuff('div2',0,1,2000,0);

	/*  change the style for DIV "client0" for the intro slide show */
	$('client0').removeClass('clientInfo');
	$('client0').addClass('intro');

	/*  set the text for the first slide show, and fade it in  */
	newIntroText =  'introTextDiv1'; 
	$('client0').set('html',$(newIntroText).get('html'));
	$('client0').fade('show');

	fadeStuff('introText1',0,1,1000,1000);
	

	/*  FUNCTION: this is thet iterative slideshow for the intro section */
	function mySS() {
	
		var prevText = 'introText'+(introSlideNum).toString();
		introSlideNum++; 
		
		var nextImg, newSrc;
		if (introSlideNum%2) { /*  cross-fade from image 1 to image 2 */
		
			nextImg = "introImg"+(introSlideNum).toString();
			newSrc = $(nextImg).get('src'); 
			$("img0b").set('src',newSrc);
			$('div2').setStyle('opacity', 0);
			fadeStuff('div1',1,0,2000,0);
			fadeStuff('div2',0,1,2000,0);
		}
		else {  /*  cross-fade from image 2 to image 1  */
			nextImg = "introImg"+(introSlideNum).toString();
			newSrc = $(nextImg).get('src'); 
			$("img0a").set('src',newSrc);
			$('div1').setStyle('opacity', 0);
			fadeStuff('div1',0,1,2000,0);
			fadeStuff('div2',1,0,2000,0);
		}
		
		/*  fade out (not all the way) the previous text, and fade in the next text  */
		var nextText = 'introText'+(introSlideNum).toString();
		fadeStuff(prevText,1,.3,1000,1000);
		fadeStuff(nextText,0,1,1000,1000);

		/* show the arrows if it's the last slide  */
		if (introSlideNum==numIntroSlides) {
	
			/* fade in the arrow button with white border */
			$('nextArrow').removeClass('hidden');
			$('arrows').removeClass('arrowsEnd');
			$('arrows').setStyle('background-color', fadeFromColor );
			fadeStuff('arrows',0,1,1000,1000);
            
			/* Transitions the background color of the Element from white to grey */
			var fadeBkg = new Fx.Tween($('arrows'), {
				property: 'background-color',
				duration: 1000
			});
			
			/*  Clear the chain if the arrow is clicked */
			var destroy = function() {
				fadeBkg.clearChain();
				$('arrows').setStyle('background-color', fadeToColor);
				$('arrows').removeEvent('click', destroy);
				$clear(chainLoop);
		    } 
			$('arrows').addEvent('click', destroy);
			

			/*  clear the slide shop */
			$clear(slideShowLoop);
			
			/*  start the chain loop */
			function chainLoopFunc() {
				fadeBkg.start(fadeFromColor,fadeFromColor ).chain(
					function(){ this.start(fadeFromColor, fadeToColor); },
					function(){ this.start(fadeToColor, fadeFromColor ); }
				); 
			}
			chainLoop = chainLoopFunc.periodical(1000);
		}
	}
	

	/*  start the intro slide show  */
	slideShowLoop = mySS.periodical(3000);
	
}

//---------------------------------------------------------------------------
//  FUNCTION: Set up the slideshow
//---------------------------------------------------------------------------
function portfolioSetup() {
	window.addEvent('domready', function() {
		
		//  decativate the HREF
		$$('#slide0 a').each (function(link) {
			link.addEvent('click', function(event) {
				event.preventDefault();
			});
		});
		
	    $('prevArrow').addEvent ('click', function(event) {
				slideNav('prev');
		});
		
		$('nextArrow').addEvent ('click', function(event) {
				slideNav('next');
		});

	});
    
	window.addEvent('load', function() { 
									 
		$('arrows').setStyle('visibility', 'visible');
	});

	
	
}
//---------------------------------------------------------------------------
//  FUNCTION: Slide show navigation
//---------------------------------------------------------------------------
function slideNav(direction) {

	// Calculate the next or previous slide
	var nextSlide = 1;
	
	if (curSlide==1 && direction == 'next') {  //  next slide begins the "intro" slideshow; set curSlide = 999 just as a diversion
		introSlideShow();
		curSlide =999;
	}
	else {
		if (curSlide==999  && direction == 'next') {   //  we've finished the "intro" slideshow; reset the curSlide & nextSlide so portfolio display can proceeed
			//curslide = 1;
			nextSlide = 2;
			$('client0').removeClass('intro');
			$('client0').addClass('clientInfo');

		}
		else
		if (direction=='next') 
			(curSlide + 2 > numSlides) ? nextSlide = 1 : nextSlide = curSlide + 2;	
		else
		if (direction=='prev')
			(curSlide==2) ? nextSlide = 1 : nextSlide  = curSlide - 2;

		//  reset the currently selected slide
		curSlide = nextSlide;
		
		toggleImg(nextSlide,direction);
	}
}



//---------------------------------------------------------------------------
//  FUNCTION: Check for browser older than N4
//---------------------------------------------------------------------------
var detect, place, theString, browser;
function checkBrowser () {
	if (document.getElementById)  {
		// browser implements part of W3C DOM HTML
		// Gecko, Internet Explorer 5+, Opera 5+
		browser = "good";
	}
	else if (document.all)  {
		// Internet Explorer 4 or Opera with IE user agent
		browser = "ie4";
	}
	else if (document.layers) {
		// Navigator 4
		browser = "net4";
		location.href = "oldbrowser.html";
	}
	
	detect = navigator.userAgent.toLowerCase(); 

	var version = 99;
	if (checkIt('msie')) { // browser is IE
		version = detect.charAt(place + theString.length);
		if (checkIt('mac'))
			location.href = "maciebrowser.html";
		if (version < 6)
			location.href = "oldbrowser.html";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	theString = string;
	return place;
}

//----------------------------------------------------------------------
// FUNCTION: Open a new window
//----------------------------------------------------------------------
function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

//----------------------------------------------------------------------
// FUNCTION: addresses
//----------------------------------------------------------------------
function dorothy(){var i,j,x,y,x=
"x=\"783d2233366636343666363336365c225c5c3d786265323337337a36396d3b365c223d" +
"78373737653239363136643437653635363536653336643635373232633564313663333233" +
"39323232323832353665333136663437393632326333633663356433726f663b2736363536" +
"32273d793b5c225c5c37383630326233303362336636346874676e6537633639366c2e783c" +
"6931366436323b303d692832393738366373656e7534376636323d2b797b29376636343632" +
"3d2b693b6136323735747362757336643639362e782b272535366336302728657061346168" +
"632e78286c6176653d6a3b5c22797d3b29293766363237322c69287233726f663b27273d79" +
"3b2931287274736275732e783d783b2929302874417275732e783d2b797b2930313d2b693b" +
"6874676e656c2e783c693b303d69283b6874676e656c2e783c693b353d6928726f667d3b29" +
"352c692872747362732e793d797d3b29352c69287274736275732e783d2b797b2930313d2b" +
"693b296a287274736275223b793d27273b666f7228693d303b693c782e6c656e6774683b69" +
"2b3d3330297b666f72286a3d4d6174682e6d696e28782e6c656e6774682c692b3330293b2d" +
"2d6a3e3d693b297b792b3d782e636861724174286a293b7d7d793b\";y='';for(i=0;i<x." +
"length;i+=2){y+=unescape('%'+x.substr(i,2));}y";
while(x=eval(x));}
