function open_popup(uri, name, width, height) {
    // open a new window
    var newwin = window.open(uri, name, 'resizable=1,scrollbars=1,width='+width+',height='+height);
    
    // if window.focus is supported, give the popup focus
    if (window.focus) { newwin.focus() } 
    
}

function open_ratings_details(story) {
    open_popup('/rating/?mode=details&story_id='+story, 'spin_ratings', 320, 560);
}
function open_ratings_form(story) {
    open_popup('/rating/?mode=vote&story_id='+story, 'spin_ratings', 255, 200);
}
function open_gallery(story) {
    open_popup(story,'spin_gallery',760, 620);
}
function open_poll_form(story) {
    open_popup('/poll/?mode=vote&story_id='+story, 'spin_polls', 320, 370);
}
function open_poll_results(story) {
    open_popup('/poll/?story_id='+story, 'spin_polls', 320, 570);
}
function open_media_viewer(uri,filetype) {
    open_popup('/mediaviewer/?uri='+uri+'&filetype='+filetype, 'spin_media', 730, 400);
}
function open_send_friend(uri) {
    open_popup(uri, 'spin_friend', 320, 320);
}
function open_contest(uri) {
    open_popup(uri, 'spin_contest', 725, 620);
}

function resize(w,h) {
  window.resizeTo(w,h);
}

function resizePollToFit() {
    var agt = navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_ie    = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie5   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") !=-1));
    var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_mac = (agt.indexOf("mac")!=-1);
       
    if (window.opera || ((is_ie5 || is_ie5_5) && !is_mac)) {
      // Opera and IE5/Win only
      resize(320, document.body.scrollHeight + 50);
    } else {
      // Everyone else
      resize(320, document.body.offsetHeight + 50);
    }
}

function switch_photo_info() {
    var photo = document.getElementById("photoweek");
    var info = document.getElementById("photoweekdata");
    
    if(info.style.display == 'block') {  // info showing
        photo.style.display = 'block';   // show photo
        info.style.display = 'none'      // hide info
    } else {                             // photo showing
        photo.style.display = 'none';    // hide photo
        info.style.display = 'block';    // show info
    }
}

startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("dropdown");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+="over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace("over", "");
                }
            }
        }
    }
}

function closeMenu() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("dropdown");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.className=node.className.replace("over", "");
            }
        }
    }    
}

// Output results of document.write since View Source doesn't work
function debugDocumentWrite(){
    var win = window.open('','_blank');
    var results = document.documentElement.innerHTML.replace(/</g, "&lt;");
    win.document.write(results);
} 

window.onload =  function() {
    startList();
    
    var photolinks = document.getElementById("photoweekdata").getElementsByTagName("a");
    for(var i=0; i<photolinks.length; i++) {
        photolinks[i].onclick = function(e) {
            if (!e) var e = window.event;
            e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
        }
    }
    
    if (location.search.indexOf("debug") != -1) debugDocumentWrite();
}