var timeoutchange = 1;

function changeflash_with_timeout(root,now) {

  if (timeoutchange)
    changeflash(root,now);
}

function getMovie() {
        var M$ =  navigator.appName.indexOf("Microsoft")!=-1
        return (M$ ? window : document)["menuflash"]
}

function changeflash(root,now) {
/*MY*/
	/*if (root == 'kupit-nedvizhimost') root = 'buy';
	switch (now) {
		case 'zemelnie-uchastki-v-podmoskovje':now = 'outofcity';break;
		case 'novostroyki-v-moskve':now = 'newflats';break;
		case 'kvartiri-i-garazhi':now = 'flats';break;
		case 'nejilie-pomesheniya-v-moskve':now = 'comm';break;
	}*/
	/*root = root.replace(/-/g,'_');
	now = now.replace(/-/g,'_');*/
	//alert(root+'/'+now);
/*MY*/
       var movie = getMovie();
       movie.SetVariable("rvoot", root);
       movie.SetVariable("now", now);
}

  function dosearch() {

    word = document.getElementById('findobj').value;

    if (word)
    {
      word = escape(word);
      getcenter('search', '', '', 'word='+word);
      document.getElementById('findobj').value = '';
    }

  }

function getcenter(root,now,more,postfix) {
/*MY*/
	link = '/';
	if (root && root != 'home') { link += root;
		if (now) link += '/'+now;
		if (more) link += '/'+more;
		if (postfix) link += '/?'+postfix;
	}
	//window.open(link,'_self');
	document.location.href = link;
	return;
/*MY*/
  timeoutchange = 0;

  changeflash(root,now);


  document.getElementById('bdy').style.cursor="wait";

  if (root && root != 'home')
    ind = 0;
  else
    ind = 1;

/***********************/
  if (!ind)
  {
    urrl = 'root='+root;
    if (now)
      urrl += '&noww='+now;

    var tnum = $.ajax({
    url: '/gettheme.php?'+urrl,
    async: false
   }).responseText;

    link = '/'+root;
    if (now)
      link += '/'+now;
    if (more)
      link += '/'+more;

    if (postfix)
    {
      tmptmp = link+"/?ajax=1&"+postfix;
      printlink = link+"/?prn=yes&"+postfix;
    }
    else
    {
      tmptmp = link+'/?ajax=1';
      printlink = link+'/?prn=yes';
    }
  }
  else
  {
    tmptmp = '/?ajax=1';
    tnum = 0;
  }

  for (i = 0; i <= 5; i++)
  {
    if ( $('#main_theme_'+i).length)
    {
      document.getElementById('main_theme_'+i).id = 'main_theme_'+tnum;
      document.getElementById('bottom_theme_'+i).id = 'bottom_theme_'+tnum;
    }
  }

/***********************/
    var tmptmp = $.ajax({
    url: tmptmp,
    async: false
   }).responseText;

    document.getElementById('tochange').innerHTML = tmptmp;

  if (!ind)
  {
    var tmptmp = $.ajax({
    url: "/submenu.php?"+urrl,
    async: false
   }).responseText;

    document.getElementById('submenu').innerHTML = tmptmp;
  }


/**********************/
//  if (!ind)
//  {
  $(".lightbox").lightbox({fitToScreen: true});
//  }

  if (!ind)
    showme = 'block';
  else
    showme = 'none';

  document.getElementById('print').style.display = showme;

  if (!ind)
  {
    document.getElementById('print').innerHTML = '<a href="'+printlink+'" target="_blank"><img src="/i/ico5.gif" alt="Распечатать" /></a> <a target="_blank" href="'+printlink+'">версия для печати</a>';
  }

  document.getElementById('submenu').style.display = showme;

  document.getElementById('bdy').style.cursor="auto";

}
