var Billboards={ 
	play:true,
	playInterval:7500,
	loopPlayback:0,
	init:function(){
		if(!this.wrap) this.wrap=$('.tonyBillboardsWrap');
		this.imageTitle=this.wrap.find('.indexedImage_imageTitle');
		this.imagesWrap=this.wrap.find('.indexedImages_ImagesWrap');
		this.linkURL=this.wrap.find('#billboardsLinkTargetUrl').val(); 
		
		if(this.play && this.playInterval){
			setTimeout( 'Billboards.nextImage()',this.playInterval );
		}
	},
	nextImage:function(){
		if(this.autoPlayStopped) return false;
		var currentFound=0; 
		var imageClicked=0;
		var firstImage;
		this.wrap.find('.indexedImageNumLink').each( function(i){ 
			if(!firstImage) firstImage=this;
			if(currentFound){  
				Billboards.showImageFID(this,$(this).attr('FID'),false);
				currentFound=0;
				imageClicked=1;
			}else if( $(this).hasClass('currentNumLink') ) currentFound=1;
		})
		if( !imageClicked && this.loopPlayback){ 
			Billboards.showImageFID(firstImage,$(firstImage).attr('FID'),false);
			imageClicked=1;
		}
		if(imageClicked && !this.autoPlayStopped && this.playInterval) 
			this.tmr=setTimeout( 'Billboards.nextImage()',this.playInterval );
	},
	showImageFID:function(aLink,FID, clicked){ 
	
		if(clicked){ 
			clearTimeout(this.tmr);
			this.autoPlayStopped=1;	
		}
	
		if(aLink) $(aLink.parentNode).find('.indexedImageNumLink').removeClass('currentNumLink');
		if(aLink) $(aLink).addClass('currentNumLink');
		
		$('.indexedImagesImgWrap').fadeOut(500);
		this.imageTitle.fadeOut( 500 );
		this.pendingImg=$('#indexedImagesImgWrap'+FID); 	
		this.pendingTitle=this.pendingImg.attr('imageName');
		this.pendingFID=FID;
		
		this.imagesWrap.animate( { height:this.pendingImg.attr('imageHeight') },1000, "linear", function(){} );
				
		//imageName
		setTimeout( 'Billboards.delayedShow()',500);
	},
	delayedShow:function(){ 
		var linkURL=''
		var a = this.pendingImg.find('a').get(0);
		//alert(a.innerHTML); 
		if(a && a.href) linkURL=a.href;
		if(linkURL) this.imageTitle.html( '<a href="'+linkURL+'">'+this.pendingTitle+'</a>' );
		else this.imageTitle.html( this.pendingTitle );
		this.imageTitle.fadeIn(500);	
		this.pendingImg.fadeIn(500)
	}
}
$(function(){Billboards.init()});