function $get (key, url) {
	if(arguments.length < 2) url =location.href;
	if(arguments.length > 0 && key != ""){
		if(key != "#"){
			key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
			var results = regex.exec(url);
			return (results == null )? "" : results[1];
		}else {
			var result = url.split("#");
			return (result.length > 1)? result[1] : "";
		}
	} else {
		url = url.split("?");
		var results = "{"
			if(url.length > 1){
				url = url[1].split("#");
				if(url.length > 1) results = results+'"hash": "'+url[1]+'"';
				url[0].split("&").each(function(item,index){
					item = item.split("=");
					results = (results.length == 1)? results+'"'+item[0]+'":"'+item[1]+'"' : results+',"'+item[0]+'":"'+item[1]+'"';
				});
			}
		return Json.evaluate(results+"}");
	}
}

var Site = {
	
	start: function() {
		
		Site.forecast = $('forecast');
		Site.forecastes = $('forecastes');
		Site.sidepanel = $('sidepanel');
		Site.newsblock = $('newsblock');
		
		if (Site.forecast) new Json.Remote('../includes/NewAjax.php?forecast=1', {onComplete: function(obj) {if (obj) Forecast.start(obj)}}).send();
		
		if (Site.sidepanel) Site.doSidepanel();
		
		if (Site.forecastes) Site.doForecastes();
		
		if (Site.newsblock) {
			Site.newsblock.getElements('.news').each(function(e, i) {
				e.addEvents({
				'click': function() {document.location.href = e.getElement('a').href + '&v=1'},
				'mouseenter': function() {e.addClass('over'); e.setOpacity(1)},
				'mouseleave': function() {e.removeClass('over'); e.setOpacity(0.7)} 
				});
			});	
		}
		
	
		if ($('loginForm') && $('loginLink')) {
			$('loginLink').addEvent('click', function() {
				new Fx.Style ($('inPanel1'), 'opacity', {onComplete: function() {
					$('inPanel1').setStyle('display', 'none');
					$('inPanel2').setStyle('display', 'block');
					$('loginFormName').focus();
				}}).start(0);										  
			});
			$('loginForm').getElements('input').each(function (e) { 
				e.addEvents ({
				'focus':function() { e.addClass('focus') },
				'blur':function() { e.removeClass('focus') }
				});
			});
			//$('loginForm').getElement('.submit').addEvent('click', function () {$('loginForm').submit()});
		}
	
		if ($('searchForm') && $('searchLink')) {
			$('searchLink').addEvent('click', function() {
				new Fx.Style ($('inPanel1'), 'opacity', {onComplete: function() {
					$('inPanel1').setStyle('display', 'none');
					$('inPanel3').setStyle('display', 'block');
					$('searchFormStr').focus();
				}}).start(0);
			});
			$('searchForm').getElements('input').each(function (e) { 
				e.addEvents ({
				'focus':function() { e.addClass('focus') },
				'blur':function() { e.removeClass('focus') }
				});
			});
			//$('searchForm').getElement('.submit').addEvent('click', function () {$('searchForm').submit()});
		}
		
		if ($('login_form')) {
			$('forgotPassLink').addEvent('click', function () {
				$('loginPassLayer').style.display = 'none';
				$('login_submit').value = 'Напомнить пароль';
			});
		}
		
		$$('.button').each (function (e) {
			e.addEvents({
				'mouseover': function () {this.addClass('over')},
				'mouseout': function () {this.removeClass('over')}
			});
		});
		
		$('banner3').innerHTML = '<PARAM NAME="movie" value="/userfiles/Image/banners/kupibilliard.swf"><PARAM NAME="quality" VALUE="high"><PARAM NAME="wmode" VALUE="opaque"> <EMBED src="/userfiles/Image/banners/kupibilliard.swf" quality="high" wmode="opaque" bgcolor="#347F26" WIDTH="350" HEIGHT="100" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
		
	
	},

	doSidepanel: function () {
		divs = Site.sidepanel.getElements('.tcontent');
		divs[0].setStyle('display', 'block');
		els = Site.sidepanel.getElements('.tabs a');
		els.each(function(e, i) {
			e.addEvents({
				'click': function() {
					els.removeClass('selected'); 
					e.addClass('selected');
					divs.setStyle('display', 'none');
					divs[i].setStyle('display', 'block');
				},
				'mouseenter': function() {e.addClass('over')},
				'mouseleave': function() {e.removeClass('over')}
			});
		});
	},
	
	doForecastes: function() {
		els = Site.forecastes.getElements('.fc');
		els.each(function(e, i) {
			var num = e.getElement('.num');
			num.setHTML(i+1).setOpacity(0.2);
			e.addEvents({
				'mouseenter': function() {e.addClass('over')},
				'mouseleave': function() {e.removeClass('over')}
			});
		});
	}
};

