$(function(){
  $('#nav ul')
    .wrap('<div class="drop"></div>')
    .before('<div class="drop-t">&#160;</div>')
    .after('<div class="drop-b">&#160;</div>')
    .wrap('<div class="drop-c"></div>');
  $('#nav > li:last').addClass('last');
  $('.home-vote tr:even td').addClass('grey');
  $('.video-list').cycle({
    pager: '#tab-3 .pager',
    pagerAnchorBuilder:
      function(idx, slide) { 
        return '<li><a href="#">' + (idx+1) + '</a></li>';
      },
    timeout:0,
    speed:400
  });
  $('.photo-list').cycle({
    pager: '#tab-2 .pager',
    pagerAnchorBuilder:
      function(idx, slide) { 
        return '<li><a href="#">' + (idx+1) + '</a></li>';
      },
    timeout:5000,
    speed:400
  });
  $('.photo-listspot').cycle({
    pager: '#tab-1 .pager',
    prev:'.back',
    next:'.continue',
    pagerAnchorBuilder:
      function(idx, slide) { 
        return '<li><a href="#">' + (idx+1) + '</a></li>';
      },
    timeout:8000,
    speed:400
  });
  $('.pageTitle[id*=IssueTitle] ~ br').remove();
  $('.pageTitle[id*=IssueTitle]').remove(); 
	$('select[id*=PrefixList]').prepend('<option value=""> </option>').val('');
  Seeding();
  WirePlaceholders();
  FormToAkamaiRedirect('deutch.house.gov');
});

function Seeding()
{
  $('.formFieldError[style*=hidden]').css('display','none');
  var formID = $.url().param('ID');
  if(formID == '742')
  {
    SeedHelper('email',$('input[id*=EmailControl]'));
    SeedHelper('firstname',$('#'+$('label:contains(First Name)').attr('for')));
    SeedHelper('lastname',$('#'+$('label:contains(Last Name)').attr('for')));
  }
  else if(formID=='1134')   
  {
    ReplaceWithTextArea('additional');
  }
}
function SeedHelper (parameterString, targetInput)
{
  var param = $.url().param(parameterString);
  if(param!=null)
  {
    param = unescape(param.replace(/\+/g, ' '));
    targetInput.val(param);
  }
}

function ReplaceWithTextArea(LabelKeyword)
{
  var Box;
  var TextArea;
  LabelKeyword = "additional";
  Box = $('#' + $('.formFieldContainer label:contains(' + LabelKeyword + ')').attr('for'));
  TextArea = '<textarea id="'+Box.attr('id')+'" name="'+Box.attr('name')+'" style="width:550px; height:100px; font-family:arial,sans-serif;">'+Box.val()+'</textarea>';
  Box.after(TextArea);
  Box.remove();
}

function inputSupportsPlaceholder() {
  var i = document.createElement('input');
  return 'placeholder' in i;
}
function WirePlaceholders(){
  if (!inputSupportsPlaceholder()) {
    $('input[placeholder]').each(function () {
      var textBox = $(this);
      if (textBox.val() == '')
      { textBox.val(textBox.attr('placeholder')); }
      textBox.focus(function () {
        if (textBox.val() == textBox.attr('placeholder'))
        { textBox.val(''); }
      });
      textBox.blur(function () {
        if (textBox.val() == '')
        { textBox.val(textBox.attr('placeholder')); }
      });
    });
  }
}
// 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);
    });
  }
}


