﻿//Prevents IE6 from flickering when links have images as backgrounds
function IE6Flicker() 
{
    try { document.execCommand("BackgroundImageCache", false, true); } 
    catch(err) {}
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

var HomePageTabs = {
    start: function() {
        var latestnewslink = $$('#latestnewslink a')[0];
        var featureddocslink = $$('#featureddocslink a')[0];
        
        latestnewslink.addEvent('click', function(e){
            // If this tab is already selected the nothing to do
            if (latestnewslink.hasClass('selected'))
                return;
                
            // Set this tab as selected
            latestnewslink.addClass("selected");
            
            // Remove the selected state from the other tab
            featureddocslink.removeClass('selected');
            
            // Show the latest news list
            $('latestnews').removeClass('hidden');
            
            // Hide the other list
            $('featuredDocs').addClass('hidden');
        });       
        
        featureddocslink.addEvent('click', function(e){
            // If this tab is already selected the nothing to do
            if (featureddocslink.hasClass('selected'))
                return;
                
            // Set this tab as selected
            featureddocslink.addClass("selected");
            
            // Remove the selected state from the other tab
            latestnewslink.removeClass('selected');
            
            // Show the featured docs list
            $('featuredDocs').removeClass('hidden');
            
            // Hide the other list
            $('latestnews').addClass('hidden');
        });
    }
}

var Site = {
	start: function() {
	    HomePageTabs.start();
	    IE6Flicker();
    }
};
window.addEvent('domready', Site.start);