﻿
var idnew,idprv; // stores Ids of div to be slide
var Anew,Aprv;   // stores Ids of span buttons ie. Next & Prev
var idTemp,id;   // stores temporory id of currently displaying div
var i=1,tabIndex; // index of currently active tab
var VisNow = new Array(4);  // Array that stores no. of currently displaying div
var k=1,flg=0,t=10000;

/*------------ This function exicutes onlaod & initialise all values. --------------------------------
-------------- It hides all divs but leave the one. ---------------------------------------------------*/
function hideme()
{
    //document.getElementById('Div1').style.background="#110808";
  
    idprv='tabD1';
    Aprv='Div12';
    document.getElementById(Aprv).style.background="#d12828";
    idTemp=idprv;
    tabIndex=1;
    VisNow[1]=1;
    VisNow[2]=1;
    VisNow[3]=1;
    VisNow[4]=1;
    EnabDesabPrv();
    EnabDesabNxt();
    changeTab();
}

//--------------------------- This method Changes virtical tab selection ------------------------------
function changeTab()
{
    if(k>4)
        k=1;
    idnew='tabD'+k;
    Anew='Div'+k+'2';
    openTab(idnew,Anew,0);
    k=parseInt(k)+1;
    setTimeout("changeTab()",parseInt(t)); //call function "slideit()" every 5 seconds
}

//--------------------------- This method visible the div corrosponding to active tab --------------------
function openTab(idnew,Anew,flg)
{
    document.getElementById(idprv).style.display="none";
    document.getElementById(Aprv).style.background="#110808";
    document.getElementById(Anew).style.background="#d12828";
    document.getElementById(idnew).style.display="";
    //document.getElementById(Anew).style.border="none";
    idprv=idnew;
    Aprv=Anew;
    idTemp=idnew;
    tabIndex=idnew.substring(4);
    i=VisNow[tabIndex];
    k=tabIndex;
    EnabDesabPrv();
    EnabDesabNxt();
    if(flg==1)
        t=10000;
    else
        t=8000;
}


if (window.addEventListener)
window.addEventListener("load", hideme, false)
else if (window.attachEvent)
window.attachEvent("onload", hideme)

// ---------------- this method deactivate 'Prv' button if there is no previous page availaible for news ------
function EnabDesabPrv()
{
    var j=parseInt(i)-1;
    id=idTemp+j;
    if(document.getElementById(id))
    {
        document.getElementById('spPrv').style.display='';
    }
    else
    {
        document.getElementById('spPrv').style.display='none';
    }
}

// ---------------- this method deactivate 'Nxt' button if there is no Next page availaible for news --------
function EnabDesabNxt()
{
    var j=parseInt(i)+1;
    id=idTemp+j;
    if(document.getElementById(id))
    {
        document.getElementById('spNxt').style.display='';
    }
    else
    {
         document.getElementById('spNxt').style.display='none';
    }
}


//--------------------------- This methods provides effect as next & prev ro currently displaying news ---------
$(document).ready(function(){
    
    $("#spNxt").click(function () 
    {
        var j=parseInt(i)+1;
        id=idTemp+j;
        if(document.getElementById(id))
        {
            id='#'+idTemp+i;
            $(id).fadeOut("slow",function(){
                    i=parseInt(i)+1;
                    id='#'+idTemp+i;
                    $(id).fadeIn("slow");
                    VisNow[tabIndex]=i;
                    EnabDesabPrv();
                    EnabDesabNxt();  
            });
        }
    });
    
    $("#spPrv").click(function () 
    {
        var j=parseInt(i)-1;
        id=idTemp+j;
        if(document.getElementById(id))
        {
            id='#'+idTemp+i;
            $(id).fadeOut("slow",function(){
                i=parseInt(i)-1;
                id='#'+idTemp+i;
                $(id).fadeIn("slow"); 
                VisNow[tabIndex]=i;
                EnabDesabPrv();
                EnabDesabNxt();    
            });
        }
    });            
});