
(function (a) {
    a.fn.hoverIntent = function (k, j) {
        var l = {
            sensitivity: 10,
            interval: 100,
            timeout: 1
        };
        l = a.extend(l, j ? {
            over: k,
            out: j
        } : k);
        var n, m, h, d;
        var e = function (f) {
            n = f.pageX;
            m = f.pageY
        };
        var c = function (g, f) {
            f.hoverIntent_t = clearTimeout(f.hoverIntent_t);
            if ((Math.abs(h - n) + Math.abs(d - m)) < l.sensitivity) {
                a(f).unbind("mousemove", e);
                f.hoverIntent_s = 1;
                return l.over.apply(f, [g])
            } else {
                h = n;
                d = m;
                f.hoverIntent_t = setTimeout(function () {
                    c(g, f)
                }, l.interval)
            }
        };
        var i = function (g, f) {
            f.hoverIntent_t = clearTimeout(f.hoverIntent_t);
            f.hoverIntent_s = 0;
            return l.out.apply(f, [g])
        };
        var b = function (q) {
            var o = (q.type == "mouseover" ? q.fromElement : q.toElement) || q.relatedTarget;
            while (o && o != this) {
                try {
                    o = o.parentNode
                } catch (q) {
                    o = this
                }
            }
            if (o == this) {
                return false
            }
            var g = jQuery.extend({}, q);
            var f = this;
            if (f.hoverIntent_t) {
                f.hoverIntent_t = clearTimeout(f.hoverIntent_t)
            }
            if (q.type == "mouseover") {
                h = g.pageX;
                d = g.pageY;
                a(f).bind("mousemove", e);
                if (f.hoverIntent_s != 1) {
                    f.hoverIntent_t = setTimeout(function () {
                        c(g, f)
                    }, l.interval)
                }
            } else {
                a(f).unbind("mousemove", e);
                if (f.hoverIntent_s == 1) {
                    f.hoverIntent_t = setTimeout(function () {
                        i(g, f)
                    }, l.timeout)
                }
            }
        };
        return this.mouseover(b).mouseout(b)
    }
})(jQuery);

var here_ID = 0;
var as = 0;

function goHere()
{
	if(as != 1)
	{
		here_ID ++;
		var bem = here_ID+1;
		$('#tophot'+here_ID).removeClass("here");
		if(here_ID != 4) $('#tophot'+here_ID).next().addClass("here");
		else {
			$('#tophot1').addClass("here");
			bem = 1;
			here_ID = 0;
		}
		$(".main-hot .img:visible").fadeOut(300, function () {});
		$("#imgfortophot" + bem).fadeIn(300)
	}
}

 

jQuery(function (d) {

			var setting = {
			  tl: { radius: 10 },
			  tr: { radius: 10 },
			  bl: { radius: 10 },
			  br: { radius: 10 },
			  antiAlias: true
			}
			curvyCorners(setting, ".img, .myBox_text");
			$('.myBox_text').fadeTo(100, 0.80);
			
    d(".tophot div").hoverIntent(function () {
        if (d(this).hasClass("here")) {} else {
            d(".tophot div").removeClass("here");
            d(this).addClass("here");
            bem = d(this).attr("id");
            d(".main-hot .img:visible").fadeOut(300, function () {});
            d("#imgfor" + bem).fadeIn(300)
        }
    }, function () {
		here_ID = d(this).attr("id");
		here_ID = parseInt(here_ID.replace('tophot',''));
		here_ID = here_ID - 1;
		});

		$(".head").mouseover(function(){
			as = 1;
		}).mouseout(function(){
			as = 0;
		})
		setInterval("goHere(as, here_ID)",5000);		
});



// карусель конец

function go_page(element)
{
	$('html').scrollTo(".news",1000);
}


var lasturl="";
var i = 0;
var a = 0;
function checkURL(a)
{
	hash = window.location.hash;
	if(lasturl != '') 
	if(hash == '') { 
		var domen = window.location.hostname;
		hash = location.href; 
		hash = hash.replace('http://'+domen,'');
		//alert(hash);  
	}
		if(hash != lasturl)
		{		  
		  if((hash!='#postform')&&(hash!='#bbcode')&&(hash!='#review_anchor'))
		  {
			
			if(hash.indexOf("message")!=-1)	
			{
				lasturl=hash;
			}
			else
			{				
				if(a==1) $('#content').html('<br /><br /><br /><br />');
				lasturl=hash;
		  		loadPage(hash, a);
			}
		  }
		}
}

function loadPage(hr, a)
{
	//alert(hr +' ! ');
	//hr = decodeURI(hr);
	//alert(hr +' !!!! ');
	hr = hr.replace('#','');
	hr = hr.replace('%3F','?');
	hr = hr.replace('%3D','=');
	//alert(hr);
	var w = $('#content').innerWidth();
	var h = $('#content').innerHeight();
	$('#content').prepend('<div class="zaliv" style="width:'+w+'px; height:'+h+'px;"><img src="/bitrix/templates/main/images/ajax-loader.gif" style="margin:10px;" /></div>');
	$('.zaliv').fadeTo(100,0.50);
	$('#content').load(hr, 'aj=1',function() { 
	});
	
}

$(document).ready(function () {		

checkURL(1);	
setInterval("checkURL()",250);

$("a.aj").live('click', function() {
	var hr = $(this).attr("href");
	var domen = window.location.hostname;
	
	go_page(this);
	//alert(domen);
	hr = encodeURI(hr);
	//alert('!'+hr);
	hr = hr.replace('http://'+domen,'');
	hr = hr.replace('?','%3F');
	hr = hr.replace('=','%3D');
	window.location.hash = hr;
	checkURL();
	return false;
});

var subm = '';

$('input[class="but"]').live('click', function() {
	subm = $(this).attr("name");
	if(subm == 'set_filter') subm = 'del_filter'; 
	else {
		subm = 'set_filter';
		$('#filter_form').find('input[type!="submit"][type!="hidden"]').each(function() { $(this).attr('value',''); });
	}
	var allInputs = $('#filter_form').find("input");
	var i=0;
	//var text = $('#filter_form').attr('action');
	var text =  $('#filter_form').attr('action');
	//var dir = $('#filter_form').attr('action');
	//alert (dir);
	for(i; i<allInputs.length; i=i+1 )
	{
		if(subm != allInputs[i].name) text += (i < 1) ? '?'+allInputs[i].name+'='+allInputs[i].value : '&'+allInputs[i].name+'='+allInputs[i].value;
	}
	//alert(text);
	text = encodeURI(text);
	//text = text.replace('http://'+domen,'');
	text = text.replace('?','%3F');
	text = text.replace('=','%3D');
	window.location.hash = text;
	checkURL();	
	return false;
});
	
/*$("#filter_form").submit(function() {
	
});*/

//$(document).find('input[type="submit"]').each(function() { $(this).addClass('blue_but'); });


//show_news(document.getElementById("head_section_first"));	  	
			  
	$(".top_menu_fon td, .news_menu_fon td").hover(
	  function () {
		$(this).css("background-position","top");
	  }, 
	  function () {
		$(this).css("background-position","bottom");
	  }
	);
	
	$(".blue_but").hover(
	  function () {
		$(this).css("background-position","bottom");
	  }, 
	  function () {
		$(this).css("background-position","top");
	  }
	);
	
	
});



function show_razd(elem)
{
	$('#show_razd').attr('href',elem)
}

