(function($){
    var $document = $(document),
        iframe,
        hash = '',
        needHistoryAdd = /MSIE/.test(navigator.userAgent),
        afterHistoryRead = false,
        afterHistoryAdd = false;
    function check() {
        if (hash != (hash = document.location.hash)) {
            // если мы только что прочли из хистори, не надо туда записывать
            if (!afterHistoryRead && needHistoryAdd) historyAdd(hash);
            afterHistoryRead = false;
            $document.trigger('hashChange', [hash]);
			regionCheck();
        }
        setTimeout(check, 42);
    }
    function historyAdd(hash) {
        if (!iframe) iframe = $('<iframe style="display:none" src="javascript:false;"></iframe>').appendTo('body')[0];
        var d = iframe.contentDocument ||
            (iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
        d.open();
        // можем позволить себе вольности с незакрытыми тегами, браузер достроит
        d.write('<html><head><title>' + document.title + '</title></head><body>');
        d.write($('<div/>').append($('<div id="hashdiv"></div>').text(hash)).html());
        d.write(
            '<script>' +
                'window._hash = document.getElementById("hashdiv").innerText;' +
                'window.onload = parent._historyRead;' +
            '</script>'
        );
        afterHistoryAdd = true;
        d.close();
    }
    if ('onpropertychange' in document && 'attachEvent' in document) {
        document.attachEvent('onpropertychange', function(){
            if (event.propertyName == 'location') {
                check();
            }
        });
    }
    if (needHistoryAdd) {
        window._historyRead = function(){
            if (!afterHistoryAdd) {
                var newHash = this._hash;
                if (document.location.hash != newHash) {
                    afterHistoryRead = true;
                    document.location.hash = newHash;
                }
            }
            afterHistoryAdd = false;
        };
    }

    $(function(){ setTimeout(check, 1) });

})(jQuery);
function str_replace ( search, replace, subject ) {if(!(replace instanceof Array)){replace=new Array(replace);if(search instanceof Array){while(search.length>replace.length){replace[replace.length]=replace[0];}}}if(!(search instanceof Array))search=new Array(search);while(search.length>replace.length){replace[replace.length]='';}if(subject instanceof Array){for(k in subject){subject[k]=str_replace(search,replace,subject[k]);}return subject;} for(var k=0; k<search.length; k++){var i = subject.indexOf(search[k]);while(i>-1){subject = subject.replace(search[k], replace[k]);i = subject.indexOf(search[k],i);}}return subject;}

timeIn = 0;
timeOut = 0;

function sloganRotator(timeout) {
	var current = $('#slogan div.current');
	var next = current.next();
	if (!next.html()) next = $('#slogan div:first');
	if (!$.browser.msie) current.removeClass('current').delay(timeout).fadeOut('slow',function(){next.addClass('current').fadeIn('slow'); sloganRotator(timeout);});
		else current.removeClass('current').delay(timeout).fadeOut(0,function(){next.addClass('current').fadeIn(0); sloganRotator(timeout);});
}

function hideblocks(exept) {
	$('.info .data h2').each(function(){
		var tmp = $(this).children('a').attr('name');
		if (exept == tmp) {
			$('#container'+tmp).show();
		} else {
			$('#container'+tmp).hide();
		}
	});
}

function adjustCols(time1) {
/*
		$('.col-main .content .info .wrapper').css('height','');
		$('.add-wrapper').css('height','');
		

		var add  = $('.add-wrapper').height();
		var main = $('.col-main .content .info .wrapper').height();
		var tp   = 120;
		var dlt  = 6;
		var dlt2 = -140;
		
		if (add + 100 > main) {
			var varHeight = add + tp + dlt;
			$('.col-main .content .info .wrapper').css('height', varHeight);
		}
		else {
			var varHeight = main + dlt + dlt2;
			$('.add-wrapper').css('height', varHeight);
		}

*/
}


/*
$(function(){
	$('.content a').live(
		'click',
		function(){
			if ($(this).attr('href').indexOf('menu')!="-1") {
				var href = $(this).attr('href');

				href = str_replace('http://www.garantexpress.ru','',href);
				href = str_replace('http://garantexpress.ru','',href);
				href = str_replace('/','',href);

				document.location.hash = href;

				return false;
			}
		}
	);
})
$(document).bind('hashChange', function(e, newHash){
	if (newHash.indexOf('#menu')!="-1") {
			var href = str_replace('#','',newHash);
			if (href) {
				$('.content').load(
					''+href+' .content',function(){
						document.title = $('#ptitle').text();
						adjustCols(50);
					}
				);
			}
	}
});
*/

