/* general js functions */

// global init
window.addEvent('domready', function() {
	
	// setup hat rollovers
	var hatLink = $('storeHat').getElement('a');
	var storeLink = $('storeLink');
	var yCoord = storeLink.getPosition().y - 26;
	hatLink.setStyle('top', yCoord + 'px');
	hatLink.addEvent('mouseover', function(){
		storeLink.addClass('on');
	});
	hatLink.addEvent('mouseout', function(){
		storeLink.removeClass('on');
	});
	
	// hilight news category for all posts
	var navLinks = $$('ul.news li a');
	if (navLinks[2]) navLinks[2].addClass('on');
	
	// set flash article color fade
	if ($('flashPost')) {
		var myFx = new Fx.Tween($('flashPost'), { duration: 5000 })
		myFx.start('background-color', '#fff', '#FFDF89');
	}
	
});

// function to open external links in new window
function openInNewWin() {
	// suggest all new windows have unique names
	var winName = 'window_'+ Math.round(100000 * Math.random());
	var newWindow = window.open(this.get('href'), winName);
	newWindow.focus();
	return false;
}

// function to set external links opening behavior
function setExtLinks(){
	var anchors = $$("a");
	$each(anchors, function(el) {
		if (el.get("href") && el.get("rel") == "ext"){
			el.onclick = openInNewWin;
		}
		if (el.hasClass("missing")){
			el.addEvent('click', function(e){
				e.stop();
			});
		}
	});
}
