/* ********************************************************* */
/* This script file defines functions used by the banner widget 
/* for the Investor Home Page
/*                           
/* ********************************************************* */
function CInvestorBannerWidget() { }
CInvestorBannerWidget.prototype =
{
    /* ************************************ */
    /* Properties                           */
    /* ************************************ */
  imageContainer : '',	
	pagerContainer : '',
	/* ************************************ */
	/* Public Methods                       */
	/* ************************************ */
	 AttachEvents: function() {
		 //append play button to nav
		var btnResumeCycle = $("<a class='feature-btn-pause' id='resumeCycle' href='#' onclick='return false;' title='Pause'><span>Pause</span></a>");
		btnResumeCycle.appendTo(this.pagerContainer);
		var imageCon = this.imageContainer;
		var isplaying = true;
		var pauseTimeoutId;
		//button event
		$('#resumeCycle').click(function() {
			 if(isplaying){
				$(imageCon).cycle('pause');
				$(this).removeClass('feature-btn-pause').addClass('feature-btn-play').attr('title','Resume');
				isplaying = false;
			 }else{
				 $(imageCon).cycle('resume');
				 $(this).removeClass('feature-btn-play').addClass('feature-btn-pause').attr('title','Pause');
				 isplaying = true;
				}
		});
		
		// pause for image hover
		$(imageCon).hover(
				function(){
					pauseTimeoutId = setTimeout(pauseCycle,900);
				},									
				function(){
					clearTimeout(pauseTimeoutId);
				}									
		);
		
		// pause for over-lay text hover
		$('#overlay-text').hover(
				function(){
					pauseTimeoutId = setTimeout(pauseCycle,900);
				},									
				function(){
					clearTimeout(pauseTimeoutId);
				}									
		);
		
		function pauseCycle(){
			$(imageCon).cycle('pause');		
			$('#resumeCycle').removeClass('feature-btn-pause').addClass('feature-btn-play').attr('title','Resume').focus();
			isplaying = false;
		}
		
		function resumeCycle(){
			
			//$(imageCon).cycle('resume');
			//$('resumeCycle').removeClass('feature-btn-play').addClass('feature-btn-pause').attr('title','Pause');
			//isplaying = true;
		}
	},

	CycleImages : function(speedParam, timeOutParam)	{
		//start cycling through the images
		$(this.imageContainer).cycle({fx:'fade', speed:speedParam, timeout:timeOutParam, pager:this.pagerContainer, fit: 1, pause: 0, before: 
		function () {	
			$('#overlay-text').hide().html('<h3>' + this.title + '</h3><p>' + this.rel + '  &nbsp;&raquo;&nbsp;<a href="' + this.href + '" style="color: #CCC;">Find out more</a></p>').fadeIn(500);
		}
		, after: 
			function () {
			}
		});
		this.AttachEvents();
	},
	
	
	Initialise : function( imageCon, pagerCon )	{		
		this.imageContainer = imageCon;
		this.pagerContainer = pagerCon;	
		$('#home-feature-overlay').html('<div id="overlay-text" style="width: 580px;height: 46px;"></div>');
	}
}

