$().ready(function(){

	if (document.referrer && !document.referrer.match("timeboil")){
		$("body").append("<img src='/stat/?referer="+encodeURIComponent(document.referrer)+"&uri="+encodeURIComponent(window.location.href)+"' class='g-block'>");	
	}


	$(".b-vote-link").click(function(){
		$(".b-vote-push").submit();
		return false;
	});
	$("a.b-login").click(function(){
		var el = $(this).parent().prev();
		$(el).val($(this).attr("href"));
		return false;
	});
	
	$(".b-search").focus(function(){
		if ($(this).val() == "ключевое слово"){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val() == ""){
			$(this).val("ключевое слово");
		}
	});

	$(".b-password").focus(function(){
		if ($(this).val() == "Пароль"){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val() == ""){
			$(this).val("Пароль");
		}
	});
	_parseElements();
});


function _parseElements(){
	$.each($(".b-link-ajax"),function(){
		if (!$(this).attr("yea"))
		{
			$(this).attr("yea","year");
			$(this).bind("click",function(){
					$(this).attr("yea","yea");
					var target = $(this).attr("rel") || $(this).attr("target");	
					if (target == "function"){
						var run = $(this).attr("code");
						eval(run);
						return;
					}
					var obj = this;
					var href = $(this).attr("href") || $(this).attr("action");
					var load = $(this).attr("type");
					var loads = new Array;
					if (load)
					{
						loads = load.split(",");
					}
					var relement = $(this).attr("relement");
					if (!href.match(/\/$/) && !href.match(/\?/)){
						href+="/";
					}
					if (!href.match(/\?/)){
						href+="?";
					}
					else{
						href+="&";
					}
					if (!target){
						target = $(this).parents(".b-tab-body")[0];
					}
					href+="rnd="+Math.round(Math.random()*77777777+77777777);
					$.ajax({
						url:href,
						dataType:'html',
						type:'GET',
						success:function(msg){
							if (msg!="&nbsp;")
							{
								$(target).html(msg);
								window.setTimeout(function(){
									_parseElements();
								},50);
							}
							if (loads[0] && loads[1])
							{
								eval(loads[0]+"(obj,"+loads[1]+","+loads[2]+")");
							}
						}
					
					});
				return false;
			});
		}		
	});
	$.each($(".b-form-ajax"),function(){
		if (!$(this).attr("yea"))
		{
			$(this).attr("yea","yea");
			$(this).bind("submit",function(){
					var target = $(this).attr("rel") || $(this).attr("target");
					var nofuck = $(this).attr("nofuck") || false;
					if (nofuck){
						alert(nofuck)
						return false;
					}
					$(this).ajaxSubmit({
						success:function(msg){
							if (msg!="&nbsp;")
							{
								$(target).html(msg);
								window.setTimeout(function(){
									_parseElements();
								},50);
							}
						}
					});
				return false;
			});
		}
	});
	$.each($(".b-calendar"),function(){
		if (!$(this).attr("yea")){
			$(this).attr("yea",1);
			//$(this).datepicker({firstDay: 1});
			$(this).datepicker({firstDay: 1, changeMonth: true, changeYear: true, showOn: 'button', buttonImage: '/i/calendar.gif', dateFormat:'yy-mm-dd'});
		}
	});
}