$(document).ready(function(){
	$(".gallery .items ul").cycle({ 
	    fx:     'fade', 
	    speed:  'slow', 
	    timeout: 5000,
	    pager:  '.gal-nav ul',
	    prev: '.gal-nav .prev',
	    next: '.gal-nav .next'
	});
	$(".gal-nav ul li").remove();	
	$(".gal-nav ul a").wrap('<li></li>');
	$(".gal-nav ul a:first").addClass('activeSlide');
	HackIssues();
	$('.IssueBar a').corner();
	$('a.AuthFormLink').corner();
	SpeakerAsst();
	FlagHacks();
	$('a[href*=.pdf]').attr('target','_blank');
	AddExitMsg();
    if(readCookie('popupSignup') != 'hide')
    {
	    $('#modalPopup').click();
	    createCookie('popupSignup','hide',365);
	}
});

function HackIssues()
{
    $('.pageTitle[id*=IssueTitle] ~ br').remove();
    $('.pageTitle[id*=IssueTitle]').remove(); 
    $('table[id*=SocialTagsTable]').remove();
}

function SpeakerAsst()
{
    var directory = jQuery.url.segment(0);
    if(directory != null)
    {
        directory = directory.toLowerCase();
        if(directory == 'assistanttothespeaker')
        {
            SpeakerChanges();
        }
    }
    var doctype = jQuery.url.param('DocumentTypeID');
    if(doctype == '1699' || doctype == '1700' || doctype == '1762')
    {
        SpeakerChanges();
    }
    var isstype = jQuery.url.param('CatagoryID');
    if(isstype == '5919')
    {
        SpeakerChanges();
    }
}

function SpeakerChanges()
{
    $('.banners').html('<a href="/AssistantToTheSpeaker/" class="asst-ban"><img alt="Office of the Assistant to the Speaker - Honorable Chris Van Hollen (D-MD)" src="/images/cvh-asstban.png"/></a>');
    $('.nav ul').remove();
    $('a.speaker'
        ).html('Maryland&rsquo;s 8th District'
        ).attr('href','/'
        ).css('background-image','url(/images/speaker4.gif)'
        ).css('height','40px'
        ).css('margin','0');
    $('.content h1:first').before($('.nav').html());
    $('.PageLink').before($('.nav').html());
    //$('.morenews').corner('tl br');
    $('.nav').remove();
    $('#footer .offices, #footer .footer-logo').remove();
//    $('#footer ul.links').css('float','left').css('margin-left','-20px');
    $('#footer ul.links').css('float','right');
    $('#footer ul.social').css('clear','both').css('margin-bottom','0');
    $('#center'
        ).css('margin-top','-42px'
        ).css('z-index','10');
    $('.PageLink').css('background-image','url(/images/int-content-head2.gif)');
    $('ul.links li:eq(1)').remove();
    $('.actions li:eq(1)').remove();
    $('.content').css('width','auto');
    $('.content ul.news').css('padding-right','10px');
    $('.content h1:gt(0)').css('background-image','url(/images/int-content-head.gif)');
}

function FlagHacks()
{
    var flagText = 'You may e-mail me by filling out your information and comments below. Otherwise, please mail your request to my Rockville office at 51 Monroe St, Suite 507, Rockville, MD 20850 or fax it to my D.C. office at 202-225-0375. If you have any questions, please call my D.C. office at 202-225-5341.<br/><br/>There is a processing and shipping fee associated with the flag. Once you calculate the cost of your flag below, please mail a check payable to &rsquo;Chris Van Hollen Office Supply Account&lsquo; to my Rockville office at 51 Monroe St, Suite 507, Rockville, MD 20850.';
    
    var form = jQuery.url.segment(1);
    if(form != null)
    {
        form = form.toLowerCase();
        if(form == "flagrequest")
        {
            $('#aspnetForm > font.middlecopy:first > div:first').html(flagText);
            $('#Table1').remove();
        }
    }
}

// JavaScript External Link Exit Message
function exitMsg(){
     var answer = confirm("You are now leaving this House of Representatives website. Thank you for visiting. Neither this office nor the U.S. House of Representatives is responsible for the content of the non-House site you are about to access.")

if (!answer)
return false;

return true;
//end of Exit Message
}


// Check whether links are external:
// (Only works with elements that have href):
$.extend($.expr[':'],{
    external: function(a,i,m) {
        if(!a.href) {return false;}
        if(a.hostname.search(/house\.gov/gi)!=-1) {return false;}
        return a.hostname && a.hostname !== window.location.hostname;
    }
});

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


/* --- Add Exit Message ---*/
function AddExitMsg()
{
    $('a:external').attr('target','_blank');
    $('a:external').click(function(){
        return(exitMsg());
    });
}