// swfobject.embedSWF('http://admin.brightcove.com/viewer/federated.swf?flashId=flashObj0&servicesURL=http%3A%2F%2Fservices.brightcove.com%2Fservices&viewerSecureGatewayURL=https%3A%2F%2Fconsole.brightcove.com%2Fservices%2Famfgateway&cdnURL=http%3A%2F%2Fadmin.brightcove.com&autoStart=false&preloadBackColor=%4a4a4a&width=480&height=385&playerId=1840674020&externalAds=false&sendReports=false&buildNumber=84&ranNum=997134','feature_video','480','385','7.0.0','http://www.barackobama.com/js/expressInstall.swf',{},{bgcolor:'4a4a4a',wmode:'transparent'});

document.write('<style type="text/css">#lead_in, #pages { overflow: hidden; } .page { display: none; position: absolute; }</style>');

window.addEvent('domready',function(){

	$$('#signup input[type=text]').each(function(el,i){
		var hideLbl = function() { $$('label[for='+this.id+']').setStyles({left:'-9999px'}); };
		var showLbl = function() { if (this.value == '') $$('label[for='+this.id+']').setStyles({left:'auto'}); };
		(el.value == '') ? showLbl.run('',el) : hideLbl.run('',el);
		el.addEvents({'focus':hideLbl,'blur':showLbl});
	});

	// set scrolling functionality of lead-in box
	var lead_in = $('lead_in');
	var lead_in_txt = lead_in.get('html');
	var scrollbox = new Element('div',{'html':lead_in_txt,'styles':{'position':'relative'}});
	lead_in.empty().grab(scrollbox);
	var scrollup = new Element('a',{
		'href':'#',
		'class':'scrollup',
		'events':{
			'click':function(){return false;},
			'mousedown':function(){scroll.start({top:'0'});},
			'mouseup':function(){scroll.cancel();},
			'mouseover':function(){ this.addClass('on'); },
			'mouseout':function(){ checkBG(); }
		}
	}).inject(lead_in,'before');
	var scrolldown = new Element('a',{
		'href':'#',
		'class':'scrolldown',
		'events':{
			'click':function(){return false;},
			'mousedown':function(){scroll.start({top:(lead_in.getSize().y-scrollbox.getScrollSize().y-20)+'px'});},
			'mouseup':function(){scroll.cancel();},
			'mouseover':function(){ this.addClass('on'); },
			'mouseout':function(){ checkBG(); }
		}
	}).inject(lead_in,'after');
	var checkBG = function() {
		(scrollbox.getStyle('top').toInt() == 0) ? scrollup.removeClass('on') : scrollup.addClass('on');
		(scrollbox.getStyle('top').toInt() == (lead_in.getSize().y-scrollbox.getScrollSize().y-20)) ? scrolldown.removeClass('on') : scrolldown.addClass('on');
	};
	var scroll = new Fx.Morph(scrollbox,{duration:'1000',onCancel:checkBG,onComplete:checkBG});
	checkBG();
	
	$$('#nav a, .page_link a').each(function(el,i){
		if (el.href.indexOf('#') > -1) {
			var href = el.href.substr(el.href.indexOf('#')+1,el.href.length);
			el.addEvent('click',function(){
				$$('.page').fade('out').setStyles({display:'none',zIndex:'1'});
				$(href).setStyle('display','block').fade('in').setStyle('z-index','2');
				return false;
			});
		}
	});
	$$('.page').fade('hide').setStyles({display:'none',zIndex:'1'});
	if (document.location.href.indexOf('#')>-1 && (document.location.href.indexOf('#')+1) != document.location.href.length) {
		var id = document.location.href.substr(document.location.href.indexOf('#'),document.location.href.length);
		$$(id).setStyle('display','block').fade('in').setStyle('z-index','2');
	} else {
		$$('.page:first-child').setStyle('display','block').fade('in').setStyle('z-index','2');
	}
	
});