/* unFocus.History, version2.0 (beta 4) (2009/07/09)
Copyright: 2005-2009, Kevin Newman (http://www.unfocus.com/)
License: MIT - license.txt */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4(!H.l)6 l={};l.x=2(){9.h={};t(6 i=0;i<I.m;i++){9.h[I[i]]=[]}};l.x.J={K:2(a,b){t(6 i=0;i<9.h[a].m;i++)4(9.h[a][i]==b)7;9.h[a].18(b)},19:2(a,b){t(6 i=0;i<9.h[a].m;i++){4(9.h[a][i]==b){9.h.1a(i,1);7}}},p:2(a,b){t(6 i=0;i<9.h[a].m;i++)9.h[a][i](b)}};l.L=(2(){2 y(){6 c=9,z=1b,u,3;6 d=2(){7 M.N.1c(1)};3=d();6 e=2(a){H.M.N=a};2 O(){6 a=d();4(3!=a){3=a;c.p("n",a)}}4(A)u=A(O,z);c.1d=2(){7 3};c.k=2 k(a){4(3!=a){3=a;e(a);c.p("n",a)}7 r};4(s.P)s.P=\'1e\';4(/Q\\/\\d+/.1f(B.R)&&B.R.S(/Q\\/(\\d+)/)[1]<1g){6 f=s.m,v={},o,w=T;2 U(){o=j.V("1h");o.W="1i";o.1j="1k";j.q.X(o,j.q.Y)}e=2(a){v[f]=a;o.1l="#"+d();o.1m()};d=2(){7 v[f]};v[f]=3;2 Z(a){4(3!=a){3=a;f=s.m+1;w=r;e(a);c.p("n",a);w=T}7 r}c.k=2(a){U();c.k=Z;7 c.k(a)};2 10(){4(!w){6 a=s.m;4(a!=f){f=a;6 b=d();4(3!=b){3=b;c.p("n",b)}}}};1n(u);u=A(10,z)}1o 4(/*@1p!@*/0&&B.1q.S(/1r (\\d+\\.\\d+)/)[1]>=5.5){4(j.11&&j.11>=8)7;6 g,C;2 12(){6 a="1s";g=j.V("1t");g.D("1u",a);g.D("W",a);g.D("1v",\'1w:;\');g.13.1x="1y";g.13.1z="-1A";j.q.X(g,j.q.Y);C=1B[a];E(3,r)}2 E(a){1C(C.j){1D("1E/F");1F("<F><14></14><q 1G",\'1H="1I.l.L.G(\\\'\'+a+\'\\\');">\',a+"</q></F>");1J()}}2 15(a){3=a;c.p("n",a)}c.G=2(){c.G=15};2 16(a){4(3!=a){3=a;E(a)}7 r};c.k=2(a){12();c.k=16;7 c.k(a)};c.K("n",2(a){e(a)})}}y.J=17 l.x("n");7 17 y()})();',62,108,'||function|_currentHash|if||var|return||this||||||||_listeners||document|addHistory|unFocus|length|historyChange|_form|notifyListeners|body|true|history|for|_intervalID|_historyStates|_recentlyAdded|EventManager|Keeper|_pollInterval|setInterval|navigator|_historyFrameRef|setAttribute|_createHistoryHTML|html|_updateFromHistory|window|arguments|prototype|addEventListener|History|location|hash|_watchHash|navigationMode|WebKit|appVersion|match|false|_createSafariSetHashForm|createElement|id|insertBefore|firstChild|addHistorySafari|_watchHistoryLength|documentMode|_createHistoryFrame|style|head|updateFromHistory|addHistoryIE|new|push|removeEventListener|splice|200|substring|getCurrent|compatible|test|420|form|unFocusHistoryForm|method|get|action|submit|clearInterval|else|cc_on|userAgent|MSIE|unFocusHistoryFrame|iframe|name|src|javascript|position|absolute|top|900px|frames|with|open|text|write|onl|oad|parent|close'.split('|'),0,{}))

hs.graphicsDir = '/highslide/graphics/';
hs.align = 'center';

hs.outlineType = null;
hs.fadeInOut = true;
hs.dimmingOpacity = 0.75;
hs.dimmingDuration = 50;
hs.showCredits= false;
 hs.transitions = ["fade"];
hs.outlineWhileAnimating = true;




function flv_DoFSCommand(command, args) { 	
	if (command=='go') {go(args);}	

}

function go(n) {
location.href = $('#menu a').eq(n).attr('href');
}

$(function(){

$hl = $('#hl');


$cur = $('a.current'); off = $cur.offset();
$hl.css({'left': off.left-(($.browser.msie) ? 120 : 20), 'width': $($cur).parent().width()}).show();




if ($.browser.msie) {

	$('.mnu td a').hover(
		function(){
		off = $(this).offset();
		$hl.css({'left': off.left-120, 'width': $(this).parent().width()}).show()},
		function(){ $hl.hide()}
	);
} else {

	$('.mnu td').hover(
		function(){
		off = $(this).offset();
		$hl.clearQueue().css({ 'left': off.left-20, 'width': $(this).width()}).fadeTo(300, 1)},
		function(){ $hl.fadeTo(100, 0)}

	);
}

if ($.browser.version!='6.0') {
	$('<img class="za tr" src="/i/z_tr.png" alt="" /><img class="za tl" src="/i/z_tl.png" alt="" /><img class="za br" src="/i/z_br.png" alt="" /><img class="za bl" src="/i/z_bl.png" alt="" /><img class="za l" src="/i/z_l.png" alt="" /><img class="za r" src="/i/z_r.png" alt="" /><img class="za br" src="/i/z_br.png" alt="" />').prependTo('.bigFrame');
}
	function imageresize() {
			var contentwidth = $('body').width();
			if ((contentwidth) < '1100'){
			    $('body').addClass('piccolo');
			} else {
			    $('body').removeClass('piccolo');
			}
		}
	
		imageresize();	
	
		$(window).bind("resize", function(){
			imageresize();
		});



});

function setupNewLinks(obj)  {

	$("img[rel]").overlay({expose: {  color: '#000', loadSpeed: 200, opacity: 0.5 , top: '5%' }}); // грамоты
	
  var links = $('a.ajax', obj); // все ссылки внутри объекта obj  

  for (i = 0; i < links.length; i ++)    {        
    tmp = links[i].href.replace("http://"+site, ""); 
	$(links[i]).bind("click", function() {
	//	markLinksWithHref(this.href);
		historyVar.getNewHistoryState(this.href.replace("http://"+site+"#", ""));
		this.className = "curPage";
	});      
	links[i].href = "#" + tmp;
  }
}

function checkAnchorOnload()  {
  var urlPathName = location.pathname; // console.log("urlPathName: "+urlPathName)
  var urlAnchor = location.hash;  // console.log("urlAnchor: "+urlAnchor)
  if (start)    {  
		if(urlPathName != root) { // если не главная > перенаправление на главную
			
			location.href = "http://"+site+root+"#"+urlPathName;		
		} else if(urlAnchor != "" && urlAnchor.indexOf("#/") != -1) {      	  
			getDataAjax(urlAnchor.replace("#", ""));   
		}	  
  } else if(!start) {	
		if(urlPathName == root) { //console.log("urlPathName == root ")		
			  if (urlAnchor == "" || (urlAnchor == "#" && navigator.appName == 'Microsoft Internet Explorer')) {
					getDataAjax("http://"+site+"/");
			  } else if (urlAnchor.indexOf("#/") != -1) {
					getDataAjax(urlAnchor.replace("#/", ""));
			  }		  
		}
  }	
}

function getDataAjax (adr) { //console.log("getDataAjax: "+adr) 	

	$('#bufer').load(adr+'?ajax=1', function (data) {
	//	document.title = $('#bufer #pagetitle').text();
		if ($.browser.msie) {

			$('#contentwrapper').html();
			$('body').removeClass();
			$('body').addClass($('#bufer #section').text());
			$('#contentwrapper').html($('#bufer #cont').html())
			setupNewLinks($('#contentwrapper'));
			
		} else {

			$('#contentwrapper').fadeOut(100, function(){
				$('body').removeClass();
				$('body').addClass($('#bufer #section').text());
				$(this).html($('#bufer #cont').html()).fadeIn(200); 
				setupNewLinks($('#contentwrapper'));
			});

		}
		
		  
	});	
}
  
function historyHandler() {
  var stateVar = "nothin'", displayDiv = document.getElementById("content");
  
  this.getNewHistoryState = function(currentState) {
    var newVal = currentState;
    unFocus.History.addHistory(newVal);
  };  
  this.historyListener = function(historyHash) {
    stateVar = historyHash;    
    checkAnchorOnload();
  };
  unFocus.History.addEventListener('historyChange', this.historyListener);  
  this.historyListener(unFocus.History.getCurrent());
};
