var CurrentUpcomingEvent = -1;
var CurrentNews = -1;
var CurrentPartner = -1;
var NewsRoll = true;
var NewsRollTimeout;
var VIDEOTITLEHEIGHTS = new Array();

$(document).ready(function() {

  News_Roll();
  Partners_Roll();

  for (var i=0; i<TotalVideos; i++)
     {
      VIDEOTITLEHEIGHTS[i] = $("#VIDEOTITLECELL_"+i).height();
      $("#VIDEOTITLECELL_"+i).css('height','35px');
     }

});

function UpdateIncomingEvents()
  {
   if (UPCOMINGEVENTSDATA.length==0) { return; }
   
   CurrentUpcomingEvent++;
   if (CurrentUpcomingEvent>=UPCOMINGEVENTSDATA.length) { CurrentUpcomingEvent = 0; }
   
   var ViewURL = UPCOMINGEVENTSDATA[CurrentUpcomingEvent][1];
   
   var HTMLDATA = '';
   HTMLDATA += '<table cellspacing="0" cellpadding="0" border="0">';
   HTMLDATA += '<tr>';
   HTMLDATA += '<td width="72"><div style="padding-top:1px"><a class="smalltxtA2 i_upcoming02" style="color:#003399" href="'+ViewURL+'"><b>'+UPCOMINGEVENTSDATA[CurrentUpcomingEvent][0]+' г.</b></a></div></td>';
   HTMLDATA += '<td><div style="padding-left:8px"><a class="bigtxtA1 i_upcoming02" href="'+ViewURL+'">'+UPCOMINGEVENTSDATA[CurrentUpcomingEvent][2]+'</a></div></td>';
   HTMLDATA += '</tr>';
   HTMLDATA += '</table>';
   
   if (navigator.userAgent.indexOf("MSIE")!=-1) { $("#UPCOMINGEVENTS_HEADLINE").empty().append(HTMLDATA).show(); }
   else
     {
      $("#UPCOMINGEVENTS_HEADLINE").fadeTo(800, 0.05, function() {
   
        $("#UPCOMINGEVENTS_HEADLINE").empty().append(HTMLDATA).fadeTo(300, 1.0);
   
      });
     }
   
   setTimeout("UpdateIncomingEvents()",9000)
  }
  
function News_SwitchTo(id,ContinueRoll)
  {
   var ItemHeight = 0;
   var MaxHeight = 0;
   
   for (var i=0; i<NEWSDATA.length; i++)
      {
       ItemHeight = $("#NEWSITEM_"+NEWSDATA[i][0]).height();
       if (ItemHeight>MaxHeight) { MaxHeight = ItemHeight; }

       if (NEWSDATA[i][0]!=id)
         {
          $("#NEWSITEM_"+NEWSDATA[i][0]).hide();
          $("#NEWSLINK_"+NEWSDATA[i][0]).css('margin-top','-12px');
         }
      }
      
   $("#NEWSITEM_"+id).show();
   $("#NEWSLINK_"+id).css('margin-top','0px');
   
   if (MaxHeight>0)
     {
      $("#NEWSCONTAINER").css('height',(MaxHeight+10)+'px');
      for (var i=0; i<NEWSDATA.length; i++) { $("#NEWSITEM_"+NEWSDATA[i][0]).css('height',MaxHeight+'px'); }
     }
   
   if (!ContinueRoll) { clearTimeout(NewsRollTimeout); NewsRoll = false; $("#NEWS_BALLOON").hide(); }
  }
  
function News_Roll()
  {
   if (NEWSDATA.length==0) { return; }
   
   CurrentNews++;
   if (CurrentNews>=NEWSDATA.length) { CurrentNews = 0; }
   
   News_SwitchTo(NEWSDATA[CurrentNews][0],true);
   
   if (NewsRoll) { NewsRollTimeout = setTimeout("News_Roll()",9000); }
  }
  
function News_SwitchOver(obj,id,index)
  {
   $(obj).css('cursor','pointer');
   $("#NEWSLINKDIV_"+index).css('visibility','visible');
   if (index>0) { $("#NEWSLINKDIV_"+(index-1)).css('visibility','visible'); }
   
   var NewsLinkPos = $("#NEWSLINK_"+id).position();
   
   $("#NEWS_BALLOONTEXT").empty().append(NEWSDATA[index][2]);
   $("#NEWS_BALLOON").show().css('top','-19px').css('left',(NewsLinkPos.left-27)+'px');

   var NewsBallonHeight = $("#NEWS_BALLOON").height();
   if (NewsBallonHeight>0) { $("#NEWS_BALLOON").css('top',(-2-NewsBallonHeight)+'px'); }
  }
  
function News_SwitchOut(obj,id,index)
  {
   $(obj).css('cursor','');
   $("#NEWSLINKDIV_"+index).css('visibility','hidden');
   if (index>0) { $("#NEWSLINKDIV_"+(index-1)).css('visibility','hidden'); }
   
   $("#NEWS_BALLOON").hide();
  }
  
function VideoOver(obj,id)
  { 
   $(obj).css('background-position','0px -300px').css('cursor','pointer');
   $("#VIDEOTITLECELL_"+id).stop().animate({ height:VIDEOTITLEHEIGHTS[id]+'px' },200);
  }

function VideoOut(obj,id)
  { 
   $(obj).css('background-position','0px 0px').css('cursor','');
   $("#VIDEOTITLECELL_"+id).stop().animate({ height:'35px' },300);
  }
  
function SidebarBannerOver(obj,id,offset)
  {
   $(obj).css('cursor','pointer');
   $("#"+id).css('margin-top',offset+'px');
  }
  
function SidebarBannerOut(obj,id,offset)
  {
   $(obj).css('cursor','');
   $("#"+id).css('margin-top',offset+'px');
  }
  
function Partners_Roll()
  {
   if (PARTNERSDATA.length==0) { return; }
   
   if (CurrentPartner==-1) { Partners_Update(); }
   else
     {
      $("#PARTNERS_"+CurrentPartner).fadeTo(400, 0, function() { $("#PARTNERS_"+CurrentPartner).hide(); Partners_Update(); });
     }
  }

function Partners_Update()
  {
   CurrentPartner++;
   if (CurrentPartner>=PARTNERSDATA.length) { CurrentPartner = 0; }

   if (!PARTNERSDATA[CurrentPartner][0])
     {
      HTMLDATA = '<a target="_blank" href="'+PARTNERSDATA[CurrentPartner][2]+'"><img src="'+PARTNERSDATA[CurrentPartner][3]+'" border="0" title="'+PARTNERSDATA[CurrentPartner][1]+'"></a>';
      $("#PARTNERS_"+CurrentPartner).append(HTMLDATA);
      PARTNERSDATA[CurrentPartner][0] = true;
     }
     
   $("#PARTNERS_"+CurrentPartner).fadeTo(400, 1, function() {
     
     ContainerHeight = $("#PARTNERS_"+CurrentPartner).height();
     if (ContainerHeight==0) { ContainerHeight = 120; }
     $("#PARTNERS_CONTAINER").css('height',ContainerHeight+'px');

     setTimeout("Partners_Roll()",9000);
     
   });
  }
  
function ExpandArticles(id)
  {
   $("#"+id+"_MoreArticles").slideDown("medium");
   $("#"+id+"_MoreButton").slideDown("medium");
   $("#"+id+"_ExpandButton").slideUp("fast");
  }
