function initPage(){
	ieHover('#menu li');
	initGall1();
	initGall2();
	highlightUrl();
	//setUpNewsHomeIssueLinks();
	$('a[href*=.pdf], .quick li a:external').attr('target','_blank');
	$('[href*=//energycommerce.house.gov]').each(function(){
	  var newurl = $(this).attr('href').replace('energycommerce.house.gov','democrats.energycommerce.house.gov');
	  $(this).attr('href',newurl);
	});
	$('.contact address').cluetip({splitTitle: '|'});
	FormToAkamaiRedirect('waxman.house.gov');
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
	
/*--- ie hover ---*/
function ieHover(_list) {
	if ($.browser.msie && $.browser.version < 7) {
		$(_list).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	}
}
/*--- fadeGall ---*/
function initGall1(){
	var _duration = 5000;
	var _timer;
	var _a = 0;
	var _ind;
	var _box = $('#header .banner .item').hide();
	_box.eq(_a).show();
	if(_box.length > 1){
		function changeEl(){
			if(_a < _box.length - 1) _ind = _a + 1;
			else _ind = 0;
			_box.eq(_a).css('z-index', 1).fadeOut(600);
			_box.eq(_ind).css('z-index', 2).fadeIn(600, function(){
				_a = _ind;
				_timer = setTimeout(function(){changeEl();}, _duration);
			});
		}
		_timer = setTimeout(function(){changeEl();}, _duration);
	}
}
function initGall2(){
	var _a = 0;
	$('.gallery').each(function(){
		var _hold = $(this);
		var _box = _hold.find('.frame > ul > li').hide();
		_box.eq(_a).show();
		_hold.find('a.prev').click(function(){
			if(_a > 0) changeEl(_a - 1);
			else changeEl(_box.length - 1);
			//resetTimer();
			return false;
		});
		_hold.find('a.next').click(function(){
			if(_a < _box.length - 1) changeEl(_a + 1);
			else changeEl(0);
			//resetTimer();
			return false;
		});
		function changeEl(_ind){
			_box.eq(_a).css('z-index', 1).fadeOut(600);
			_box.eq(_ind).css('z-index', 2).fadeIn(600);
			_a = _ind;
		}
		

		
		$(this).everyTime(6000, "AutoRot", function(){
	        if(_a < _box.length - 1) changeEl(_a + 1);
		    else changeEl(0);
	    },0,true);

	});
}
		function resetTimer(){
	        $(this).parent().stopTime();
	    }

function highlightUrl(){
  $('.quick a').each(function(){
    var relurl = jQuery.url.attr('relative').toLowerCase();
    var fullurl = jQuery.url.attr('source').toLowerCase();
    var href = $(this).attr('href').toLowerCase();
    if((href == relurl) || (href == fullurl))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4484') && (relurl == '/issuelist/internal/foodqualityprotectionact.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4477') && (relurl=='/issuelist/internal/safewater1996.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4499') && (relurl=='/issuelist/internal/merc.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4482') && (relurl=='/issuelist/internal/orphandrugs.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4486') && (relurl=='/issuelist/internal/nursinghomes.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4489') && (relurl=='/issuelist/internal/tobacco.htm'))
    {
      $(this).css('font-weight','bold');
    }
    if((href == '/issues/issue/?issueid=4474') && (relurl=='/issuelist/internal/caa1990.htm'))
    {
      $(this).css('font-weight','bold');
    }
  });
}
function setUpNewsHomeIssueLinks(){
  $('select#.RedirectSelect').children().each(function(){
    $(this).click(function(){
      window.location=$(this).val();
    });
  });
}

// Check whether links are external:
// (Only works with elements that have href):
$.extend($.expr[':'],{
  external: function(a,i,m) {
    if(!a.href) {return false;}
    return a.hostname && a.hostname !== window.location.hostname;
  }
});

function f(o)
{
	o.value=o.value.replace(/([^0-9])/g,"");
}
var state = "CA";
var district = "30";

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=args[i+1]; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.match(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/gi);
      if (p==null) errors+='- '+nm+' must be a valid e-mail address.\n';
	} else if (test!='R') { num = parseFloat(val);
	if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
	if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
	min=test.substring(8,p); max=test.substring(p+1);
	if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	} if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}
// 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);
    });
  }
}

