﻿// layout.js
//
root = '';
var nav = [    ['主页', root+'/default.aspx',
                []
            ],
            ['活动看板', root+'/activities/2012_CNYGreetings.aspx',
                [   // ['各道场活动表', root+'/activities/timeTable.htm'],
                     ['新年祝贺', root+'/activities/2012_CNYGreetings.aspx'],
//                     ['供僧法会', root+'/activities/gongSeng.aspx'],
//                     ['药师法会', root+'/activities/QiYuan.aspx'],
//                     ['卫塞节', root+'/activities/WesakDay.aspx']
//                     ['2011 新年贺词', root+'/activities/2011_newYearGreeting.html']    
//                    ['法炬山快讯', root+'/activities/dlmXpress.htm'],
//                    ['人间小菩萨欢乐营', root+'/activities/HLY.htm'],
//                    ['展翅高飞挑战营', root+'/activities/TZY.htm'],
//                    ['佛大培训学院', root+'/activities/FDPX.htm'],
//                    ['长者自在', root+'/activities/CQY.htm']
                ]
            ],
//            ['法会', root+'/fahui/yaoshi.htm',
//                [    ['药师消灾免难法会', root+'/fahui/yaoshi.htm'],
//                    ['观音平安吉祥法会', root+'/fahui/guanyin.htm']
//                ]
//            ],
            ['慈悲活动', root+'/ceremony/ten.aspx',
                [    //['<b>新春活动</b>',root+'/ceremony/cny.htm'],
                    ['10元献爱心', root+'/ceremony/ten.aspx'],
                    ['爱心奉献', root+'/ceremony/pu_man.aspx'],
                    ['一花一世界', root+'/ceremony/yihua_main.aspx'],
                    ['跑出心中的彩虹', root+'/ceremony/yipao.aspx']
                ]
            ],
            ['网上佛学', root+'/about_us/BDV_foda_collection.htm',
                [   ['佛大系列丛书', '/about_us/BDV_foda_collection.htm'],
//                    ['人间小菩萨画报', root+'/e_learning/XPS.htm'],
                    ['小佛钟', root+'/about_us/BDV_child.htm'],
                    ['人间佛教杂志丛书', root+'/about_us/BDV_mag.htm'],
                    ['慧海法师弘法讲座系列', root+'/about_us/BDV_Disc.htm']
                ]
            ],
            ['关于我们', root+'/about_us/dlm.aspx',
                [    ['法炬山', root+'/about_us/dlm.aspx'],
                    ['开山宗长', root+'/about_us/revHH.aspx'],
                    ['监院', root+'/about_us/revMB.aspx'],
                    ['道场', root+'/about_us/vihara.aspx'],
                    ['大马佛教大学', root+'/about_us/DBU.aspx'],
                    ['人间佛教协会', root+'/about_us/MMBA.aspx'],
                    ['人间慈悲基金会', 'http://www.humanistik.org.my'],
                    ['法来菩提中心', root+'/about_us/BDV_child.htm'],
                    ['我是地球慈悲人', 'http://www.humanistik.org.my/huanbao_add.html']
                ]
            ]
    ];
var today = new Date();
var ltoday = new Lunar(today);
var sect, chap;

function cyclical(num) {
   return(Gan[num%10]+Zhi[num%12])
}

function getMap(){
    return(nav);
}

function displayDate(){
    document.write('&#35199;&#20803; ' + today.getFullYear() + '&#24180;' + (today.getMonth()+1) + '&#26376;' +today.getDate() + '&#26085; &#26143;&#26399;' + cDay[today.getDay()]);
    document.write('&nbsp;&nbsp;&#8226;&nbsp;&nbsp;');
    document.write('&#20892;&#21382; ' +cyclical(ltoday.yearCyl)+ '&#24180;' +ltoday.month + '&#26376;' +Math.floor(ltoday.day)+ '&#26085;');
    document.write('&nbsp;&nbsp;&#8226;&nbsp;&nbsp;');
    document.write('&#20315;&#21382; ' + ltoday.byear + '&#24180;');
}

function drawHeader()
{
    document.write('<table width="100%" border="0" background="/img/seascape-1.jpg"' +
                   'style="background-position:top right; background-repeat:no-repeat">');
    
    // row1: date
    document.write('<tr><td colspan="3" align="right" style="font-size: 12px;">');
    displayDate(this.location.href);
    document.write('</td></tr>');
    
	// row2: logo and name
    document.write('<tr>');
    document.write('<td rowspan="2" class="center" width="100"><img src="/img/DLMlogo.gif" width="88" /></td>');
    document.write('');
    document.write('<td class="center" width="400"><img src="/img/dharma_light_word.gif" /></td>');
    document.write('<td></td>');
    document.write('</tr>');
	
	// row3: logo (from previous row) and tema
    document.write('<tr>')
    document.write('<td class="center" style="font-size: 12px; letter-spacing: 2px; font-weight: 900 ">');
	document.write('人间的灵山');
	document.write('<img src="/img/wan.gif" hspace="5" width="18" height="18" align="absbottom" />');
	document.write('佛教的法海');
	document.write('</td>');
    document.write('<td></td>');
    document.write('</tr>');
    document.write('</table>');
}

