function getCookie(Name){
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value, days){
var expireDate = new Date()
//set "expstring" to either an explicit date (past or future)
if (typeof days!="undefined"){ //if set persistent cookie
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; "+interstitialBox.cookiesetting[1]
}
else //else if this is a session only cookie setting
document.cookie = name+"="+value+"; "+interstitialBox.cookiesetting[1]
}

$(document).ready(function() {
	
	// hide video
	$('.deactivate').click(function() {
    	$('#flashcontent').css('display','none');
		setCookie('video','no',365);
	}); 
	if (getCookie('video') == 'no') {
         $('#flashcontent').css('display','none');
	}

	/* Prove It slide-down Explanations */
	
	$('a.showExplain, a.closeExplain').click(function() {
		$('div.'+$(this).attr('rel')).slideToggle('fast');						
	});
	// x is the class of the div to show
	$('.startHidden').hide(0);
	
	
	$(".tweet-text, #dtd-tweets li").each(function(z) {
		$(this).html(prototype.string.autolink($(this).text()));
	});
	
	/* Ads */
	//if (!($.browser.msie && $.browser.version.substr(0,1)<7)) {
	//	$('.ad1, .ad2, .ad3, .ad4').fadeTo(0,0.5);
	// }
	$('.submenu').hide();

	// $('a.expand').click(function() {
	// 	$(this).parents().children('ul.submenu').slideToggle('fast');
	// });
	increase = 0.0;
	currentRounded = 0.0;
	$.getJSON("./utilities/getDebt.cfm", function(json){
		increase = json.INC;
		currentRounded = json.AMT;
		$('.counter').jOdometer({
			delayTime: 1000,
			increment: increase, 
			counterStart: currentRounded, 
			numbersImage: 'images/numbers.png', 
			speed: 400,
			spaceNumbers: 0, 
			offsetRight:0
		});
		$('.counter2').jOdometer({
			delayTime: 1000,
			increment: increase, 
			counterStart: currentRounded, 
			numbersImage: 'images/jodometer-sidebar.png', 
			speed: 400,
			spaceNumbers: 0, 
			offsetRight:0,
			heightNumber: 31, // Default: 31
			widthNumber: 8 // Default: 14

		});
		$('.counter3').jOdometer({
			delayTime: 1000,
			increment: increase, 
			counterStart: currentRounded, 
			numbersImage: 'images/debt-clock/jodometer-dirty.png', 
			speed: 400,
			spaceNumbers: 0, 
			offsetRight:0,
			heightNumber: 80, // Default: 31
			widthNumber: 36 // Default: 14

		});
	});
	
	if($('#alertArea').length > 0) {	
		$('#alertArea').hide(0);
	}
	if ( $('div.understanding-debt').length ) {
		$('<div class="sidebar-top-horizontal-bar"></div>').insertBefore('li.understanding-debt a.expand');
		$('.understanding-debt .submenu').show();
	}
	if ( $('div.understanding-danger').length ) {
		$('<div class="sidebar-top-horizontal-bar"></div>').insertBefore('li.understanding-danger a.expand');
		$('.understanding-danger .submenu').show();
	}
	if ( $('div.action').length ) {
		$('<div class="sidebar-top-horizontal-bar"></div>').insertBefore('li.action a.expand');
		$('.action .submenu').show();
	}
	if ( $('div.cartoons-section').length ) {
		$('<div class="sidebar-top-horizontal-bar"></div>').insertBefore('li.cartoons a.expand');
		// $('.action .submenu').show();
	}
	if ( $('div.other-voices-section').length ) {
		$('<div class="sidebar-top-horizontal-bar"></div>').insertBefore('li.other-voices a.expand');
		// $('.action .submenu').show();
	}
	if($('.currentDebt').length) {
		$.get("./utilities/getDebt.cfm?format=comma", function(tx){
			$('.currentDebt').html(tx);
		});
	}
	
	/* Lightbox effect and hover-fade for ads */
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	$('.ad-left, .ad-3-col, .ad-4-col').hover(function(){
		$(this).stop().fadeTo("fast", 0.5); 
	}, function(){
		$(this).stop().fadeTo("fast", 1); 		
	});	

	/* Validation for forms */
 	$("#signup").validate();
 	$("#contact-us").validate();
	$("#marchw").validate();
	$("#sgnbmp").validate();
	$("#signpt").validate();
	$("#emaila").validate();
	
	/* delete later */
	$('#poll-results').hide(0);
	
	$("#vote").click(function() {
		/*
		$.ajax({
			type: "GET",
			url: "utilities/getPoll.cfm",
			dataType: "html",
			success: function(html){
				$('#poll-holder').html(data,function() {
					$('#poll-results').visualize({type: 'pie', pieMargin: 0, colors: ['#C83C21','#cccccc','#555555']});
					$('.visualize-info').css('left','0');
				});
			}
		});
		*/
		$.post('utilities/getPoll.cfm',
			   { eliminatedebt: $("input[name=eliminatedebt]:checked").val() },
			   function(data) {
					$('#poll-questions').hide(0);
					$('#poll-holder').html(data);
					$('#poll-results').visualize({type: 'pie', pieMargin: 0, colors: ['#C83C21','#cccccc','#555555']});
					$('.visualize-info').css('left','0');
					$('#poll-results').hide(0);
				},
				"html"
		);
		return false;
	});
});

	
/* Random quotes feature */
function showRandQuote() {
	var arr = new Array(1);
arr.push("<blockquote>Blessed are <strong>the young</strong>, for they shall <strong>inherit the national debt</strong>.&rdquo; <br/><cite>&mdash; Herbert Hoover</cite></blockquote>");
arr.push("<blockquote><strong>I am for</strong> a government rigorously frugal and simple, applying all  the possible savings of the public revenue to <strong>the discharge of the national debt.</strong>&rdquo; <br/><cite>&mdash; Thomas Jefferson</cite></blockquote>");
arr.push("<blockquote>Solvency is maintained by  means of a national debt, on the principle, <strong>&lsquo;If you will not lend me the money, how can I pay you?&rsquo;</strong>&rdquo; <br/><cite>&mdash; Ralph Waldo Emerson</cite></blockquote>");
arr.push("<blockquote>We must not let <strong>our rulers</strong> load us with <strong>perpetual debt</strong>.&rdquo; <br/><cite>&mdash; Thomas Jefferson </cite></blockquote>");
arr.push("<blockquote>As a very important source of  strength and security, <strong>cherish public  credit</strong>.&rdquo; <br/><cite>&mdash; George Washington, <br>Farewell  Address</cite></blockquote>");
arr.push("<blockquote>Do not  count your chickens before they are hatched.&rdquo; <br/><cite>&mdash; Aesop</cite></blockquote>");
arr.push("<blockquote>The budget  should be balanced, the Treasury should be refilled, <strong>public debt should be reduced</strong>.&rdquo; <br/><cite>&mdash; Cicero, <br>Roman statesman</cite></blockquote>");
arr.push("<blockquote>Nothing is so well  calculated to <strong>produce a death-like  torpor</strong> in the country as an extended system of taxation and <strong>a great national debt</strong>.&rdquo; <br/><cite>&mdash; William Cobbett, <br>English  journalist, <br>18th century</cite></blockquote>");
arr.push("<blockquote>Deep down  in our hearts, we know that <strong>we have  bankrupted America</strong> and that <strong>we have  given our children a legacy of bankruptcy</strong>.&rdquo; <br/><cite>&mdash; John C.  Danforth, <br>Former U.S. Senator and Ambassador to the United Nations</cite></blockquote>");
arr.push("<blockquote>Don&rsquo;t let  your mouth write no check that <strong>your tail  can&rsquo;t cash</strong>.&rdquo; <br/><cite>&mdash; Bo Diddley</cite></blockquote>");
arr.push("<blockquote>A <strong>billion</strong> here, a <strong>billion</strong> there, sooner or later <strong>it  adds up to</strong> <strong>real money</strong>.&rdquo; <br/><cite>&mdash; Everett  Dirksen, <br>former Senator (R-IL)</cite></blockquote>");
arr.push("<blockquote>I, however,  place &hellip; <strong>public debt</strong> as the <strong>greatest of the dangers to be feared</strong>.&rdquo; <br/><cite>&mdash; Thomas  Jefferson</cite></blockquote>");
arr.push("<blockquote>That&rsquo;s what  a Congressman or a Senator is for &mdash; to see that <strong>too much money</strong> don&rsquo;t accumulate in the national Treasury.&rdquo; <br/><cite>&mdash; Will Rogers</cite></blockquote>");
arr.push("<blockquote>Can  we, who man the ship of state, deny it is somewhat <strong>out of control</strong>?&rdquo; <br/><cite> &mdash; President Ronald Reagan<br/>");
arr.push("<blockquote>I have long  argued that <strong>paying down the national  debt</strong> is beneficial for the economy.&rdquo; <br/><cite> &mdash; Alan  Greenspan</cite></blockquote>");
arr.push("<blockquote>The fact  is, we&rsquo;ll never build a lasting economic recovery by going <strong>deeper into debt at a faster rate</strong> <strong>than we ever have before</strong>.&rdquo; <br/><cite>&mdash; President Ronald  Reagan</cite></blockquote>");
arr.push("<blockquote><strong>Debt</strong> is the <strong>slavery</strong> <strong>of the free</strong>.&rdquo; <br/><cite>&mdash; Publilius Syrus, <br>former slave, writer, <br>1st  century AD</cite></blockquote>");
arr.push("<blockquote>A small <strong>debt produces</strong> a debtor; a large one, <strong>an enemy</strong>.&rdquo; <br/><cite>&mdash; Publilius  Syrus, <br>former slave, writer, <br>1st century AD</cite></blockquote>");
arr.push("<blockquote><strong>Debt is like any other</strong> <strong>trap</strong>, easy enough to get into, but hard  enough to get out of.&rdquo; <br/><cite>&mdash; Henry  Wheeler Shaw, <br>humorist, <br>19th century</cite></blockquote>");
arr.push("<blockquote>Debt is the <strong>fatal disease of republics</strong>, the  first thing and the mightiest to undermine governments and corrupt the people.&rdquo; <br/><cite>&mdash; Wendell  Phillips, <br>American abolitionist</cite></blockquote>");
arr.push("<blockquote>Do not  accustom yourself to consider debt<strong> </strong>only  as an inconvenience; <strong>you will find it</strong> <strong>a calamity</strong>. <br/><cite>&mdash; Samuel  Johnson, <br>18th century English author</cite></blockquote>");
arr.push("<blockquote>Avoiding  likewise the accumulation of debt &hellip; not ungenerously<strong> throwing upon posterity the burden which we ourselves ought to bear</strong>.&rdquo; <br/><cite>&mdash; George  Washington</cite></blockquote>");
arr.push("<blockquote>Some debts  are fun when you are acquiring them, but none are fun when you set about  retiring them.&rdquo; <br/><cite>&mdash; Ogden Nash,  <br>poet</cite></blockquote>");
arr.push("<blockquote>Let every  man, every corporation, and especially let every village, town, and city, every  county and State, <strong>get out of debt and  keep out of debt</strong>. It is the debtor that is <strong>ruined by hard times</strong>.&rdquo; <br/><cite>&mdash; Rutherford B. Hayes</cite></blockquote>");
arr.push("<blockquote> This is about the <strong>future of our country</strong>, our kids and grandkids.&rdquo; <br/><cite>&mdash; David M. Walker,  <br>former Comptroller General of the United States</cite></blockquote>");
arr.push("<blockquote>Our  financial condition is <strong>worse than  advertized</strong>. We need to act. We need to act soon because <strong>time working against us</strong>.&rdquo; <br/><cite>&mdash; David M.  Walker, <br>former Comptroller General <br>of the United States</cite></blockquote>");
arr.push("<blockquote>I would  argue that the <strong>most serious threat to  the United States</strong> is not someone hiding in a cave in Afghanistan or  Pakistan, but <strong>our own fiscal  irresponsibility</strong>.&rdquo; <br/><cite>&mdash; David M.  Walker, <br>former Comptroller General <br>of the United States</cite></blockquote>");
arr.push("<blockquote>We suffer  from a fiscal cancer, it is growing within us, and if we do not treat it, it  could have <strong>catastrophic consequences for  our country</strong>.&rdquo; <br/><cite>&mdash; David M.  Walker, <br>former Comptroller General <br>of the United States</cite></blockquote>");
arr.push("<blockquote>With  respect to the <strong>fiscal crisis looming out  there in the future</strong>, we&rsquo;ll see whether a democracy can deal with <strong>an obvious problem that&rsquo;s going to be  present in not too many years</strong>. And the earlier we <strong>take action</strong> to deal with it, the better.&rdquo; <br/><cite>&mdash; Paul Volcker,  <br>former Federal Reserve Chairman</cite></blockquote>");
arr.push("<blockquote>For  decades, we have <strong>piled deficit upon  deficit</strong>, mortgaging our future and our children&rsquo;s future for <strong>the temporary convenience of the present</strong>.&rdquo; <br/><cite>&mdash; President Ronald  Reagan</cite></blockquote>");
arr.push("<blockquote>We&rsquo;ve got a <strong>very big problem staring us in the face</strong>.&rdquo; <br/><cite>&mdash; Alice  Rivlin, <br>Founding Director, <br>Congressional Budget Office</cite></blockquote>");
arr.push("<blockquote>Fiscally, we  are in <strong>uncharted territory</strong>.&rdquo; <br/><cite>&mdash; Warren  Buffett, <br>billionaire, <br>August 19, 2009</cite></blockquote>");
arr.push("<blockquote>How we  spend the public&rsquo;s money should reflect what is important to us in our  country.&rdquo;<br/><cite>&mdash; Nancy  Pelosi, <br>(CA-D) 2006</cite></blockquote>");
arr.push("<blockquote>But the <strong>long-term deficit and debt</strong> that we have  accumulated <strong>is unsustainable</strong>. We can&rsquo;t keep on just borrowing from China,  or borrowing from other countries&hellip; <strong>at  some point they&rsquo;re just going to get tired of buying our debt</strong>.&rdquo; <br/> <cite> &mdash; President  Obama, <br>May 14, 2009</cite></blockquote>");
arr.push("<blockquote>&hellip; [W]e  have to pay interest on that debt. And  that means that we&rsquo;re <strong>mortgaging our  children&rsquo;s future</strong> with more and more debt.&rdquo;<br/> <cite> &mdash;  President Obama, <br>May 14, 2009</cite></blockquote>");
arr.push("<blockquote>Rather go  to bed supperless than rise in debt.&rdquo; <br/><cite>&mdash; Benjamin  Franklin</cite></blockquote>");
arr.push("<blockquote>Debt is the <strong>worst poverty</strong>.&rdquo;<br/><cite>&mdash; Thomas Fuller, <br>16th century  English historian</cite></blockquote>");
arr.push("<blockquote>Who goes a-borrowing goeth  a-sorrowing.&rdquo;<br/><cite>&mdash; Thomas Tusser, <br>15th century  English poet and farmer</cite></blockquote>");
arr.push("<blockquote>Our debt is getting so out of control  and our deficits are getting so high, that <strong>if  we, as a nation, tried to enter the European Union, [&hellip;] we couldn&rsquo;t get in</strong>.&rdquo; <br/><cite>&mdash; Senator Judd Gregg <br>(NH-R)</cite></blockquote>");
arr.push("<blockquote>The national debt is <strong>out of control</strong>.&rdquo; <br/><cite>&mdash; Senator Judd Gregg  <br>(NH-R)</cite></blockquote>");
arr.push("<blockquote>We cannot  live in the present only. Human beings cannot survive unless they create provision for the future.&rdquo; <br/><cite>&mdash; Alan Greenspan, <br>former Chairman of the  Federal Reserve</cite></blockquote>");
arr.push("<blockquote>The nation is hurtling toward a budgetary doomsday&hellip;&rdquo; <br/><cite>&mdash; David Stockman<br/> Fmr. Director of the Office of Management and Budget</cite></blockquote>");
	var idx = Math.floor(Math.random() * arr.length-2);
	if (arr[idx+1] === undefined) {
		document.write("<blockquote>Fiscally, we  are in <strong>uncharted territory</strong>.&rdquo; <br/><cite>&mdash; Warren  Buffett, <br>billionaire, <br>August 19, 2009</cite></blockquote>");
	} else {
		document.write(arr[idx+1]);
	}
}

function triggerAlert(x) {
		$('#alertArea').text(x);
		$('#alertArea').fadeIn('fast');
}

function hideAlert() {
		$('#alertArea').fadeOut('fast');
}



var prototype = {};
prototype.string = {};

prototype.string.autolink = function (tweet, options){
	
  if(tweet.search(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/) > -1) {
    tweet = tweet.replace(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/, "<a href='$1'>$1</a>")
  }

  if(tweet.search(/@\w+/) > -1) {
    tweet = tweet.replace(/(@)(\w+)/g, "$1<a href='http://twitter.com/$2'>$2</a>");
  }

  return tweet;
};


