var $$ = $.fn;

var options = {
     			StartSlide: 1,  
				TotalSlides: 6,
				SlideShowInterval: 7000,
				FadeSpeed: 600,
				IsPausedOnHover: 1,
				HasBannerLink: 1,
				href1: {link: 'services.outsourcing.asp', target: '_top'}, 
				href2: {link: 'services.embedded.asp', target: '_top'},
				href3: {link: 'services.mobile.asp', target: '_top'},
				href4: {link: 'products.captioning.asp', target: '_top'},
				href5: {link: 'services.hardware.asp', target: '_top'},
				href6: {link: 'products.mobile.asp', target: '_top'}
   			};

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
	  
    Ready : function()
    {
	  
	  $('#tmpSlideshow')
        .hover(
			   function() {
				   if (options.IsPausedOnHover)
				   {
				   		$$.Slideshow.SetInterrupted(true);
				   }
			   }, 
			   function() {
				   if (options.IsPausedOnHover)
				   {
				   		$$.Slideshow.SetInterrupted(false);
				   }
			   }
	    )
	  $('.tmpSlideshowControl')
        .click(
          function() {
            $('.tmpSlide').hide();

            $('#tmpSlide-' + $(this).SplitID()).show();
            
            $$.Slideshow.Counter = parseInt($(this).SplitID()) + 1;
			if (options.HasBannerLink)
		    {
			  $$.Slideshow.SetBannerLink($$.Slideshow.Counter-1);
		    }
          }
        );

      this.Counter = options.StartSlide;
	  $$.Slideshow.SetInterrupted(false);

      this.Transition();
    },
	
	
	SetInterrupted : function(state)
	{
		if (state == true)
		{
			$$.Slideshow.Interrupted = true;
		}
		else
		{
			$$.Slideshow.Interrupted = false;
		}
	},

    Resume : function()
    {
      this.Interrupted = false; 
    },
	
	SetBannerLink : function(count)
    {
	$('#BannerLink').attr("href", eval('options.href'+count+'.link'));
			  $('#BannerLink').attr("target", eval('options.href'+count+'.target'));
	},
	
    Transition : function()
    {
	  if (this.Interrupted) {
        setTimeout('$$.Slideshow.Transition();', options.SlideShowInterval);
		return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = options.TotalSlides;
      }

      $('#tmpSlide-' + this.Last).fadeOut(options.FadeSpeed);  

	  if ($$.Slideshow.Counter > options.TotalSlides) 
	  {
            $$.Slideshow.Counter = 1;
	  }
	  
	  $('#tmpSlide-' + $$.Slideshow.Counter).fadeIn(options.FadeSpeed);
		
	  if (options.HasBannerLink)
	  {
		$$.Slideshow.SetBannerLink($$.Slideshow.Counter);
	  }
      
	  $$.Slideshow.Counter++;

      setTimeout('$$.Slideshow.Transition();', options.SlideShowInterval);
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow.Ready();
  }
);