bWorking = false;

function setLinks() {
    var links = document.getElementsByTagName("a");
    for (i=0;i<links.length;i++) {
        if (links[i].className.match("storylink")) {
            links[i].onclick = function() {
                this.href = "javascript:void(0);"
                var title_search = this.id.split("_");
                cansasCityShuffle(title_search[1]);
            }
        }
    }
}

function cansasCityShuffle(sStoryID) {
    if (!bWorking && sStoryID != sCurrentStoryID) {
        bWorking = true;
        highlightLink(sStoryID);
        Effect.Fade($("panel_"+sCurrentStoryID), {
            duration: 0.5,
            afterFinish:function() {
                Effect.Appear($("panel_"+sStoryID), {
                    duration: 0.5,
                    afterFinish:function() {
                        sCurrentStoryID = sStoryID;
                        bWorking = false;
                    }
                });
            }
        });
        
//        Effect.BlindUp($("panel_"+sCurrentStoryID), {
//            duration: 0.5,
//            afterFinish:function() {
//                Effect.BlindDown($("panel_"+sStoryID), {
//                    duration: 0.5,
//                    afterFinish:function() {
//                        
//                    }
//                });
//            }
//        });
        
    }
}

function highlightLink(sStoryID) {
    var links = document.getElementsByTagName("a");
    for (i=0;i<links.length;i++) {
        if (links[i].className == "storylink on") {
            links[i].className = "storylink";
        }
    }
    $("link_"+sStoryID).className = "storylink on";
}

Event.observe (window, "load", function() {
    setLinks();
});

