/*
 * NB - this requires scrips.js for browser detection
 */
var showCase					= {
	sFlashMoviePath : '/_swf/showcaseImageClipper.swf',					// this is the swf we are going to swap in
	sShowcaseID : 'showCaseHolder',										// this is the showcase element ID
	sImageClass : 'mainShowcaseImage',									// this is the class we are using to target the image
	sMovieIDPrefix : 'showcaseSWF',										// this is the new movie prefix
	sMovieHolderPrefix : 'showcaseSWFHolder',							// this is the new movie span prefix
	nFlashWidth : 364,													// this is the width of the flash movie replacement
	nFlashHeight : 170,													// this is the height of the flash movie replacement
	sFlashVersion : '8,0,0,0',											// this is the flash version
	sFlashBGColor : '#F2F2F2',											// this is the flash bg color
	init : function() {
		if(!document.getElementById||!document.createTextNode){return;}
		showCase.swapOutImages();
	},
	
	swapOutImages : function() {
		if (!document.getElementById(showCase.sShowcaseID)) {return;}
		var eShowcase			= document.getElementById(showCase.sShowcaseID);
		var aAllImages			= getAllChildren(eShowcase, 'img');
		var nCount				= 0;
		
		if (!aAllImages.length) {return;}
		
		for (var i = 0; i < aAllImages.length; i++) {
			if (aAllImages[i].className != showCase.sImageClass) {
				continue;
			}
			
			if (showCase.isJPEG(aAllImages[i])) {
				showCase.replaceWithFlash(aAllImages[i], ++nCount);
			}
		}
	},
	
	isJPEG : function (eImage) {
		var sFileName			= eImage.src;
		var aSplit				= sFileName.split(".");
		var sExtension			= aSplit[aSplit.length - 1];
		
		return (sExtension == 'jpg' || sExtension == 'jpeg') ? true : false;
	},
	
	replaceWithFlash : function (eImage,nCount) {
		var eSpan				= showCase.updateSpan(eImage,nCount);
		eSpan.innerHTML			= showCase.createFlashMovie(nCount,eImage);
	},
	
	createFlashMovie : function(nCount,eImage) {
		var sHTML				= '';
		
		sHTML					= sHTML.concat('<object id="' + showCase.sMovieIDPrefix + nCount + '"');
		sHTML					= sHTML.concat(' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + showCase.sFlashVersion + '"');
		sHTML					= sHTML.concat(' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
		sHTML					= sHTML.concat(' height="' + showCase.nFlashHeight + '"');
		sHTML					= sHTML.concat(' width="' + showCase.nFlashWidth + '">');
		sHTML					= sHTML.concat('<param name="allowscriptaccess" value="sameDomain"/>');
		sHTML					= sHTML.concat('<param name="movie" value="' + showCase.sFlashMoviePath + '?sImagePath=' + escape(eImage.src) + '"/>');
		sHTML					= sHTML.concat('<param name="quality" value="high"/>');
		sHTML					= sHTML.concat('<param name="bgcolor" value="' + showCase.sFlashBGColor + '"/>');
		sHTML					= sHTML.concat('<embed pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" name="');
		sHTML					= sHTML.concat(showCase.sMovieIDPrefix + nCount);
		sHTML					= sHTML.concat('" bgcolor="');
		sHTML					= sHTML.concat(showCase.sFlashBGColor);
		sHTML					= sHTML.concat('" quality="high" src="');
		sHTML					= sHTML.concat(showCase.sFlashMoviePath + '?sImagePath=' + escape(eImage.src));
		sHTML					= sHTML.concat('" height="' + showCase.nFlashHeight + '" width="' + showCase.nFlashWidth + '"/>');
		sHTML					= sHTML.concat('</object>');
		
		return sHTML;
	},
	
	updateSpan : function (eImage,nCount) {
		var eSpan				= eImage.parentNode
		eSpan.id				= showCase.sMovieHolderPrefix + nCount;
		return eSpan;
	}
}

WindowListener.add("load","showCase.init()");