// a sample of header
// [logo] 法炬山                           西元 20xx年xx月xx日 星期X  •  农历 XX年xx月xx日  •  佛历 25xx年
// -------------------------------------------------------------------------------------------------------------
function drawSmallHeader(){
    
    // Table: Header
    document.write('<table width="100%" class="header" cellspacing="0">');
    document.write('<tr><td width="30%">');
    
    // logo & name
    document.write('<img src="' +root+ '/img/DLMlogo.gif" height=35>');
    document.write('<img src="' +root+ '/img/dharma_light_word.gif" height=35>');
    document.write('</td>');

    // date
    document.write('<td class="date">');
    displayDate();
    document.write('</td></tr></table>');
}

function extract(URL){
    var x = URL;
    if(x.indexOf('/XPS/XPS') > 0)
        URL = root+'/e_learning/XPS.htm';
    for(var a=0; a<nav.length; a++)
        for(var b=0; b<nav[a][2].length; b++)
            if(this.location.pathname==nav[a][2][b][1]){
                sect = a;
                chap = b;
                if(x.indexOf('/XPS/XPS')>0)
                    chap = -1;
                return;
            }
    
}

function drawGlobalNav(){
    document.write('<div class="GlobalNav">');
    document.write('<div class="mainMenu" style="z-index:99">');
    document.write('<ul>');
    
    for (var i=0; i<nav.length; i++)
    {
        document.write('<li><a class="mainMenu' + i +'" href="' + nav[i][1] + '">' + nav[i][0] +'</A>');
        
        /*/ Sub menus
        document.write('<table id=subMenu' + i + '><tbody><tr><td>');
        
        if (i == nav.length-1)
            document.write('<ul class=endstop>');
        else
            document.write('<ul>');
        
        for (var j=0; j<nav[i][2].length; j++)
        {
            document.write('<li><a href="' + nav[i][2][j][1] + '">' + nav[i][2][j][0] +'</a></li>');
        }
        document.write('</ul></td></tr></tbody></table>');
        // end sub menus*/
        
        //document.write('<!--[if lte IE 6]></a><![endif]--></li>');
		document.write('</li>');
    }
    
    document.write('</ul></div></div>');
}
function drawSidebar(URL){

    // for XPS
    extract(URL);

    // Global navigation menu
    drawGlobalNav();

    // Sub-menus
    document.write('<table width="100%" class="sidebar" cellspacing="0"><tr><td>');
    for(var j=0; j<nav[sect][2].length; j++)
    {
        if(j!=0)    // add separator between every chapter
            document.write('&nbsp;&nbsp;&#8226;&nbsp;&nbsp;');
        if(j==chap)    // highlight current selected chapter
            document.write('<strong class="selected">' +nav[sect][2][j][0]+ '</strong>');
        else        // add corresponding linkage to other chapter
            document.write('<a href="' +nav[sect][2][j][1]+ '">' +nav[sect][2][j][0]+ '</a>');
    }
    document.write('</td></tr></table>');
}

/* Draw page footer
 * 
 * Script to draw a standard footer for all pages. CSS controlled via "footer"
 * and "legal" class.
 *
 * Below is how current footer would looks like:
 *
 *                                       主页  •  活动看板  •  网上佛学  •  关于我们
 *                           尊重智慧产权 转载请徵同意 ©20xx 马来西亚法炬山 e-mail us 
 */
function drawFooter(URL){
    
    document.write('<table class="footer" cellpadding="0" width="100%">');
    
    // Print properties declaration, follow by email-us
    document.write('<tr><td>');
    document.write('<var class="legal">尊重智慧产权 转载请徵同意 &copy;'
        +today.getFullYear()+ ' 马来西亚法炬山</var> <a href="mailto:info@dlm.org.my">e-mail us</a>');
    document.write('</td></tr>');
    document.write('</table>');
}

//
// Function: Image Slide Show
//
// BODY Example:
// <body onLoad="mySlideShow1.play(); mySlideShow2.play();">
// <img src="originalImage1.gif" name="slide1">
// <img src="originalImage2.gif" name="slide2">
//
// SCRIPT Example:
// var mySlideList1 = ['image1.gif', 'image2.gif', 'image3.gif'];
// var mySlideShow1 = new SlideShow(mySlideList1, 'slide1', 3000, "mySlideShow1");
// var mySlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];
// var mySlideShow2 = new SlideShow(mySlideList2, 'slide2', 1000, "mySlideShow2");
//
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}
function SlideShow(slideList, image, speed, name)
{
  this.slideList = slideList;
  this.image = image;
  this.speed = speed;
  this.name = name;
  this.current = 0;
  this.timer = 0;
}
SlideShow.prototype.play = SlideShow_play;  
function SlideShow_play()
{
  with(this)
  {
    if(current++ == slideList.length-1) current = 0;
    switchImage(image, slideList[current]);
    clearTimeout(timer);
    timer = setTimeout(name+'.play()', speed);
  }
}

