/* class for individual bottomShowcase slides */



function bottomShowcaseItem( url , imgUrl , headline , display_name , display_url ){
	this.url = url;
	this.imgUrl = imgUrl;
	this.headline = headline;
	this.display_name = display_name;
	this.display_url = display_url;	
	this.parentBrowser = null;
}						
							
/* class for the slide player */
function bottomShowcaseBrowser( elementId, leftArrowId, rightArrowId, displayItemsCount , scrollItemsCount, imgSrc ){
	this.elementId = elementId;
	this.leftArrowId = leftArrowId;
	this.rightArrowId = rightArrowId;
	this.displayItemsCount = displayItemsCount;		// total number of items to be displayed at one time
	this.scrollItemsCount = scrollItemsCount;		// how many items to scroll by when clicking next or previous
	this.itemArray = new Array();
	this.itemIndex = 0;
	this.imgSrc = imgSrc;
	this.leftImgOff = this.imgSrc + "moth_reverse_off.gif";
	this.leftImgOn = this.imgSrc + "moth_reverse.gif";
	this.rightImgOff = this.imgSrc + "moth_forward_off.gif";
	this.rightImgOn = this.imgSrc + "moth_forward.gif";
	
	// self-register
	//this = window.bottomShowcaseBrowserInstance;
}


bottomShowcaseBrowser.prototype.showButtons = function(){
	if (document.createElement){
	
		//begin left arrow
		MOTHleftArrow = document.getElementById(this.leftArrowId);
		//create image
		isOff = (this.itemIndex == 0);
		MOTHleftArrowImg = document.createElement("IMG");
		state = (isOff) ? this.leftImgOff : this.leftImgOn;
		MOTHleftArrowImg.setAttribute("src", state );
		MOTHleftArrowImg.setAttribute("name", "moth_reverse"); 
				
		//create anchor
		if (!isOff){
			MOTHleftArrowAnchor = document.createElement( "A" );
			MOTHleftArrowAnchor.setAttribute("href", "javascript:browser.update(0)");
			MOTHleftArrowAnchor.appendChild(MOTHleftArrowImg);
			MOTHleftArrow.appendChild(MOTHleftArrowAnchor);
		} else {
			MOTHleftArrow.appendChild(MOTHleftArrowImg);
		}
		//end left arrow

		//begin right arrow
		MOTHrightArrow = document.getElementById(this.rightArrowId);
		//create image
		isOff = ((this.itemIndex + this.displayItemsCount) >= this.itemArray.length);
		MOTHrightArrowImg = document.createElement("IMG");
		state = (isOff) ? this.rightImgOff : this.rightImgOn;
		MOTHrightArrowImg.setAttribute("src", state );
		MOTHrightArrowImg.setAttribute("name", "moth_forward"); 
		//create anchor
		if (!isOff){	
			MOTHrightArrowAnchor = document.createElement("A");
			MOTHrightArrowAnchor.setAttribute("href" , "javascript:browser.update(1)");
			MOTHrightArrowAnchor.appendChild(MOTHrightArrowImg);
			MOTHrightArrow.appendChild(MOTHrightArrowAnchor);
		} else {
			MOTHrightArrow.appendChild(MOTHrightArrowImg);
		}	
		//end right arrow
	}
}


bottomShowcaseItem.prototype.write = function(  ){
	if( document.createElement ){
		parentElement = document.getElementById( this.parentBrowser.elementId );
		if( parentElement.tagName == "TABLE" && this.parentBrowser.getBodyRow ){
			
			// create header
			headerObj = document.createElement( "TH" );
			headerTitleObj = document.createElement( "H4" );
			if (this.display_url == "#") { 
				anchorObj = document.createTextNode(this.display_name);
			} else {
				anchorObj = document.createElement("A");
				anchorObj.setAttribute("href", this.display_url);
				anchorObj.appendChild(document.createTextNode( this.display_name + " »"));
			}
					
			
			// create body
			tdObj = document.createElement( "TD" );
			storyObj = document.createElement( "DIV" );
			storyObj.className = "story";
			calloutObj = document.createElement( "DIV" );
			calloutObj.className = "callout";
			calloutLinkObj = document.createElement( "A" );
			calloutLinkObj.setAttribute( "href" , this.url );
			calloutImgObj = document.createElement( "IMG" );
			calloutImgObj.setAttribute( "src" , this.imgUrl );
			calloutImgObj.setAttribute( "alt" , this.headline );
			calloutLinkObj.appendChild( calloutImgObj );
			calloutObj.appendChild( calloutLinkObj );
			storyObj.appendChild( calloutObj );
			headlineObj = document.createElement( "H5" );
			headlineLinkObj = document.createElement( "A" );
			headlineLinkObj.setAttribute( "href" , this.url );
			headlineLinkObj.appendChild( document.createTextNode( this.headline ) );
			headlineObj.appendChild( headlineLinkObj );
			storyObj.appendChild( headlineObj );
			tdObj.appendChild( storyObj );
			this.parentBrowser.getBodyRow().appendChild( tdObj );	
		}
	}
}							
							
