var ImageSwitch = 0;

function rollover(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_on.src;');
}

function rolloff(n) {
	if (ImageSwitch == 1 && n != '') eval('document.' + n + '.src = ' + n + '_off.src;');
}

function preload_images() {
	about_us_on = new Image;
	about_us_off = new Image;
	about_us_on.src = 'images/nav/about_us_on.png';
	about_us_off.src = 'images/nav/about_us.gif';
	contact_us_on = new Image;
	contact_us_off = new Image;
	contact_us_on.src = 'images/nav/contact_us_on.png';
	contact_us_off.src = 'images/nav/contact_us.gif';
	data_on = new Image;
	data_off = new Image;
	data_on.src = 'images/nav/data_on.png';
	data_off.src = 'images/nav/data.gif';
	partners_on = new Image;
	partners_off = new Image;
	partners_on.src = 'images/nav/partners_on.png';
	partners_off.src = 'images/nav/partners.gif';
	press_on = new Image;
	press_off = new Image;
	press_on.src = 'images/nav/press_on.png';
	press_off.src = 'images/nav/press.gif';
	ImageSwitch = 1;
}

function pop_file(f, w, h) {
	var temp_url = f;
	var new_win = window.open(temp_url, 'pop' + h + w, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + w + ',height=' + h + ',alwaysRaised=yes');
	new_win.focus();
}

function check_enews_form() {
	var el = '';
	var form = document.enews_form;
	if (form.nametxt.value == '') el += 'Enter a value for "Name" \n';
	if (form.Zipcode.value == '') el += 'Enter a value for "Zip Code" \n';
	if (form.Email.value == '') el += 'Enter a value for "Email Address" \n';
	if (el == '') {
		return true;
	} else {
		alert('Please address the following and then click "Subscribe" again: \n \n' + el);
		return false;
	}
}

// code for scrolling news settings
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var rotation_time = 6000; //time in milliseconds

$(document).ready(function(){
	headline_count = $("div.headline").size();
	current_headline = 0;
	var h1=$("#headline"+current_headline).height();
	var h2=$("#scrollup").height();
	h=Math.round((h2-h1)/2.3);
	$("#headline"+current_headline).show().animate({top: h},2000);
	if (headline_count>1) headline_interval = setInterval(headline_rotate,rotation_time);
	old_headline = current_headline;
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count
	var h2=$("#scrollup").height();
	var h1=$("#headline"+current_headline).height();
	var h3=$("#headline"+old_headline).height();
	$("#headline"+old_headline).animate({top: -h3},2000, function() {
    	$(this).css('top', h2+'px');
    });
	h=Math.round((h2-h1)/2.3);
	$("#headline"+current_headline).show().animate({top: h},2000);
	old_headline = current_headline;
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		EventCache.add(elm, evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

addEvent(window, 'load', preload_images, false);
addEvent(window, 'unload', EventCache.flush, false);