$(document).ready(Init);

function Init()
{
  ShowTimer();
//  isMainPage();
  addClassPortfolio();
  addClassPortfolioPreview();
}

function ShowTimer()
{
  var d = new Date();
  $("#timer").load('/timer.php');
  setTimeout('ShowTimer()', 60000);

}

function isMainPage()
{
  if(!CurRegion)
  {
    if($(".mainPage").attr('id'))
      ShowMap();
  }
}

function LoadMap()
{
  $.get(
  '/geomap-ajax/','',
  WriteMap
);
  
}

function WriteMap(obj)
{
  $("#map").html(obj).animate({opacity:"show", width:"show", height:"show"}, 300, SetMapProperties).each(function(){this.onclick = function(){DivClick();HideMap()}});
  $("#map > #bigmap").append('<span class="loading">Идет загрузка...</span>');
}


function ShowMap()
{
	window.location = '#top';
  $("select").css('visibility','hidden');
  if(!$("#map").html()){
    LoadMap();
  }
  else{
   $("#map").animate({opacity:"show", width:"show", height:"show"}, 300);
  }
}

function SetMapProperties()
{
  $("#map > #bigmap > a").each(function(){this.onmouseover=function(){$("#td_"+this.className).addClass("active"); SetRegion($("#td_"+this.className).html())};this.onmouseout=function(){$("#td_"+this.className).attr("class","timezone");};}).attr('onclick', 'return false;');
  setTimeout('$("#map> #bigmap > span.loading").remove()', 2000);
}

function HideMap()
{

  $("#map").animate({opacity:"hide", height:"hide"}, 300);  
  $("select").css('visibility','visible');
}

function addClassPortfolio()
{
  $("ul#works > li").each(function(index) {if((index+1) % 3 == 0) $(this).addClass("extreme")});
}
function addClassPortfolioPreview()
{
  $("ul#portfolio_preview_ul > li").each(function(index) {if((index+1) % 3 == 0) $(this).addClass("extreme")});
}
