
// overwrite some jquery bugs
var height_ = jQuery.fn.height;
jQuery.fn.height = function() {
	if ( this[0] == window && jQuery.browser.opera && jQuery.browser.version >= 9.50)
 		return window.innerHeight;
	else return height_.apply(this,arguments);
};



// _meef.main stuff
(function(container) {

	var self = {

		priv:	1,
		msie6:	false,


		// public variables & functions
		ready:	function()	{

			// prepare navigation
			self.prepareNav();
			self.prepareStatusBox();
			// self.prepareTooltip();

			// are we on ie6?
			if ($.browser.msie && parseInt($.browser.version) == 6) self.msie6 = true;

			// fix background flicker on ie6
			/*@cc_on
			document.execCommand("BackgroundImageCache", false, true);
			@*/


			// start fixpng stuff
			// $('.autoPNG').ifixpng();
			if (self.msie6)	$('.autoPng').ifixpng();

			// gamehints close
			$('#container div.gameHintClose').bind('click', self.gameHintClose);
		},

		gameHintClose:	function(event)	{
			// close layer, make ajax call
			var parent = $(this).parent();
			var id = $(parent).attr('rel');

			var post = {id: id};
			var url = '/main/ajax-game-hint-remove/?' + SID;
			$.ajax({
				type:	'POST',
				url:	url,
				cache:	false,
				data:	post,
				dataType: 'json'
			});
			$(parent).hide();
		},

		prepareTooltip:	function()	{
			var toolOptions = {
				track: true,
			    delay: 0,
			    showURL: false,
			    showBody: " - ",
			    extraClass: "pretty",
			    fixPNG: true,
			    opacity: 0.95
			};
			$('.tooltip').tooltip(toolOptions);
		},

		prepareNav:	function()	{

			// make logo clickable
			$('#logoLeft').bind('click', function(){ document.location = '/' + SID });
			
			// header navigation
			$('#header li').each(function(){

				// add click stuff on each button
				$(this).bind('click', function(){
					// redirect to rel-attribute of li
					var url = $(this).attr('rel');
					if (url.substr(0,4) == 'http')	{
						// open in new tab
						window.open(url);	
						
					} else {
						// redirect in same window
						location.href = url;
					}
				});

				// do not add hover if already has active
				if ($(this).hasClass('active')) return;
				// add hover
				$(this).bind('mouseenter', function(){
					$(this).addClass('active');
				}).bind('mouseleave', function(){
					$(this).removeClass('active');
				});

			});

			// evnetually is there a leftMenu nav?
			var sideNav = $('.contentSide ul li');
			if (sideNav.length > 0)	{
				$.each(sideNav, function(){
					if ($(this).hasClass('active'))	return;
					$(this).bind('mouseenter', function()	{
						$(this).addClass('active');
					}).bind('mouseleave', function()	{
						$(this).removeClass('active');
					}).bind('click', function(event){
						event.preventDefault();
						// find href
						var href = $(this).children().attr('href');
						location.href = href;
					});

				});

			}

			// eventually outer page?
			$('#outerHeader .outerNav, #outerHeaderNav .outerNav').each(function()	{

				$(this).bind('mouseenter', function(){
					$(this).addClass('active');
				}).bind('mouseleave', function() {
					$(this).removeClass('active');
				}).bind('click', function(){
					if (this.id == 'outerHeader3')	{
						if (lang == 'en') {
							window.open('http://board.smashdown.net/', 'forumSmashdown');
						} else {
							window.open('http://forum.smashdown.de/', 'forumSmashdown');	
						}
						
						return;
					}
					if (this.id == 'outerHeader1')	{
						if ($(this).attr('data-signUpUrl') != undefined)	{
							// redirect to signup url
							document.location = $(this).attr('data-signUpUrl');
							return;
						}
						$('#containerSignUp').slideDown(200);
						return;
					}

					//container.game.actionDialog.message('Dieses Spiel befindet sich noch in der Beta-Testphase. Deshalb sind diese Bereiche leider noch nicht verfügbar. ');
				})
			});


		},


		prepareStatusBox: function()	{
			$('#statusBox').css('opacity', 0.4);
			$('#statusBox').bind('mouseenter', function() {
				$(this).animate({'opacity':0.99}, {queue: false, duration: 200, complete: self.counter});
			}).bind('mouseleave', function() {
				$(this).animate({'opacity':0.4}, {queue: false, duration: 200, complete: self.counter});
			});

		},

		counter: function()	{
			self.priv++;
		}

	};
	container.main = self;


})(_meef);
$(_meef.main.ready);

_meef.game = {
	formatDecimal:		function(nStr)	{
		
		var decPoint = ','; var thousandsPoint = '.';
		if (lang == 'en') {
			decPoint = '.';
			thousandsPoint = ',';
		}
	
		nStr += '';
		var x = nStr.split(thousandsPoint);
		var x1 = x[0];
		var x2 = x.length > 1 ? decPoint + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + thousandsPoint + '$2');
		}
		return x1 + x2;

	}
};







