
//
// FLASH/FLOATBOX FUNCTIONS
//

// Receive variable from Flash
 function sendToJavaScript(value) {
	 initFloatbox(value);
 };
 

 // Return the type of file - video or image
 function initFloatbox(fileName) {
	clearDiv();
	if (fileName.lastIndexOf(".html") == -1) {
		var strArray = new Array();
		strArray = fileName.split("_");
		strRelOptions = '';
		addAnchors(strArray);
	} else {
		fb.loadAnchor(fileName); // Passed as HREF.	
	}
	fb.tagAnchors(document.body);
	fb.start(document.getElementById('fb1'));
 };
 
// Add anchor and attributes to div named "fbLinks".
// 0 = name, 1 = number of that type, 2 = type: video/image, 3 = number of items, 4 = dimensions.
function addAnchors(strArray) {
	var el = document.getElementById('fbLinks');
	for (i=1; i<=strArray[3]; i++) {
		var a = document.createElement('a');
		a.setAttribute('id', 'fb'+i);
		var rel='floatbox.'+strArray[0]+strArray[2]+strArray[1];
		var ext;
		if (strArray[2] == "image") ext=".jpg";  // For Print pieces.
		if (strArray[2] == "video") ext=".mov";  // For TV Spots or videos.
		var url = 'print/large/'+strArray[0]+"_"+strArray[1]+"_"+strArray[2]+"_"+i+ext;
		a.setAttribute('rel', rel);
		a.setAttribute('href', url);
		if (strArray[4]) {
			revArray = strArray[4].split("x");
			var h = revArray[0];
			var w = revArray[1];
			var rev = "width:"+h+" height:"+w+" scrolling:no";  // rev="width:400 height:300"
			a.setAttribute('rev', rev);
		}
		// alert ("rel: "+rel+", url: "+url);
		el.appendChild(a);
	}
};

function clearDiv() {
	var el = document.getElementById('fbLinks');
	if ( el.hasChildNodes() ) {
		while ( el.childNodes.length >= 1 ) {
			el.removeChild( el.firstChild );       
		} 
	}
	fb.tagAnchors(document.body); // Clear floatbox.
};
