var userClicked = false;
var ssInt = null;
var curBanner = 1;
var lastBanner = 0;


var bannerHeadings = new Array('Seismic Processing &amp; Imaging', 'Interpretation &amp; Modeling', 'Reservoir Characterization','Reservoir Engineering','Well Planning &amp;  Drilling Engineering');
var bannerTexts = new Array('Paradigm seismic processing and imaging helps you optimize the<br />return on your digital investment.',
			                'Paradigm interpretation and modeling tools merge the interpreter and <br />modeler roles, improving accuracy and reducing uncertainty.',
			                'Paradigm reservoir characterization technology helps engineers optimize<br />hydrocarbon reserves with better reservoir management programs.',
							'Paradigm reservoir engineering technologies provide the means for reservoir <br />engineers to understand and manage more mature fields.',
			                'Paradigm well planning and drilling solutions enable users to reduce<br />uncertainty and facilitate quick and accurate well planning.');

var bannerLinks = new Array('/products/seismic-processing-imaging.aspx', 
			    '/products/interpretation-modeling.aspx', 
			    '/products/reservoir-characterization.aspx',
				'/products/reservoir-engineering.aspx',
			    '/products/well-planning-drilling-engineering.aspx');

function autoRotateTab()
{
       jQuery('#heroSlideshowControls-Next a').trigger("click");
}


function fadeBanner()
{
     jQuery('#heroBannerOverlayInner').fadeOut(function() {

           curBanner++;
           lastBanner++;
           //alert("CurBanner: " + curBanner + " / LastBanner: " + lastBanner);
           

           // change out the icon, heading, and text
           jQuery('#heroBannerOverlayText h3').html(bannerHeadings[(curBanner - 1)]);
           jQuery('#heroBannerOverlayText p').html(bannerTexts[(curBanner - 1)]);
           //jQuery('#heroBannerOverlayInner img').attr('src', '_img/heroWidget/icons/' + curBanner + '.png');
           jQuery('#bannerIcon' + (lastBanner)).css('display', 'none');
           //jQuery('#bannerIcon' + (curBanner - 1)).css('margin-left', '0px');
	   jQuery('#bannerIcon' + curBanner).css('display', 'inline'); // inline to prevent IE6's Double Float Margin Bug
           //jQuery('#heroBannerOverlayInner img').parent().attr('href', bannerLinks[curBanner - 1]);
           
           if (curBanner == 5)
           {
               curBanner = 0;
               lastBanner = 4;
           }
           if (lastBanner == 5)
           {
               lastBanner = 0;           
           }
           jQuery(this).fadeIn();
     });
}


jQuery(document).ready(function () 
{
     // setup fading for the banner overlay of the hero text
     bannerOverlayTimer = setInterval(fadeBanner, 8000);

     // get the total number of tabs (-2 is for prev/next buttons)
     var numTabs = jQuery('#heroSlideshowControls li').size() - 2;
     var root = $("#AppRoot").val();    
     var heroTabs = jQuery('#heroSlideshow');
     
     // setup the tabs interface with the previous and next buttons disabled
     heroTabs.tabs(2,{ disabled: [1,  numTabs + 2], selectedClass: 'heroSlideshowControls-ButtonOn', fxFade: true});

     // reset the link for the first overlay banner icon, jQuery UI is inexplicably changing this href at startup

					       
     // wrap the banner overlay icons in links. jQuery UI mishandles the link if its hardcoded
     for(var i = 0; i<=5; i++)
     {
     	     jQuery('#bannerIcon' + (i + 1)).wrap('<a href="' + root + bannerLinks[i] + '"></a>');
     }
     ssInt = setInterval(autoRotateTab, 25000);

     // setup the previous a next button functionalities
     jQuery('#heroSlideshowControls-Next a').click(function (e, wasAuto) 
     {
	  // get the current tab index (1 based, subtract one for prev button)
          var curTab = heroTabs.tabsSelected() - 1;
          if (curTab < numTabs)
          {
              curTab++;
          }
          else
          {
              curTab = 1;
          }
	  heroTabs.tabsClick(curTab + 1);
	  clearInterval(ssInt);
	  ssInt = setInterval(autoRotateTab, 30000);
	  return false;
     });
   
     jQuery('#heroSlideshowControls-Prev a').click(function () 
     {
	  // get the current tab index (1 based, subtract one for prev button)
          var curTab = heroTabs.tabsSelected() - 1;
          if (curTab > 1)
          {
              curTab--;
          }
          else
          {
              curTab = numTabs; //+1 to account for the prev button
          }
          heroTabs.tabsClick(curTab + 1);
		  clearInterval(ssInt);
	  	  ssInt = setInterval(autoRotateTab, 30000);
	  return false;
     });

});
