/*
	    __                     __                  _      _            
	   / /_  ____  ____  _____/ /_____________  __(_)____(_)___  ____ _
	  / __ \/ __ \/ __ \/ ___/ __/ ___/ ___/ / / / / ___/ / __ \/ __ `/
	 / /_/ / /_/ / /_/ (__  ) /_/ /__/ /  / /_/ / (__  ) / / / / /_/ / 
	/_.___/\____/\____/____/\__/\___/_/   \__,_/_/____/_/_/ /_/\__, /  
            Looking under the hood hey... like what you see?     /____/

		Take it... we can't stop you from stealing it :)
		Just hope you feel a little bit, you know,
		crap if you do.
	
							-- fyrebase.com
*/

var Rez;
var Conny = (window.console ? true: false);

window.addEvent('domready', 
function() {
	Rez = new Rezolution.Screen();
	new BoostedMenu();
	new BoostedPosts();
	new Boosted();
	new BoostedIndexes();
});

window.addEvent('resize', 
function() {
	if(!$defined(Rez)){
		Rez = new Rezolution.Screen();
	}
	Rez.Scale($(document.body).offsetWidth);
});

/**
  * @section Rezolution
  *
  * Screen rez layout trickery and what nots
  */

var Rezolution = {};

Rezolution.Screen = new Class({
	initialize: function() {
		this.Scale($(document.body).offsetWidth);
	},

	_Switch: function(unit) {
	        var rhtmed=document.getElementById('rhtmed'); 
		if (unit <= 960) {
				try { rhtmed.style.display = "none"; } catch (e) {}
			$(document.body).swapClass('Wide_Screen_Pimping', 'Needs_Glasses');
		} else {
				try { rhtmed.style.display = ""; } catch (e) {}
			$(document.body).swapClass('Needs_Glasses', 'Wide_Screen_Pimping');
		}
		
		if(unit >= 1560){
			$(document.body).addClass('floatingGrid');
		}else{
			$(document.body).removeClass('floatingGrid');
		}
	},

	Scale: function(unit) {
		this._Switch(unit);
	}
});


/**
  * @section Boosted Menu
  */

BoostedMenu = new Class({
	timer: null,
	initialize: function() {
		$each(_Menu, 
		function(pval, pkey) {
			var dt = new Element('a', {
				text: pkey
			});
			var li = new Element('li').adopt(dt);

			$('primary').adopt(li);
			if($type(pval) === 'object'){
				var dd = new Element('div', {
					'class': 'dd'
				});
				var cnt = 0;
				$each(pval, 
				function(sval, skey) {
					var item = new Element('a', {
						text: skey,
						href: this._GetHref(sval)
					});
					if (cnt === 0) {
						item.addClass('first');
					}
					dd.adopt(item);
					if (Browser.Engine.trident4) {
						item.addEvent('mouseenter', 
						function() {
							this.addClass('hovering');
						});
						item.addEvent('mouseleave', 
						function() {
							this.removeClass('hovering');
						});
					}
					cnt++;
				},
				this);
				li.addEvent('mouseleave', 
				function() {
					this.timer = (function() {
						dd.setStyle('display', 'none');
						li.removeClass('hovering');
					}).delay(500);
				}.bind(this));
				
				li.addEvent('mouseenter', 
				function() {
					this._HideAll();
					li.addClass('hovering');
					dd.setStyle('display', 'block');
					$clear(this.timer);
				}.bind(this));
				li.adopt(dd);
				
				var liStr = dt.get('text');
				var ddStr = li.getFirst('div').getFirst('a').get('text');
				var val = _Menu[liStr][ddStr];
				dt.set('href',this._GetHref(val));
				
			}else{
				li.addEvent('mouseleave', 
				function() {
					li.removeClass('hovering');
				}.bind(this));
				
				li.addEvent('mouseenter', 
				function() {
					this._HideAll();
					li.addClass('hovering');
					$clear(this.timer);
				}.bind(this));
				
				var liStr = dt.get('text');
				var val = _Menu[liStr];
				dt.set('href',this._GetHref(val));
			}
		},
		this);
	},
	
	_GetHref: function(val){
		if ($type(val) === 'number') {
			return '/forums/index.php?showforum=' + val;
		} else if ($type(val) === 'string') {
			return val;
		}
	},

	_HideAll: function() {
		$$('#nav #primary .dd').each(function(dd) {
			dd.setStyle('display', 'none');
		});
		$$('#nav #primary li').each(function(li) {
			li.removeClass('hovering');
		});
	}
});


/**
 * @section BoostedPosts
 *
 * Add hooks to elements within post instead of haxoring the templates?
 */


BoostedPosts = new Class({
	initialize: function() {
		this.AddPostBtnKlass();
	},
	
	AddPostBtnKlass: function(){
		var btns = $$('.btnPost');
		btns.each(function(btn){
			if(btn.getFirst('img').get('src').contains('t_closed.gif')){
				btn.addClass('btnPostClosed');
			}
			if(btn.getFirst('img').get('src').contains('t_moved.gif')){
				btn.addClass('btnPostMoved');
			}
		});
	}
});

BoostedIndexes = new Class({
	initialize: function() {
		var cats = $$('div.forumCat');
		if (cats.length > 0) {
			cats.getLast().addClass('last');
		}
	}
});

Boosted = new Class({
	initialize: function() {
		this.CleanPagination();
		this.RandomHead();
	},
	
	CleanPagination: function(){
		var paginations = $$('.BoostedPagination');
		paginations.each(function(p){
			var i = p.getElement('.inner');
			if(i && i.getChildren().length === 0){
				i.setStyle('display','none');
			}
		});
	},
	
	RandomHead: function(){
		$('header').addClass('headerBG' + Math.floor(Math.random()*6));
	}
});

