var $j = jQuery.noConflict();

function nextLeadStory( $currentStory ) {
	if ( 'news-item lead' == $j( '#news-item-' + ($currentStory+1 ) ).attr('class') ) {
		$j( '#news-item-' + ($currentStory+1 ) ).show( 400 );
	} else {
		$j( '#news-item-1' ).show( 400 );
	}
	$j( '#news-item-' + $currentStory ).hide( 400 );
}

function doState( state, anchor ) {
	var states = ['ID', 'MT', 'OR', 'WA', 'US', 'GL'];
	for ( var s in states ) {
		if ( state == states[s] ) {
			$j( '#active_' + states[s] ).show( 0 );
			$j( '#counties_' + states[s] ).show( 400 );
		} else {
			$j( '#active_' + states[s] ).hide( 0 );
			$j( '#counties_' + states[s] ).hide( 200 );
		}
	}
	/* anchor.blur(); */
}

$j( document ).ready( function() {
	$j( '.fade' ).hover(
		function () {
			$j( 'img', this ).fadeTo( 256, 0 );
		},
		function () {
			$j( 'img', this ).fadeTo( 256, 1 );
		}
	);
	$j( '.fade2' ).hover(
		function () {
			$j( 'img', this ).fadeTo( 256, 1 );
		},
		function () {
			$j( 'img', this ).fadeTo( 256, 0 );
		}
	);
	initializeMap();
});

function initializeMap() {
	var latlng = new google.maps.LatLng(47.0, -117);
	var myOptions = {
	zoom: 5,
	center: latlng,
	mapTypeId: google.maps.MapTypeId.TERRAIN
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var ctaLayer = new google.maps.KmlLayer('http://www.budkrogh.com/Ports3.kml',{preserveViewport:true});
	ctaLayer.setMap(map); 
	var ctaLayer = new google.maps.KmlLayer('http://www.budkrogh.com/RailRoute3.kml',{preserveViewport:true});
	ctaLayer.setMap(map); 
	var ctaLayer = new google.maps.KmlLayer('http://www.budkrogh.com/PowderRiverBasin2.kml',{preserveViewport:true});
	ctaLayer.setMap(map); 
}

String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/g, "" );
}

function check_petition() {
	var valid = true;
	document.petition.first_name.value = document.petition.first_name.value.trim();
	document.petition.last_name.value = document.petition.last_name.value.trim();
	document.petition.email.value = document.petition.email.value.trim();
	document.petition.address.value = document.petition.address.value.trim();
	document.petition.city.value = document.petition.city.value.trim();
	document.petition.state.value = document.petition.state.value.trim();
	document.petition.zip.value = document.petition.zip.value.trim();
	if ( document.petition.first_name.value == '' ) {
		alert( 'Please enter your first name' );
		document.petition.first_name.focus();
		valid = false;
	} else if ( document.petition.last_name.value == '' ) {
		alert( 'Please enter your last name' );
		document.petition.last_name.focus();
		valid = false;
	} else if ( document.petition.email.value == '' ) {
		alert( 'Please enter your e-mail address' );
		document.petition.email.focus();
		valid = false;
	} else if ( document.petition.address.value == '' ) {
		alert( 'Please enter your street address' );
		document.petition.address.focus();
		valid = false;
	} else if ( document.petition.city.value == '' ) {
		alert( 'Please enter your city' );
		document.petition.city.focus();
		valid = false;
	} else if ( document.petition.state.value == '' ) {
		alert( 'Please select your state' );
		document.petition.state.focus();
		valid = false;
	} else if ( document.petition.zip.value == '' ) {
		alert( 'Please enter your zip' );
		document.petition.zip.focus();
		valid = false;
	}
	if ( valid && ( '' != document.petition.title_req.value ) && ( '' == document.petition.title.value ) ) {
		alert( 'Please enter your ' +  document.petition.title_req.value );
		document.petition.title.focus();
		valid = false;
	}
	if ( valid && ( '' != document.petition.org_name_req.value ) && ( '' == document.petition.org_name.value ) ) {
		alert( 'Please enter your ' +  document.petition.org_name_req.value );
		document.petition.org_name.focus();
		valid = false;
	}
	if ( valid ) {
		var regex = /.+@.+\..+/;
		var result = regex.exec( document.petition.email.value );
		valid = ( null != result );
		if ( !valid ) {
			alert( 'Please enter a valid e-mail address' );
			document.petition.email.focus();
		}
	}
	return valid;
}


