/* IE6 FIX */
var blank = new Image();
blank.src = '/assets/images/slug.gif';
function fix_png(png) {
	var src = png.src;
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	png.onload = function() { };
	png.src = blank.src;
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}



/* NAV */
var dropdown_timeout = 500;
var dropdown_closetimer = 0;
var nav_item = 0;
function dropdown_open() {
	dropdown_canceltimer();
	dropdown_close();
	nav_item = $(this).addClass('over');
}
function dropdown_close() {
	if(nav_item) nav_item.removeClass('over');
}
function dropdown_timer() {
	dropdown_closetimer = window.setTimeout(dropdown_close, dropdown_timeout);
}
function dropdown_canceltimer() {
	if(dropdown_closetimer) {
		window.clearTimeout(dropdown_closetimer);
		dropdown_closetimer = null;
	}
}
function nav_over() {
	dropdown_canceltimer();
	dropdown_close();
	nav_item = $(this).addClass('over');
}
function nav_out() {
	if(nav_item) nav_item.removeClass('over');
}
document.onclick = dropdown_close;


/* CHANGE CURSOR */
function changeCursor(targ) {
	targ.style.cursor = "pointer";
}


/* TOGGLER */
function showDetails(num) {
	$(document.getElementById('show_'+num)).hide();
	$(document.getElementById('hide_'+num)).show();
	$(document.getElementById('details_'+num)).slideDown();
}
function hideDetails(num) {
	$(document.getElementById('show_'+num)).show();
	$(document.getElementById('hide_'+num)).hide();
	$(document.getElementById('details_'+num)).slideUp();
}


/* SIFR */
if(typeof sIFR == "function"){
	sIFR.replaceElement("h2", named({sFlashSrc: "/assets/swf/centaur.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
};



/* DOC READY */
$(document).ready(function() {
	
	// fix ie6
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		// png fix
		$('img[src$=.png]').each(function() {
			if (!this.complete) {
				this.onload = function() {fix_png(this) };
			} else {
				fix_png(this);
			}
		});
		// cache bg images
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}
	
	// set nav
	$('#nav_about').bind('mouseover', nav_over);
	$('#nav_about').bind('mouseout',  nav_out);
	$('#nav_team').bind('mouseover', dropdown_open);
	$('#nav_team').bind('mouseout',  dropdown_timer);
	$('#nav_research').bind('mouseover', dropdown_open);
	$('#nav_research').bind('mouseout',  dropdown_timer);
	$('#nav_news').bind('mouseover', nav_over);
	$('#nav_news').bind('mouseout',  nav_out);
	$('#nav_events').bind('mouseover', nav_over);
	$('#nav_events').bind('mouseout',  nav_out);
	$('#nav_collaborators').bind('mouseover', dropdown_open);
	$('#nav_collaborators').bind('mouseout',  dropdown_timer);
	$('#nav_contact').bind('mouseover', nav_over);
	$('#nav_contact').bind('mouseout',  nav_out);

	// homepage's innerfade
	$('#hero').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '370px'
	});
	$('#upcoming_events div').innerfade({
		speed: 0,
		timeout: 5000,
		type: 'sequence',
		containerheight: '45px'
	});

});
