﻿var MainNews={
Headline:new Array(),
Summary:new Array(),
ImgPath:new Array(),
ImgComment:new Array(),
UrlPath:new Array(),
LastUpdate:new Array(),
Index:new Number(0),
ObjHeadline:new String('HeadMainNews'),
Objsummary:new String('SumarryMainNews'),
ObjImg:new String('ImgMainNews'),
ObjImgComm:new String('ImgCommMainNews'),
ObjUrl:new String('UrlMainNews'),
ObjUpdate:new String('UpdateMainNews'),
ImgLoader:new String('LoaderMainNews'),
IsAuto:new Number(1),
TimerObj:new Object(),
ObjImgAuto:new String('ImgAuto'),
AutoTitle:new String('تشغيل'),
UnautoTitle:new String('إيقاف')

,Show:function()
{ 
    
   document.getElementById(this.ObjHeadline).innerHTML=this.Headline[this.Index];
   document.getElementById(this.Objsummary).innerHTML=this.Summary[this.Index].replace(/\n/g, "<br>");
   hs(this.ObjImg,'none',0);
   hs(this.ImgLoader,'block',0); 
   document.getElementById(this.ObjImg).src=this.ImgPath[this.Index];
   document.getElementById(this.ObjImg).onload=function(){hs(MainNews.ObjImg,'block',0);hs(MainNews.ImgLoader,'none',0);};
   document.getElementById(this.ObjImgComm).innerHTML=this.ImgComment[this.Index];
   document.getElementById(this.ObjUrl).href=this.UrlPath[this.Index];
   document.getElementById(this.ObjUpdate).innerHTML='أخر تحديث :'+this.LastUpdate[this.Index];
   
   //opacity('ImgMainNews', 0, 100, 2000);
   fade('ImgMainNews')
   
    
									   
    if (this.IsAuto)
    {
        this.TimerObj=window.setTimeout("MainNews.Next()",10000);
        //TimerObj1=setTimeout("opacity('ImgMainNews', 100, 99, 1000)",8000);
    }
}


,Next:function()
{


   window.clearTimeout(this.TimerObj);
   window.clearTimeout(TimerObj1);
   this.Index++;
   if (this.Index>=this.Headline.length)
   this.Index=0;
   this.Show();
   try
  {
  //Run some code here
  
   if (this.Index == 0)
   {
        var e1 = document.getElementById('a1');
        e1.className = "bullet_sel";
        e1.style.color = '#99FF00';
        e1.style.fontSize = '11.5pt';
        
        var e11 = document.getElementById('a5');
        e11.className = "bullet";
        e11.style.color = '#DDDDDD';
        e11.style.fontSize = '14px';
   }
   else
   {
        var e1 = document.getElementById('a' + (this.Index + 1));
        e1.className = "bullet_sel"
        e1.style.color = '#99FF00';
        e1.style.fontSize = '11.5pt';
        
   
        var e11 = document.getElementById('a' + (this.Index));
        e11.className = "bullet";
        e11.style.color = '#DDDDDD';
        e11.style.fontSize = '14px';
   }
 
 }
catch(err)
  {
  //Handle errors here
  }  
}


,Prev:function()
{
   window.clearTimeout(this.TimerObj);
   window.clearTimeout(TimerObj1);
   this.Index--;
   if (this.Index<0)
   this.Index=0;
   this.Show();
   
   try
   {
   if (this.Index == 0)
   {
        var e1 = document.getElementById('a1');
        e1.className = "bullet_sel";
        e1.style.color = '#99FF00';
        e1.style.fontSize = '11.5pt';
        
        var e11 = document.getElementById('a2');
        e11.className = "bullet";
        e11.style.color = '#DDDDDD';
        e11.style.fontSize = '14px';
   }
   else
   {
        var e1 = document.getElementById('a' + (this.Index + 1 ));
        e1.className = "bullet_sel"
        e1.style.color = '#99FF00';
        e1.style.fontSize = '11.5pt';
    
        var e11 = document.getElementById('a' + (this.Index + 2));
        e11.className = "bullet";
        e11.style.color = '#DDDDDD';
        e11.style.fontSize = '14px';
   }
   }
catch(err)
  {
  //Handle errors here
  }

}
,AutoStatus:function()
{
  if (this.IsAuto)
  {
    window.clearTimeout(this.TimerObj);
    window.clearTimeout(TimerObj1);
    this.IsAuto=0;
    document.getElementById(this.ObjImgAuto).src='../App_Themes/site/images/buttons/greenbutton-pause-idle.gif';
    document.getElementById(this.ObjImgAuto).title=this.AutoTitle;
  }
  else
  {
  
    this.IsAuto=1;
    document.getElementById(this.ObjImgAuto).src='../App_Themes/site/images/buttons/greenbutton-pause-over.gif';
    document.getElementById(this.ObjImgAuto).title=this.UnautoTitle;
  
  }

}

   

,Selected:function(ind)
{
   window.clearTimeout(this.TimerObj);
   window.clearTimeout(TimerObj1);
   this.Index = ind;
   this.Show();
   
   try
   {
   
   
   for (i = 1; i <= 5; i++)
    {
        var e11 = document.getElementById('a' + (i));
        e11.className = "bullet";
        e11.style.color = '#DDDDDD';
        e11.style.fontSize = '14px';
    }
    
   var e1 = document.getElementById('a' + (this.Index + 1 ));
   e1.className = "bullet_sel"
   e1.style.color = '#99FF00';
   e1.style.fontSize = '11.5pt';
}
catch(err)
  {
  //Handle errors here
  }
}

,overpause:function ()
{
  if (this.IsAuto)
  {
    
    document.getElementById(this.ObjImgAuto).src='../App_Themes/site/images/buttons/greenbutton-pause-idle.gif';
    
  }
  else
  {
    document.getElementById(this.ObjImgAuto).src='../App_Themes/site/images/buttons/greenbutton-pause-over.gif';
   }

}

}




var TimerObj1=new Object();
var TimerObjOpac = new Object();
var execu = new Object();


function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    
    execu = false;
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 

        for(i = opacStart; i > opacEnd; i--){
            TimerObjOpac = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 

    } else if(opacStart < opacEnd) { 

        for(i = opacStart; i <= opacEnd; i++) 
            { 
            
            TimerObjOpac = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 

    } 
    execu = true;
} 

//change the opacity for different browsers 
function changeOpac(opacity, id){ 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}





var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
//  if(element.FadeState == null)
//  {
//    if(element.style.opacity == null
//        || element.style.opacity == ''
//        || element.style.opacity == '1')
//    {
//      element.FadeState = 2;
//    }
//    else
//    {
//      element.FadeState = -2;
//    }
//  }

    element.FadeState = element.FadeState == 1 ? 1 : -1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);

}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
        if (element.FadeState != 1)
            element.FadeState = -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
