// JavaScript Document
var playing;
var imgswp;

function imageSwap( imgElement, destPath, millisecondsToSwap, nextImageSrc )
{
	//this.imageSwapElement = new Object();
	this.imageSwapElement = imgElement;
	
	this.imageDestImg = new Image();
	this.imageDestImg.src = destPath;
	
	if ( nextImageSrc )
	{
		this.loadNextImage = new Image();
		this.loadNextImage.src = nextImageSrc;
		
		//this.loadNextImage.onload = function() { alert("loaded") }
	}

	this.millisecondsToSwap = millisecondsToSwap;
	
	this.run = runImageSwap;
	this.intervalTime = 60;
	this.interval = null;
	
	this.fadeLevel = 100;
	this.fade = fadeImage;
	this.direction = -1;
}

function runImageSwap()
{
	this.adjustmentPerPeriod = 100 / ( ( this.millisecondsToSwap/this.intervalTime ) / 2 );
	
	clearInterval( this.interval );
	this.interval = setInterval( "imgswp.fade()", this.intervalTime );
}

function fadeImage()
{
	this.fadeLevel = this.fadeLevel + this.direction * this.adjustmentPerPeriod;
	
	if 		( typeof this.imageSwapElement.style.MozOpacity != "undefined" ) 	
		this.imageSwapElement.style.MozOpacity = this.fadeLevel / 100;
	else if ( typeof this.imageSwapElement.style.opacity != "undefined" ) 		
		this.imageSwapElement.style.opacity = this.fadeLevel / 100;
	else if ( typeof this.imageSwapElement.filters == "object" ) 
		this.imageSwapElement.filters.alpha.opacity = this.fadeLevel;
	else
	{
		this.imageSwapElement.src = this.imageDestImg.src;
		clearInterval( this.interval );
		return;
	}
	
	
	if ( this.fadeLevel <= 0 )
	{
		if ( this.imageDestImg.complete )
		{
			this.imageSwapElement.src = this.imageDestImg.src;
			this.direction = 1;
			this.fadeLevel = 0;
		}
	}
	else if ( this.fadeLevel >= 100 )
	{
		clearInterval( this.interval );	
	}
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function stopSong(id)
{
		var playerDiv = $('playerDiv');
		playerDiv.innerHTML = '';
		$(''+id+'').src = "images/play.gif";
}

function changeSong(song,id)
{
	if(id == playing) stopSong(id);
	else {
		var i;
		var playerDiv = $('playerDiv');
		playerDiv.innerHTML = insertFlash( "flash/mp3Player.swf", 1, 1, 8, "song="+song+"");
		for(i=1; i<=11; i++) {
			if (id == i) $(''+i+'').src = "images/stop.gif";
			else $(''+i+'').src = "images/play.gif";
		}
	}
	playing = id;
}

function insertFlash( src, width, height, version, FlashVars )
{
	var output = '';
	
	output += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" width="' + width + '" height="' + height + '" align="middle">';
	output += '<param name="allowScriptAccess" value="sameDomain" />';
	output += '<param name="movie" value="' + src + '" />';
	output += '<param name="quality" value="high" />';
	output += '<param name="bgcolor" value="#ffffff" />';
	output += '<param name="wmode" value="transparent" />';
	output += '<param name="FlashVars" value="' + FlashVars + '" />';
	
	output += '<embed src="' + src + '" quality="high" FlashVars="' + FlashVars + '" wmode="transparent" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="special" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />';
	output += '</object>';

	return output;
}

function writeFlash( src, width, height, version, FlashVars )
{
	document.write( insertFlash( src, width, height, version, FlashVars ) );
}

function showContent(id) {
	var div = document.getElementById(id).style;
	div.display = "block";
	window.scrollTo(0,400);
}

function hideIt(id) {
	var div = document.getElementById(id).style;
	div.display = "none";
	window.scrollTo(0,0);
}

function scrollDown(end) {
	if ( window.pageYOffset < end ) {
		alert('here');
		setTimeout("scroller", 1000);
	}
}

function scroller() {
	window.scrollBy(0,20);
	scrollDown(650);
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function changeInner(cid,content) {
	$(cid).innerHTML = $(content).innerHTML;
	$('content0').style.top = "0px";
	$('scroller0').style.top = "0px";
	scroller.init;
}
function changeVideo(id,cid) {
	var stringer = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'+id+'&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
	$(cid).innerHTML = stringer;
}

function displayGalleries(photos) {
	var i,j=0,stringer;
	stringer = "<p>PICK A PHOTOGRAPHER:</p>"
	for(i in photos) {
		stringer += '<p class="pics"><a class="pics" href="Javascript:changeThumbs(photos,\''+i+'\',\'gallery'+j+'\')" id="gallery'+j+'">'+i.replace(new RegExp(/_/g), " ").substr(2)+'</a></p>';
		j++;
	}
	$('content1').innerHTML = stringer;
}

function changeThumbs(photos,id,gallery) {
	var stringer,i,j;
	var stringer = "<p>CLICK THE PICS TO ENLARGE</p>";
	for(i=0;i<photos[id].length;i++) {
			stringer += '<a href="Javascript:changePhoto(\''+photos[id][i].replace("tn/","").replace(".jpg",".png")+'\')"><img src="'+photos[id][i]+'" height="57" class="pic" alt="Thomas" /></a>';
			if (i+1%3 == 0) stringer += "<br />";
	}
	$('content2').style.top = "0px";
	$('scroller2').style.top = "0px";
	for(j=0;j<galleryCount;j++) $('gallery'+j).style.color = "#000000";
	$(gallery).style.color = "#C82127";
	$('content2').innerHTML = stringer;
	changePhoto(''+photos[id][0].replace("tn/","").replace(".jpg",".png")+'');
	/*if(id.indexOf("Tom_Casey") !== -1) $('imagePlace').style.border = '2px solid #666666';*/
	/*if(id.indexOf("Tom_Casey") !== -1) $('imagePlace').style.border = '2px solid #FFFFFF';
	else $('imagePlace').style.border = "0px solid #ffffff";*/
	if (navigator.appName.indexOf("Microsoft Internet")==-1) { 
		fixpng();
	}
}

function changePhoto(photo) {
	//imageSwap( imagePlace, imagePlace.src, 1000, photo );
	
	if (navigator.appName.indexOf("Microsoft Internet")!=-1) { 
		var img = new Image();
		img.src = photo;
		$('content0').innerHTML = '<img src="'+photo+'"  alt="Thomas" onLoad="fixpng();" id="imagePlace" />';
	}
	else {
		if ( imgswp )	clearInterval( imgswp.interval );
		imgswp = new imageSwap( $('imagePlace'), photo, 2000, $('imagePlace').src );
		imgswp.run();
	}
	//$('content0').innerHTML = '<img src="'+photo+'" alt="Thomas" />';	
}

function fixpng() {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}