$(document).ready(addRollovers);

function addRollovers() {
	$("#logo img").mouseover( function() {
		$(this).attr("src","/images/template/logo_hover.png");
	});
	$("#logo img").mouseout( function() {
		$(this).attr("src","/images/template/logo.png");
	});
	
	$(".graphic_right, .graphic_left").hover( function() {
		$(this).children('div').slideDown("fast");
	},
	function() {
		$(this).children('div').slideUp("fast");
	});
	
	$("#menu li").append("<div> </div>");
	
	$("#menu li").hover( function() {
		$(this).addClass("hover");
		$(this).children('div').slideDown("fast");
	},
	function() {
		$(this).children('div').slideUp("fast", function() {
			$(this).removeClass("hover");
		});
	});
	
	$("#menu li").click( function() {
		location.href = $(this).children('a').attr("href");
	});
	
	$(".graphic_right, .graphic_left").click( function() {
		location.href = $(this).children('div').children('a').attr("href");
	});
	
}

// ========
// = sifr =
// ========

var heavy = { src: '/sifr/heavy.swf' };
var book = { src: '/sifr/book.swf' };

sIFR.activate(book);

function sifr_replace_all() {  
	sIFR.replace(heavy, {
		selector: '.left h1',
		wmode: 'transparent'
	});
	sIFR.replace(book, {
		selector: '.left h2',
		wmode: 'transparent',
		css: {
			'.sIFR-root, a, a:link, a:hover': { 'color': '#666666', 'text-decoration': 'none' }
		}
	});
}

sifr_replace_all();


// ========
// = form =
// ========

function calculate_total() { // prereg form

	if(window.location.href.indexOf('firefly') != -1 ) {
		return false;
	}
	theform = document.getElementById('preregister');
	sits_nums = ['sits_f_students', 'sits_f_sponsors', 'sits_m_students', 'sits_m_sponsors'];
	jhc_nums = ['jhc_f_students', 'jhc_f_sponsors', 'jhc_m_students', 'jhc_m_sponsors'];

	sits = 0;
	for(i=0;i<sits_nums.length;i++) {
		current = document.getElementById('ff_' + sits_nums[i]).value;
		if(!isNaN(parseInt(current))) {
			sits = sits + parseInt(current);
		}
	}

	jhc = 0;
	for(i=0;i<jhc_nums.length;i++) {
		current = document.getElementById('ff_' + jhc_nums[i]).value;
		if(!isNaN(parseInt(current))) {
			jhc = jhc + parseInt(current);
		}
	}
	
	// sibling counts
	var sits_siblings = parseInt(document.getElementById('ff_sits_siblings').value);
	var jhc_siblings = parseInt(document.getElementById('ff_jhc_siblings').value);
	
	if(isNaN(sits_siblings)) sits_siblings = 0;
	if(isNaN(jhc_siblings)) jhc_siblings = 0;

	var sits_sub = sits * 250;
	var sits_late = sits * 10;
	sits_sub = sits_sub - (sits_siblings * 25) + sits_late;
	//var sits_due = sits * 150;

	var jhc_sub = jhc * 250;
	var jhc_late = jhc * 10;
	jhc_sub = jhc_sub - (jhc_siblings * 25) + jhc_late;
	//var jhc_due = jhc * 135;

	var a = sits + jhc; 
	//var s = a * 225; // subtotal // FALSE! didn't factor sibling rate
	
	var s = jhc_sub + sits_sub;
	
	var cc = s * .03; // just cc

	var t = s + cc; // grand total
	
	var now = (jhc + sits) * 75;
	
	var checkin = s - now;
	
	var now = now * 1.03;

	//var total_due = jhc_due + sits_due;
 	//+ ' (' + a + ' attendees)'

	document.getElementById('sits_late').innerHTML = '$' + sits_late.toFixed(2);
	theform.sits_late.value = '$' + sits_late.toFixed(2);
	
	document.getElementById('jhc_late').innerHTML = '$' + jhc_late.toFixed(2);
	theform.jhc_late.value = '$' + jhc_late.toFixed(2);
	
	document.getElementById('sits_sub').innerHTML = '$' + sits_sub.toFixed(2);
	theform.sits_sub.value = '$' + sits_sub.toFixed(2);

	document.getElementById('jhc_sub').innerHTML = '$' + jhc_sub.toFixed(2);
	theform.jhc_sub.value = '$' + jhc_sub.toFixed(2);

	document.getElementById('total_checkin').innerHTML = '$' + checkin.toFixed(2);
	theform.total_checkin.value = '$' + checkin.toFixed(2);

	document.getElementById('total_prereg').innerHTML = '$' + now.toFixed(2);
	theform.total_prereg.value = '$' + now.toFixed(2);

	document.getElementById('total_cost').innerHTML = '$' + s.toFixed(2);
	theform.total_cost.value = '$' + s.toFixed(2);


	return false;
}
 