bottomShowcaseBrowser.prototype.addItem = function( item ){
	if( item instanceof bottomShowcaseItem ){
		item.parentBrowser = this;
		this.itemArray.push( item );
	}
}			
							
bottomShowcaseBrowser.prototype.update = function( doMoveRight ){
	tableObj = document.getElementById( this.elementId );
	
	//increment index count
	var origIndex = this.itemIndex;
	this.itemIndex = (doMoveRight) ? this.itemIndex + this.scrollItemsCount : this.itemIndex - this.scrollItemsCount;
	
	//set upper and lower bounds
	this.upperBound = this.itemArray.length - this.displayItemsCount;
	this.itemIndex = ((this.itemIndex + this.displayItemsCount) > this.itemArray.length) ? this.itemArray.length-this.displayItemsCount : this.itemIndex;
	this.itemIndex = (this.itemIndex < 0) ? 0 : this.itemIndex;
	
	//update button images
	this.deleteAllChildrenOf(document.getElementById(this.leftArrowId));
	this.deleteAllChildrenOf(document.getElementById(this.rightArrowId));
	this.showButtons();
	
	if (origIndex != this.itemIndex){
		//clear 
		this.deleteAllChildrenOf( this.getBodyRow() );
		
		// re-populate
		for( iUpdate=this.itemIndex ; iUpdate < (this.itemIndex + this.displayItemsCount) ; iUpdate++ ){
			this.itemArray[iUpdate].write();
		}
	}
}

bottomShowcaseBrowser.prototype.getBodyRow = function(){
	return document.getElementById( this.elementId ).getElementsByTagName( "TBODY" )[0].getElementsByTagName( "TR" )[0];
}

bottomShowcaseBrowser.prototype.deleteAllChildrenOf = function( elementObj ){
	while (elementObj.hasChildNodes()) elementObj.removeChild(elementObj.firstChild);
}



/* class for individual bottomShowcaseRight slides */




function bottomShowcaseRightItem( url , imgUrl , headline , display_name , display_url ){
	this.url = url;
	this.imgUrl = imgUrl;
	this.headline = headline;
	this.display_name = display_name;
	this.display_url = display_url;	
	this.parentBrowser = null;
}						
							
/* class for the slide player */
function bottomShowcaseRightBrowser( elementId, leftArrowId, rightArrowId, displayItemsCount , scrollItemsCount, imgSrc ){
	this.elementId = elementId;
	this.leftArrowId = leftArrowId;
	this.rightArrowId = rightArrowId;
	this.displayItemsCount = displayItemsCount;		// total number of items to be displayed at one time
	this.scrollItemsCount = scrollItemsCount;		// how many items to scroll by when clicking next or previous
	this.itemArray = new Array();
	this.itemIndex = 0;
	this.imgSrc = imgSrc;
	this.leftImgOff = this.imgSrc + "moth_reverse_off.gif";
	this.leftImgOn = this.imgSrc + "moth_reverse.gif";
	this.rightImgOff = this.imgSrc + "moth_forward_off.gif";
	this.rightImgOn = this.imgSrc + "moth_forward.gif";
	
	// self-register
	//this = window.bottomShowcaseRightBrowserInstance;
}


bottomShowcaseRightBrowser.prototype.rightShowButtons = function(){
	if (document.createElement){
	
		//begin left arrow
		MOTHleftArrow = document.getElementById(this.leftArrowId);
		//create image
		isOff = (this.itemIndex == 0);
		MOTHleftArrowImg = document.createElement("IMG");
		state = (isOff) ? this.leftImgOff : this.leftImgOn;
		MOTHleftArrowImg.setAttribute("src", state );
		MOTHleftArrowImg.setAttribute("name", "moth_reverse"); 
				
		//create anchor
		if (!isOff){
			MOTHleftArrowAnchor = document.createElement( "A" );
			MOTHleftArrowAnchor.setAttribute("href", "javascript:browserRight.update(0)");
			MOTHleftArrowAnchor.appendChild(MOTHleftArrowImg);
			MOTHleftArrow.appendChild(MOTHleftArrowAnchor);
		} else {
			MOTHleftArrow.appendChild(MOTHleftArrowImg);
		}
		//end left arrow

		//begin right arrow
		MOTHrightArrow = document.getElementById(this.rightArrowId);
		//create image
		isOff = ((this.itemIndex + this.displayItemsCount) >= this.itemArray.length);
		MOTHrightArrowImg = document.createElement("IMG");
		state = (isOff) ? this.rightImgOff : this.rightImgOn;
		MOTHrightArrowImg.setAttribute("src", state );
		MOTHrightArrowImg.setAttribute("name", "moth_forward"); 
		//create anchor
		if (!isOff){	
			MOTHrightArrowAnchor = document.createElement("A");
			MOTHrightArrowAnchor.setAttribute("href" , "javascript:browserRight.update(1)");
			MOTHrightArrowAnchor.appendChild(MOTHrightArrowImg);
			MOTHrightArrow.appendChild(MOTHrightArrowAnchor);
		} else {
			MOTHrightArrow.appendChild(MOTHrightArrowImg);
		}	
		//end right arrow
	}
}


