﻿
 $(document).ready( function() {
 var lead_to_fade = new Array("panel1","panel2","panel3","panel4","panel5");


 var i = 0;
 var wait = 5000;
 var wait_small = 2000;
 var timer;
 var paused = false;

 function startLeadNews() {
 $('#panel1').fadeIn('fast');
 timer = window.setTimeout(function() { continueLeadNews() },wait_small);

 }

 function continueLeadNews()
 {
 $('#cap_panel1').fadeIn("slow");
 timer = window.setTimeout(function() { swapLeadNews(true) }, wait);

 }

 function SetPausedImage(o) {
 if (paused) {
 $(o).children('img').attr('src', '/_img/control-pause-over.gif');
 } else {
 $(o).children('img').attr('src', '/_img/control-pause.gif');
 }
 }

 function swapLeadNews(forward) {
 $('#cap_'+lead_to_fade[i]).fadeOut("slow");
 $('#'+lead_to_fade[i]).fadeOut('slow');
 if (forward) {
 i++;
 if (i > lead_to_fade.length-1) { i = 0; }
 } else {
 i--;
 if (i < 0) { i = lead_to_fade.length-1; }
 }
 $('#'+lead_to_fade[i]).fadeIn('slow');
 timer = window.setTimeout(function() {swapLeadNewsFadeOut()},wait_small);




 }

 function swapLeadNewsFadeOut(){
 $('#cap_'+lead_to_fade[i]).fadeIn("slow");
 if (!paused) {
 timer = window.setTimeout(function() { swapLeadNews(true) }, wait);
 }
 }


 $('.LeadPrevious').mouseover( function() {
 $(this).children('img').attr('src', '/_img/feature/arrow-previous.gif');
 });
 $('.LeadPrevious').mouseout( function() {
 $(this).children('img').attr('src', '/_img/feature/arrow-previous.gif');
 });
 $('.LeadPrevious').click( function() {
 window.clearTimeout(timer);
 swapLeadNews(false);
 return false;
 });

 $('.LeadNext').mouseover( function() {
 $(this).children('img').attr('src', '/_img/feature/arrow-next.gif');
 });
 $('.LeadNext').mouseout( function() {
 $(this).children('img').attr('src', '/_img/feature/arrow-next.gif');
 });
 $('.LeadNext').click( function() {
 window.clearTimeout(timer);
 swapLeadNews(true);
 return false;
 });

 $('.LeadPause').click( function() {
 if (paused) {
 paused = false;
 startLeadNews();
 } else {
 paused = true;
 window.clearTimeout(timer);
 }
 SetPausedImage($('.LeadPause'));
 return false;
 });

 startLeadNews();
 });


