 /***************************************************************************
 * fplinks.js
 *  Functions to insert the front page links.
 *
 *  The required <body onLoad="..."> call is 'buildLinks();'
 *
 *  Simon Hunt
 *  May 2007
 ***************************************************************************/

/** Stuff to get done when the page loads into the browser */
function buildLinks()
{
    setupLinksArray();  // defined in links.js (auto-generated from links.txt)
    _RenderLinks();     // inserts the HTML into the front page
} // func buildLinks


/** Initialization - done before the body is loaded */
var lesserLinkDivClass =
    {
        S: "fpShowItem",
        N: "fpNewsItem"
    };
var mainLinkWidth = 475;    // image width in pixels
var mainLinkHeight = 150;   // image height in pixels
var imageRoot = "img/bnr/"; // where the banner images and animations are

var lesserTag = "<!--LESSERLINK-->";
var goLinks;

if (goLinks == null) {
    goLinks = new Array();
//    goLinks.mainlink1 = "";
//    goLinks.mainlink2 = "";
    goLinks.lesserlinks = lesserTag;
} // if


//=============================================================================
// Func:    mainLink(sWhich, sImagePath, sDestURL)
// Desc:    Set main link image and URL information
// Args:    sWhich      - identifier ("1", "2", ...)
//          sImagePath  - the 'src' argument to the base <img> tag
//          sDestURL    - the URL to go to if the image is clicked
//                      (optionally include the following args)
//          animgif     -  the 'src' arg to the animated gif
//          dx, dy      -  offset from top left of base image
//          w, h        -  dimensions of the animated gif
// Return:  None
//=============================================================================
function mainLink(sWhich, sImagePath, sDestURL, animGif, dx, dy, w, h,
                                                animGif2, dx2, dy2, w2, h2) {
		var pic = imageRoot + sImagePath;
		if( sImagePath.charAt(0) == '/' ){
			pic = sImagePath;
		}

        var prop = "mainlink" + sWhich;
        var str = '<div class="showBanner">' +
                  '<a href="' + sDestURL + '"><img src="' + pic +
                  '" width=' + mainLinkWidth +
                ' height=' + mainLinkHeight + '></a>';
        if (animGif) {
            var gstr = "<div class=\"animblock\" id=\"anim"+sWhich+"\" style=\"position:absolute;" +
                     "left:"+dx+"px;top:"+dy+"px;width:"+w+"px;height:"+h+"px;" +
                     "z-index:200;visibility:visible;\" "+
                     "onclick=\"javascript:document.location='"+sDestURL+"'\"" +
                     "><img src=\"" + imageRoot +
                     animGif + "\" width=\""+w+"\" height=\""+h+"\"></div>";
            str += gstr;

        } // if
        if (animGif2) {
            var gstr = "<div class=\"animblock\" id=\"anim2"+sWhich+"\" style=\"position:absolute;" +
                     "left:"+dx2+"px;top:"+dy2+"px;width:"+w2+"px;height:"+h2+"px;" +
                     "z-index:200;visibility:visible;\" "+
                     "onclick=\"javascript:document.location='"+sDestURL+"'\"" +
                     "><img src=\"" + imageRoot +
                     animGif2 + "\" width=\""+w2+"\" height=\""+h2+"\"></div>";
            str += gstr;

        } // if
        str += '</div>';
        goLinks[prop] = str;
} // func mainLink

//  <a href="shows/noisesoff2005.html"><img src="img/noisesoff.gif"></a>

//=============================================================================
// Func:    lesserLink(sType, sLinkText, sLinkDates, sDestURL)
// Desc:    Add a lesser link: text and URL
// Args:    sType       - link type (S = show, N = news)
//          sLinkText   - the text of the link
//          sLinkDates  - the dates of the show/event (can be "")
//          sDestURL    - the URL to go to if the link is clicked
// Return:  None
//=============================================================================
function lesserLink(sType, sLinkText, sLinkDates, sDestURL, target) {
    var divClass = lesserLinkDivClass[sType];
    var targetTag;
    if( target )
    	targetTag = "target=\"" + target + "\"";
    if (!divClass)
        divClass = lesserLinkDivClass.N; // default to general news
    var txt = sLinkText;
    if (sLinkDates)
        txt += " &ndash; <span class='dates'>" + sLinkDates + "</span>";

    var str = "<div class='"+divClass+"' nowrap>"+
                "<a asdds=\"adf\" href=\"" + sDestURL + "\" " + targetTag + ">" +
                txt + "</a></div>";
    str += lesserTag;
    goLinks.lesserlinks = goLinks.lesserlinks.replace(lesserTag, str);
} // func lesserLink

//=============================================================================
// Func:    _RenderLinks()
// Desc:    Inserts generated links into the front page
// Args:    None
// Return:  None
//=============================================================================
function _RenderLinks() {
    var fpdiv = document.getElementById("fpcontent");
    var html = '<div id="MCTLogo"><img src="/img/logo/horizontal-240x75.jpg"></div>';

    for (var p in goLinks) {
        if (p!='lesserlinks') {
            html += _makeFloatBlock(p);
        } // if
    } // for each property of goLinks

    if( goLinks['lesserlinks'].indexOf(lesserTag)>0) html += _makeFloatBlock('lesserlinks');
    fpdiv.innerHTML = html ;
} // func _RenderLinks


function _makeFloatBlock(p) {
        return '<div class="floatblock" id="'+p+'">' +
           goLinks[p] + '</div>';
} // _makeFloatBlock
/*
            <img src="img/twostages.gif" width="475" height="120">
            <div class='floatblock' id="mainlink1"></div>
            <div class='floatblock' id="mainlink2"></div>
            <div class='floatblock' id="lesserlinks"></div>
*/
