var current_submenu=default_submenu=2;
var open_flash_menu=0;
var timeoutID;

jQuery.preloadImages = function() {
   jQuery.each (arguments,function (e) {
       jQuery("<img>").attr("src", this);
   });
}

$(document).ready(
  function() {
    ShowSubMenu(default_submenu);

//    $(document).pngFix();  

    $(".cornerTop").prepend('<div class="cornerLeftTop"></div><div class="cornerRightTop"></div>');
    $(".cornerBottom").prepend('<div class="cornerLeftBottom"></div><div class="cornerRightBottom"></div>');

    thumbPhotoEvents();

    $("div#linkblock a").click(function () {
      $("div#linkblock a").removeClass('active');
      $(this).addClass('active');
      href=$(this).attr('href');
      $("#ajax").html('<h2>Loading...</h2><center><img src="../images/loader.gif" vspace="30" alt="Loading"/></center>').load(href,'',function() {$("#contentblock table").addClass('beauty').find("tr:odd").addClass('odd');$("table.beauty tr:first").addClass('head');});
      return false;
    });

    $("#contentblock table").addClass('beauty').find("tr:odd").addClass('odd');$("table.beauty tr:first").addClass('head');
}
);

function ShowSubMenu(id,timer) {
  if (!timer) {setTimeout('ShowSubMenu('+id+',1)',500);return;}
  $("#mainnavigation a").removeClass('hover');
  $("#mainnavigation .topmenu"+id).addClass('hover');
  $("div#subnavigation .item").not(".submenu"+id).hide()  
  $("div#subnavigation .submenu"+id).show();
  current_submenu=id;
}

function HideSubMenu() {
  if (default_submenu != current_submenu) ShowSubMenu(default_submenu); 
}
 

/* Photo album */

var thumbPhoto_count;
var thumbPhoto_current;

function thumbPhotoEvents() {
  thumbPhoto_count = $("a.thumbPhoto").length;
  thumbPhoto_current=0;
  if (thumbPhoto_count) {
    $("div.after_head_line").prepend('<div class="photoalbum_control"><img src="../images/arrow_l_white.gif" onClick="thumbPhotoPrev();" alt="prev"/> <span>1</span> из '+thumbPhoto_count+' <img src="../images/arrow_r_white.gif" onClick="thumbPhotoNext();" alt="next"/></div>');
    $("div.photoalbum").addClass('with_right').find("a.thumbPhoto").each(function(i,val) {
	if (i%4==3) $(val).addClass('right');
	$(val).attr('num',i+1);
    }); 
    thumbPhotoShow(1);
    $("a.thumbPhoto").click(function () {
      thumbPhotoShow($(this).attr('num'));
      return false;
    });
  }

}

function thumbPhotoShow(num) {
  el=$("a.thumbPhoto").removeClass('active').eq(num-1);
  el.addClass('active');
  src=$(el).attr('href');
  name=$(el).attr('title');
  thumbPhoto_current=num=$(el).attr('num');
  $("img#headImage").attr('src',src);
  $("div.after_head_line span.name").text(name);
  $("div.after_head_line .photoalbum_control span").text(num);
}

function thumbPhotoPrev() {
  thumbPhoto_current--;
  if (thumbPhoto_current<1) thumbPhoto_current=thumbPhoto_count;
  thumbPhotoShow(thumbPhoto_current);
}

function thumbPhotoNext() {
  thumbPhoto_current++;
  if (thumbPhoto_current>thumbPhoto_count) thumbPhoto_current=1;
  thumbPhotoShow(thumbPhoto_current);
}

function ShowFlash(id,el) {
  if (open_flash_menu==id) return;// HideFlash();
  window.clearTimeout(timeoutID);
  $("#mainFlash ul.menu li").removeClass("active");
  $(el).addClass('active');
  if (!open_flash_menu) {
	$("#mainFlash div.block").hide();
	$("#mainFlash div.block"+id).show();
	$("#mainFlash .panel").fadeIn();
	$("#mainFlash .bgimage:visible").fadeTo('','.5');
  } else {
	if ($("#mainFlash .block:visible").length)
	  $("#mainFlash .panel").show().find(".block:visible").fadeOut('fast',function() {$("#mainFlash div.block"+id).fadeIn()});
	else 
	  $("#mainFlash div.block"+id).fadeIn();
  }
  open_flash_menu=id;
  timeoutID = window.setTimeout(HideFlash, 7000);
}

function HideFlash() {
	$("#mainFlash .panel").fadeOut();
	$("#mainFlash .bgimage:visible").fadeTo('','1');
	$("#mainFlash ul.menu li").removeClass("active");
	open_flash_menu=0;
}

function pam () {
	$("#footerspacer").text($("#footerspacer").text()+'.');
}