/*** SETTINGS ***/
var settings = {
	defaults: {
		bgColor: "#EEE",
		hoverColor: "#CFD4E5",
		titleColor: "#475275",
		titleHoverColor: "#6574A6",
		panelImage: "default/img/default.png"
	}
}
/** END SETTINGS **/

/*** DO NOT MODIFY ***/

function addTileEvents(id){
	var id = (typeof(id) == 'undefined')? "" : "#"+id;
	$$(id+".group>a").each(function(e){
		e.setStyle('background', settings.defaults.bgColor);
		e.set('tween', { duration: 500, transition: Fx.Transitions.Circ.easeOut });
		e.addEvents({
			// Highlight tile on mouse over
			'mouseenter': hoverHighlight.bind(e),
			// Unhightlight tile on mouse leave
			'mouseleave': hoverUnhighlight.bind(e)
		});
	});
}

function hoverHighlight(){
	var prop = 'background-color';
	this.tween(prop, value(this.retrieve('hoverColor'), settings.defaults.hoverColor));
}
function hoverUnhighlight(){
	var prop = 'background-color';
	this.tween(prop, value(this.retrieve('bgColor'), settings.defaults.bgColor));
}

function resize(e){
	
	var groups = $('groups');
	var groupsCont = $('groupsCont');
	var groupsInner = $$('#groups #innerdiv')[0];
	
	var bodyDim = $$('body')[0].getSize();
	
	if(bodyDim.x > 850){
		$$('.panel').setStyle('width', '29.333%');
	}else if(bodyDim.x > 530){
		$$('.panel').setStyle('width', '46%');
	}else{
		$$('.panel').setStyle('width', '96%');
	}
	
	if(typeof ps != "undefined") {
		ps.size = groupsCont.getSize();
		groups.style.width = ps.size.x + 'px';
		$$('.group').setStyle('width', groups.style.width);
		groupsInner.style.width = (groupsCont.getSize().x * ps.panels.length) + 'px';
		$('groups').style.height = ps.panels[ps.activePanelId].getSize().y + 'px';
		ps.warpTo(ps.activePanelId);
	}
		
}

function value(cvar, defaultValue){
	return (typeof(cvar) != 'undefined' && cvar != null )? cvar : defaultValue;
}

window.addEvent('domready', function(){
	$$('.group').fade('hide')
	addTileEvents();
	$$('#tabbar a').each(function(ele){
		var href = ele.get('href');
		ele.getParent().addEvent('click', function(){
			window.location.href = href;
		});
	});
	// Fade in groups
	$$('.group').fade('in');
});