bottomShowcaseRightItem.prototype.write = function(  ){
	if( document.createElement ){
		parentElement = document.getElementById( this.parentBrowser.elementId );
		if( parentElement.tagName == "TABLE" && this.parentBrowser.getBodyRow ){
			
			// create header
			headerObj = document.createElement( "TH" );
			headerTitleObj = document.createElement( "H4" );
			if (this.display_url == "#") { 
				anchorObj = document.createTextNode(this.display_name);
			} else {
				anchorObj = document.createElement("A");
				anchorObj.setAttribute("href", this.display_url);
				anchorObj.appendChild(document.createTextNode( this.display_name + " »"));
			}
			
			// create body
			tdObj = document.createElement( "TD" );
			storyObj = document.createElement( "DIV" );
			storyObj.className = "story";
			calloutObj = document.createElement( "DIV" );
			calloutObj.className = "callout";
			calloutLinkObj = document.createElement( "A" );
			calloutLinkObj.setAttribute( "href" , this.url );
			calloutImgObj = document.createElement( "IMG" );
			calloutImgObj.setAttribute( "src" , this.imgUrl );
			calloutImgObj.setAttribute( "alt" , this.headline );
			calloutLinkObj.appendChild( calloutImgObj );
			calloutObj.appendChild( calloutLinkObj );
			storyObj.appendChild( calloutObj );
			headlineObj = document.createElement( "H5" );
			headlineLinkObj = document.createElement( "A" );
			headlineLinkObj.setAttribute( "href" , this.url );
			headlineLinkObj.appendChild( document.createTextNode( this.headline ) );
			headlineObj.appendChild( headlineLinkObj );
			storyObj.appendChild( headlineObj );
			tdObj.appendChild( storyObj );
			this.parentBrowser.getBodyRow().appendChild( tdObj );	
		}
	}
}							
							
bottomShowcaseRightBrowser.prototype.addRightItem = function( item ){
	if( item instanceof bottomShowcaseRightItem ){
		item.parentBrowser = this;
		this.itemArray.push( item );
	}
}			
							
bottomShowcaseRightBrowser.prototype.update = function( doMoveRight ){
	tableObj = document.getElementById( this.elementId );
	
	//increment index count
	var origIndex = this.itemIndex;
	this.itemIndex = (doMoveRight) ? this.itemIndex + this.scrollItemsCount : this.itemIndex - this.scrollItemsCount;
	
	//set upper and lower bounds
	this.upperBound = this.itemArray.length - this.displayItemsCount;
	this.itemIndex = ((this.itemIndex + this.displayItemsCount) > this.itemArray.length) ? this.itemArray.length-this.displayItemsCount : this.itemIndex;
	this.itemIndex = (this.itemIndex < 0) ? 0 : this.itemIndex;
	
	//update button images
	this.deleteAllChildrenOf(document.getElementById(this.leftArrowId));
	this.deleteAllChildrenOf(document.getElementById(this.rightArrowId));
	this.rightShowButtons();
	
	if (origIndex != this.itemIndex){
		//clear 
		this.deleteAllChildrenOf( this.getBodyRow() );
		
		// re-populate
		for( iUpdate=this.itemIndex ; iUpdate < (this.itemIndex + this.displayItemsCount) ; iUpdate++ ){
			this.itemArray[iUpdate].write();
		}
	}
}

bottomShowcaseRightBrowser.prototype.getBodyRow = function(){
	return document.getElementById( this.elementId ).getElementsByTagName( "TBODY" )[0].getElementsByTagName( "TR" )[0];
}

bottomShowcaseRightBrowser.prototype.deleteAllChildrenOf = function( elementObj ){
	while (elementObj.hasChildNodes()) elementObj.removeChild(elementObj.firstChild);
}













