$(function(){
  initTabs();
  initGall();
  $('#header .banner').click(function(){window.location='/';});
  HomeTabs();
  HackIssues();
  FormToAkamaiRedirect('jeffmiller.house.gov');
});

function initTabs()
{
  $('.tab-list:first').show();
  $('.tabs .tabset a.tab').each(function(i){
    var tabSelected = $(this);
    var index = i;
    tabSelected.click(function(event){
      event.preventDefault();
      $('.tab-list, ul.flash').hide();
      $('.tab-list:eq('+index+'), ul.flash:eq('+index+')').show();
    });
  });
}

function initGall(){
	$('#header .banner > img:gt(0)').hide();
	var _a = 0;
	$('#header .banner').each(function(){
		var _hold = $(this);
		var _box = _hold.children('img').hide();
		_box.eq(_a).show();
		function changeEl(_ind){
			_box.eq(_a).css('z-index', 1).fadeOut(800);
			_box.eq(_ind).css('z-index', 2).fadeIn(800);
			_a = _ind;
		}
		
    function resetTimer(){
      $(this).parent().stopTime();
    }

    $(this).everyTime(6000, "AutoRot", function(){
        if(_a < _box.length - 1) changeEl(_a + 1);
	    else changeEl(0);
    },0,true);

	});
	
}
// Send relative links to unSSL canonical DNS
function FormToAkamaiRedirect(defaultDomain)
{
  if(location.hostname != defaultDomain
    || location.protocol != 'http:')
  {
    $('a[href^=\\/]').each(function(){
      var origUrl = $(this).attr('href');
      $(this).attr('href', 'http://' + defaultDomain + origUrl);
    });
  }
}

function HomeTabs()
{
  $('#visual ul.flash').each(function(){
    $(this).children('li:first').show();
  });
  $('.tabs #tab1.tab li a').each(function(){
    var clickedLink = $(this);
    clickedLink.click(function(event){
      event.preventDefault();    
      $('.vid-cont li').hide();        
      $(clickedLink.attr('href')).show()
    });        
  });
  $('.tabs #tab2.tab li a').each(function(i){
    var clickedLink = $(this);
    var index = i;
    clickedLink.click(function(event){
      event.preventDefault();    
      $('.pix-cont li').hide();        
      $(clickedLink.attr('href')).show()
    });        
  });
}

function HackIssues()
{
  $('.pageTitle[id*=IssueTitle] ~ br').remove();
  $('.pageTitle[id*=IssueTitle]').remove();
}