var Forecast = {
	start: function(obj) {
		
		var isOpen = false;
		
		var objIn = {'0': {'width': [332, 0]}, '1': {'width': [445, 778]}, '2': {'left':[960, 660]}};
		var objOut = {'0': {'width': [0, 332]}, '1': {'width': [778, 445]}, '2': {'left':[660, 960]}}
		
		Forecast.items = obj;
		Forecast.cur = 0;
		Forecast.run = false;
		Forecast.el = Site.forecast.getElement('.right');
		Forecast.left = Site.forecast.getElement('.left');
		Forecast.link = $("forecast-link");
		Forecast.item = Forecast.el.getElement('.item');
		Forecast.forecost = $('forecost');
		Forecast.txt = Site.forecast.getElement('.txt');
		
		Forecast.itemFx = new Fx.Style (Forecast.item, 'left', {wait: false, duration: 800, transition: Fx.Transitions.Quad.easeInOut, onComplete: function() {
			Forecast.run = false; 
			Forecast.link.setStyle('display', 'block')
		}});
		Forecast.fx = new Fx.Elements([this.left, this.el, this.forecost], {onComplete: function() {
			if (isOpen) { Forecast.forecost.setStyle('display', 'block')}
		}});
		
		Site.forecast.addEvents({'click': function(e) {
			document.location.href='http://www.onlinesport.ru/?m1=40'
			/*
			if (!Forecast.run)
			if (!isOpen) {
				$clear(Forecast.delay);
				Forecast.fx.start(objIn);
				Forecast.link.setStyle('display', 'none');
				Forecast.item.setStyle('left', 0);
				isOpen= true;
			} else  {
				Forecast.hide.delay(1000);
				Forecast.fx.start(objOut);
				Forecast.forecost.setStyle('display', 'none');
				Forecast.link.setStyle('display', 'block');
				isOpen = false;
			}*/
			},
			'mouseenter': function() {Forecast.txt.addClass('over')},
			'mouseleave': function() {Forecast.txt.removeClass('over')}
		});
		Forecast.show();
		
	},
	
	show: function() { 
		Forecast.link.setStyle('display', 'none');
		Forecast.run = true;
		Forecast.item.setHTML('<div class="dt">' + Forecast.items[Forecast.cur].dt + '</div><h3>' + Forecast.items[Forecast.cur].title + '</h3><a href="#" id="forecast-link">Узнать наш прогноз</a>');
		$("forecast-msg").setText(Forecast.items[Forecast.cur].msg);
		Forecast.item.setStyle('left', -400);
		Forecast.itemFx.start(0);
		Forecast.delay = Forecast.hide.delay(3000);
	},
	
	hide: function() {
		Forecast.link.setStyle('display', 'none');
		Forecast.run = true;
		Forecast.itemFx.start(500);
		if (Forecast.cur != Forecast.items.length - 1) Forecast.cur++; else Forecast.cur = 0;
		Forecast.delay = Forecast.show.delay(500);
	}
};

function doNovoteka() {
	new Asset.javascript('http://nnn.novoteka.ru/show.cgi?adp=1286&div=novoteka&nnn=1286');
}


window.addEvent('domready', Site.start);
