$(document).ready(function(){  
    function nonFlash(){
        $("#flashcontent").each(function(){
            var btnReadMore = "Read More"; /* Read from XML file when available */
    var flashContent = this;
    var thumbs = this.appendChild(document.createElement("div"));
    with(thumbs.style){
    position="absolute";
    right="20px";
    bottom="20px";
    textAlign="right";
    zIndex=2;

    }
    var teaserHolder = thumbs.appendChild(document.createElement("div"));
    with(teaserHolder.style){
    position="absolute";
    left=0;
    top="63px";
    zIndex=20;
    width="100%";
    textAlign="left";
    }
    var slides = [];
    var imgfolder;
    var readmoretitle;
    var autoadvance;
    var delay;
    function addThumb(item){
    $("thumbnail",item).each(function(){
    var thumb = thumbs.appendChild(document.createElement("img"));
    var slide = flashContent.appendChild(document.createElement("div"));
    var teaser = teaserHolder.appendChild(document.createElement("div"));
    teaser.appendChild(document.createTextNode($("rollOverText",item).text()));
    with(slide.style){
    position="absolute";
    top=0;
    left=0;
    display="none";
    color="white";
    }
    with(teaser.style){
    position="absolute";
    top=0;
    left="5px";
    display="none";
    color="white";
    width="100%";
    textAlign="left";
    }
    slide.className = "slide";

    slide.appendChild(document.createElement("img")).src = imgfolder + $("image",item).text();
    var h1 = slide.appendChild(document.createElement("h1"));
    with(h1.style){
        overflow="visible";
        position="absolute";
        top="20px";
        left="20px";
        fontSize="35px";
        lineHeight="50px";
        padding=0;
        margin=0;
        zIndex=2;
    }
    $(h1).append($("title",item).text());
    
    var h1Shadow = h1.cloneNode(true);
    h1Shadow.style.color="Black";
    h1Shadow.style.zIndex=1;
    h1Shadow.style.top="22px";
    h1Shadow.style.left="22px";
    
    slide.appendChild(h1Shadow);
    
    var div = slide.appendChild(document.createElement("div"));
    with(div.style){
        position="absolute";
        top="70px";
        left="20px";
        fontSize="14px";
        zIndex=2;
    }
    $(div).append($("desc",item).text());
    $(slide).append("<button onclick=\"document.location.href='"+$("link",item).text()+"'\" style=\"font-weight:bold;position:absolute;left:20px;bottom:40px;border:solid 1px white; background-color:rgb(94,130,171);cursor:pointer;color:white\">"+btnReadMore+"</button>");
    
    $("button",slide).bind("mouseout",function(){
    $(this).css({"background-color":"rgb(94,130,171)"});
    });
    $("button",slide).bind("mouseover",function(){
    $(this).css({"background-color":"rgb(135,33,46)"});
    });
    var mykey = this.firstChild.nodeValue; 
    slide._key = mykey; 
    teaser._key = mykey; 
    slides.push(mykey);
    with(thumb.style){
    marginLeft = "10px";
    marginTop = "1px";
    marginBottom = "2px";
    cursor="pointer";
    border="solid 1px white";
    }
    thumb.src = imgfolder + this.firstChild.nodeValue;
    var hi = thumbs.appendChild(document.createElement("div"));
    with(hi.style){
    position="absolute";
    left = "" + ($(thumb).position().left +8 ) + "px";
    top = "" + ($(thumb).position().top ) + "px";
    width = "" + ($(thumb).width()+2) + "px";
    height = "" + ($(thumb).height()) + "px";
    border="solid 2px white";
    zIndex=-1;
    display="none";
    }
    thumb.onclick = function(){showSlide($("thumbnail",item).text())};
    thumb.onmouseover = function(){
    $(hi).fadeIn("slow");
    $("div:visible",teaserHolder).fadeOut("slow");
    $("div[_key='"+mykey+"']",teaserHolder).fadeIn("slow");
    };
    thumb.onmouseout = function(){
    $("div:visible",teaserHolder).fadeOut("slow");
    $(hi).fadeOut("slow");
     
    };
    });
    };
    function showSlide(key){
    clearTimeout(autoadvance);
    $("div.slide:visible",flashContent).fadeOut("slow");
    $("div.slide[_key='"+key+"']",flashContent).fadeIn("slow");
    setTimeout(autoShow,1000);
    };
    function autoShow(){
    var mykey = ($("div.slide:visible",flashContent).attr("_key"));
    var nextkey = null;
    for(var x=0; x<(slides.length-1); x++){
    if(slides[x]==mykey){
nextkey = slides[x+1];
}
    }
    if(nextkey==null){
nextkey = slides[0];
}
    autoadvance = setTimeout(function(){showSlide(nextkey);},delay);
};
    var config = $("link[rel='flash-config']");
$.get(((config.length>0) ? config.get(0).getAttribute("href") : "./config.xml"),null,function(data){
    $("img",flashContent).css({visibility:"hidden"});
    imgfolder = ($("list",data).attr("imageFolder")); 
    readmoretitle = ($("list",data).attr("readMoreTitle")); 
    delay = ($("list",data).attr("delay")); 
    $("item",data).each(function(){
    addThumb(this);
    });
    $("item:first",data).each(function(){
    showSlide($("thumbnail",this).text());
    });
    },"xml");
    });
    };
    
    $("#flashcontent").each(function(){
        var flashvars = {};
        flashvars.var1 = "value1";
        flashvars.var2 = "value2";
        //
        var params = {};  
        params.menu = "false";
        params.bgcolor = "#000000";
        params.wmode ="transparent";
        //
        var attributes = {};
        attributes.id = "mySWF";
        attributes.name = "mySWF";
        //
        var flashFile ="moogFlash.swf?noCache="+(new Date().getTime());
       // Do fallback if swfobject fails to embed Flash (i.e. flash not installed)
       var l1 = $("object").length
       swfobject.embedSWF(flashFile, this.id, "1000", "270", "9.0.0","js/expressInstall.swf", flashvars, params, attributes);
       if($("object").length == l1){
            nonFlash();   
       }
    });
});

