var appVersion = navigator.appVersion;
var ie4 = (document.all) ? true : false;
var ie5 = ( navigator.appVersion.indexOf("MSIE 5") != -1 );
var ns4 = ( document.layers) ? true : false;
var ns6 = ( (navigator.appName.indexOf("Netscape") != -1) && parseInt(navigator.appVersion) >= 5 );
var mac = ( navigator.userAgent.indexOf("Mac") != -1) ? true : false;
var sf01 = ( navigator.userAgent.indexOf("KHTML") != -1);
var sf12 = ( parseInt(navigator.appVersion.replace(/.*AppleWebKit\//i, "")) >= 124 ) ;

function imgComplete( img ) { return ( img.complete ); }
function sfImgComplete( img ) { return ( img.width > 0 ); }
function ieRedrawWindow() { window.resizeBy( 0, 1 ); window.resizeBy( 0, -1 ); }
function redrawWindow() { }

if ( mac && ie5 ) {
	redrawWindow = ieRedrawWindow;
	Array.prototype.push = function() {
	
		var thisArray = this, x;
		for ( x=0; x < arguments.length; x++ ) {
			thisArray[ thisArray.length ] = arguments[x];
		}
		return thisArray.length;
	}
}

if ( sf01 || sf12 ) imgComplete = sfImgComplete;

var imgPath = "/img/", thumbPath = '/img/stills/', moviePath = '/mov/', thumbCache, projectTypeLabels, viewerTitle, viewerImg, viewer, clientDiv;

function buildHeader() {
	var out = '				<td align="center" valign="top"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0">'
		+ '\n				  <tr>'
		+ '\n					<td><table id="Table_01" width="900" height="713" border="0" cellpadding="0" cellspacing="0" align="center">'
		+ '\n					  <tr>'
		+ '\n						<td colspan="5">&nbsp;</td>'
		+ '\n						<td><img src="../images/nav_w_tip.jpg" width="18" height="39" alt="W"></td>'
		+ '\n						<td colspan="5">&nbsp;</td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td colspan="3"><img src="../images/nav_left1.jpg" width="386" height="114" alt="nav"></td>'
		+ '\n						<td colspan="4" rowspan="4"><img src="../images/nav_w.jpg" width="128" height="233" alt="W"></td>'
		+ '\n						<td colspan="4"><img src="../images/nav_right1.jpg" width="386" height="114" alt="nav"></td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td rowspan="4"><img src="../images/nav_left2.jpg" width="106" height="154" alt="nav"></td>'
		+ '\n						<td colspan="2"><img src="../images/nav_mark_woollen.jpg" width="280" height="58" alt="Mark Woollen"></td>'
		+ '\n						<td colspan="3"><img src="../images/nav_motion_design.jpg" width="280" height="58" alt="Motion Design"></td>'
		+ '\n						<td rowspan="4"><img src="../images/nav_right2.jpg" width="106" height="154" alt="nav"></td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td colspan="2"><a href="index2.html" target="_self"> <img src="../images/nav_b_home.jpg" width="280" height="33" border="0" alt="Home Page"></a></td>'
		+ '\n						<td colspan="3"><a href="http://www.markwoollen.com" target="_blank"> <img src="../images/nav_b_mwa_trailer.jpg" width="280" height="33" border="0" alt="MWA Trailer Site"></a></td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td colspan="2"><img src="../images/nav_left3.jpg" width="280" height="28" alt="nav"></td>'
		+ '\n						<td colspan="3"><img src="../images/nav_right_3.jpg" width="280" height="28" alt="nav"></td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td><a href="clientaccess.html" target="_self"> <img src="../images/nav_b_client.jpg" width="194" height="35" border="0" alt="Client Access"></a></td>'
		+ '\n						<td colspan="2"><a href="contact.html" target="_self"> <img src="../images/nav_b_contact.jpg" width="124" height="35" border="0" alt="Contact"></a></td>'
		+ '\n						<td colspan="4"><a href="about.html" target="_self"> <img src="../images/nav_b_about.jpg" width="114" height="35" border="0" alt="About"></a></td>'
		+ '\n						<td><a href="reel.html" target="_self"> <img src="../images/nav_b_reel.jpg" width="73" height="35" border="0" alt="Reel"></a></td>'
		+ '\n						<td><a href="featuredwork.html" target="_self"> <img src="../images/nav_b_featured.jpg" width="183" height="35" border="0" alt="Featured Work"></a></td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td height="405" colspan="11" background="../images/body_template.jpg">&nbsp;</td>'
		+ '\n					  </tr>'
		+ '\n					  <tr>'
		+ '\n						<td><img src="../images/spacer.gif" width="106" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="194" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="86" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="38" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="17" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="18" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="55" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="24" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="73" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="183" height="1" alt="spacer"></td>'
		+ '\n						<td><img src="../images/spacer.gif" width="106" height="1" alt="spacer"></td>'
		+ '\n					  </tr>'
		+ '\n					</table></td>'
		+ '\n				  </tr>'
		+ '\n				</table>'
		+ '\n				</td>'
	document.write(out);
}

function buildFooter() {
	var out = '</div></td></tr></table>'
			+ '\n<table border="0" cellpadding="0" cellspacing="0" align="center"><tr><td><div class="footer">207 Ashland Ave. Santa Monica, CA 90405<img src="/img/dotGrey.gif" width="9" height="10" alt="" hspace="5" align="top" />Tel.310.399.2690<img src="/img/dotOrange.gif" width="9" height="10" alt="" hspace="5" align="top" />Fax.310.399.2670<img src="/img/dotBlack.gif" width="9" height="10" alt="" hspace="5" align="top" />&nbsp;<a href="mailto:info@markwoollen.net">info @ markwoollen.net</a></div></div></td></tr></table>';
	document.write(out);
}


// C L I E N T    A C C E S S
function Client( client, url ) {
	this.client = client;
	this.url = url;
}

function showClients() {
	clientDiv = d('clients');
	for ( var x=0; x < clientList.length; x++ )
		clientDiv.innerHTML += '\n<a onmouseover="clearTimeout(clientListTimer)" onmouseout="hideClientList()" href="/' + clientList[x].url + '">' + clientList[x].client + '</a>';
}

var clientListTimer;
function hideClientList() {
	clientListTimer = setTimeout( 'clientDiv.style.display = "none"', 1000 );
}

// D E M O    R E E L   F U N C T I O N S
function init() {
	projectTypeLabels = d("projectTypeLabels");
	viewerTitle = d("viewerTitle");
	viewerImg = d("viewerImg");
	viewer = d("viewer");
}	

function Movie( fileName ) {
	var thisMovie = new Object();
	thisMovie.file = fileName + '.jpg';
	thisMovie.title = fileName.replace(/_/g, ' ');
	thisMovie.projects = [];
	for ( var x=1; x < arguments.length; x++ ) {
		thisMovie.projects[ thisMovie.projects.length ] = arguments[x];
	}
	return thisMovie;
}

var movieThumbs = [];
function preloadThumbs() {
	for ( var x=0; x < movieList.length; x++ ) {
		preloadThumbs[x] = new Image();
		preloadThumbs[x].src = thumbPath + movieList[x].file;
		window.status = "Loading: " + movieList[x].title;
	}
	window.status = null;
}

function buildMovieList() {
	var thisMovie, x, out = '';
	for ( x=0; x < movieList.length; x++ ) {
		thisMovie = movieList[x];
		out += '<a href="javascript:showMovie(' + x + ')" onmouseover="showThumb(' + x + ')" onmouseout="clearViewer()">' + thisMovie.title + '<img src="/img/casper.gif" width="15" height="16" alt="" class="qtLogo" border="0" align="top" hspace="2" /></a>';
	}
	document.write( out );
	preloadThumbs();
}


function showThumb( movieIndex ) {
	clearTimeout( thumbCache );
	projectTypeLabels.innerHTML = "";
	var thisMovie = movieList[ movieIndex ];
	viewerImg.src = thumbPath + thisMovie.file;
	viewerTitle.innerHTML = thisMovie.title;
	for ( var x = 0; x < thisMovie.projects.length; x++ ) {
		projectTypeLabels.innerHTML += projectTypes[ thisMovie.projects[x] ] + '<br />';
	}
}	

function clearViewer() {
	thumbCache = setTimeout( resetViewer, 1000 );
}

function resetViewer() {
	viewerImg.src= "/img/3bigSquares.gif";
	projectTypeLabels.innerHTML = "";
	viewerTitle.innerHTML = "";
}

function newWin( url, width, height ) {
	var newWin = window.open( url, '', 'width=' + width + ',height=' + height + ',resizable');
	newWin.focus();
	return newWin;
}

function showMovie( movieIndex ) {
	var movieWin = newWin( '/movieViewer.html?movieURL=' + movieList[ movieIndex ].title.replace(/\ /gi, '_'), 340, 265 );
}

function buildMoviePlayer( movieURL, width, height ) {
	var out = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + width + '" height="' + height + '" codebase="http://www.apple.com/qtactivex/qtplugin.cab">'
			+ '\n	<param name="src" value="' + movieURL + '">'
			+ '\n	<param name="autoplay" value="true">'
			+ '\n	<param name="controller" value="true">'
			+ '\n<embed src="' + movieURL + '" width="' + width + '" height="' + height + '" autoplay="true" controller="true" kioskmode="TRUE" pluginspage="http://www.apple.com/quicktime/download/"> </embed>'
			+ '\n</object>'
	document.body.innerHTML = out;
//Debug( out, true );
}

function swap( imgSrc ) {
	document.images["3bigElipses"].src = imgPath + imgSrc + ".gif";
}


var queryData = new Array(), queryDataArray = top.location.search.substr(1).split(/\&|;|\&;/);
for ( var x=0; x < queryDataArray.length; x++ ) {
	var thisQueryVariable = queryDataArray[x].split("=");
	queryData[ thisQueryVariable[0] ] = new Object();
	queryData[ thisQueryVariable[0] ] = thisQueryVariable[1];
}

function Debug(str,code) {
	var str_debug = "";
	if ( code ) {
		str_debug += '<html><body marginheight="0" style="white-space: pre;font-family: Monaco,Courier;font-size:9px;">\n\n';
		str_debug += str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
	}
	else {
		str_debug += '<body marginheight="0" marginwidth="0">\n\n';
		str_debug += str;
	}
	str_debug += "\n\n</body></html>";
	var debugWindow = window.open();
	debugWindow.document.write(str_debug);
}

function d( id ) {	return document.getElementById( id ); }

