
function comingup()//accordian stuff for coming up
{
	//inject a toggle
	var dd = $$('#secondary #coming-up dd.platforms');
	for(i=0;i<dd.length;i++)
	{
		var new_dd  = new Element('dd', {
			'class': 'toggle open',
			'id': 'toggle_'+i
			});
			new_dd.setText('toggle view');
			new_dd.injectAfter(dd[i]);/**/
	}
	
	var accordion = new Accordion('dd.toggle', '.open-close', {
	opacity: true,
	display: 0,//first one to open
	fixedHeight: 110, //force height for ff fix
		onActive: function(toggler, element){
			toggler.removeClass('open');
			toggler.addClass('close');
		},
 
		onBackground: function(toggler, element){
			toggler.removeClass('close');
			toggler.addClass('open');
		}
	}, $('coming-up'));
}


function selects()
{
	var all_selects = $$('select');
	for(i=0;i<all_selects.length;i++)
	{
		//alert(i);
		all_selects[i].getParent().id='select'+(i+1) ;
		var mySelect = new elSelect( {container : 'select'+(i+1)} )
		all_selects[i].setStyle('z-index',(i+1));

	}
}

function rollovers(item,fade)
{		var list = $$(item);
		list.each(function(element) {
		var fx = new Fx.Styles(element, {duration:200, wait:false});
	
		element.addEvent('mouseenter', function(){
			fx.start({
				'opacity': fade
			}); 
		});
		element.addEvent('mouseleave', function(){
			fx.start({
				'opacity': 1
			});
		});
	});
}

function emailCloak() {
	if (document.getElementById) {
		var alltags = document.all? document.all : document.getElementsByTagName("*");
		for (i=0; i < alltags.length; i++) {
			if (alltags[i].className == "cloak") {
				var oldText = alltags[i].firstChild;
				var emailAddress = alltags[i].firstChild.nodeValue;
				var user = emailAddress.substring(0, emailAddress.indexOf("("));
				var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
				var newText = user+"@"+website;
				var a = document.createElement("a");
				a.href = "mailto:"+newText;
				var address = document.createTextNode(newText);
				a.appendChild(address);
				alltags[i].replaceChild(a,oldText);
			}
		}
	}
}

function maketabs(tabclass)
{
	var all_tabs = $$(tabclass);

	if (all_tabs.length == 0) return false;
	

	for(i=0;i<all_tabs.length;i++)
	{
		all_tabs[i].setProperty('id', 'tabs_'+i); 
	
		myTabs1 = new mootabs('tabs_'+i, 
			{
			//	height: '550px', 
				width: '610px', 
			//	changeTransition: 'none', 
				mouseOverClass: 'over'
			}
		);
	}
}

function askfixer()
{
	var askabout = $$('.askaboutgames');
	if(askabout.length > 0){
		

		var askfix  = new Element('div', {
			'class': 'askfixer'
			});

		askfix.injectBefore(askabout[0]);
	}
}

function remove_prompt ()
{
	theObjects = document.getElementsByTagName("object"); 
	for (var i = 0; i < theObjects.length; i++) { 
	theObjects[i].outerHTML = theObjects[i].outerHTML; 
	}
}

function sortNumber(a, b)
{
return a - b;
}





var startTime = $time();
/* moo start (dom ready)*/
window.addEvent('domready', function() {
	//alert(startTime);
	externalLinksV2();//links with rel=external open new window so we we dont have to use _blank
	comingup(); //coming up accordian
	rollovers('#primary .news  img',0.7); //fade effects for images
	rollovers('.game-info-site-link a',0.8)
	rollovers('.askaboutgames a',0.8); //fade for games askaboutgames btn
	maketabs('.tabs'); //make the tabs, pass the class of the tabs  to it
	emailCloak();
	remove_prompt ();
	askfixer();
	var getfeatured = $$('.featured-game');
	if(getfeatured.length ==0 )
	{
		var f = $$('#primary .gutter');
		f.addClass('position');	
	} else {

	

			//get elements
			var f1 = $$('#featured_games_slot_1  .gradient dl');
			var f2 = $$('#featured_games_slot_2  .gradient dl');
			var f3 = $$('#featured_games_slot_3  .gradient dl');

			var defaultHeight = '190';

			//get heights
			var f1h = f1[0].getCoordinates().height;
			var f2h = f2[0].getCoordinates().height;
			var f3h = f3[0].getCoordinates().height;
			
			//bung in array
			var fheights =  new Array(3);
			fheights[0] = f1h;
			fheights[1] = f2h;
			fheights[2] = f3h;

			

			//if 4?
			if($$('#featured_games_slot_4  .gradient dl').length > 0){
				var f4 = $$('#featured_games_slot_4  .gradient dl');
				var f4h = f4[0].getCoordinates().height;
				fheights[3] = f4h;
				var last = 3;
			} else {
				var last = 2
			}

			

			
			fheights.sort(sortNumber);
			
			if(fheights[last]<defaultHeight)
			{
				fheights[last]=defaultHeight;
			}

			//alert(fheights[2]);
			//alert(f1h + " " + f2h + " "+f3h );

			f1[0].setStyle('height', fheights[last]+'px');
			f2[0].setStyle('height', fheights[last]+'px');
			f3[0].setStyle('height', fheights[last]+'px');

			if($$('#featured_games_slot_4  .gradient dl').length > 0){
				f4[0].setStyle('height', fheights[last]+'px');
			}
	
		
	}
	
});