//****
//Homepage article transitions
//****
var nCurrentLead = 0;
var arrArticleLead = new Array();
var nFadeOutOpacity = 100;
var nFadeInOpacity = 0;
var nClickedArticleLeadLink = -1;
var timerArticleLeads;

function initLeads()
{
    //loop through the lead articles and hide them
    for(i=0; i<=arrArticleLead.length-1; i++)
    {
        document.getElementById(arrArticleLead[i]).style.display = "none";
        document.getElementById(arrArticleLead[i]).style.MozOpacity = 0;
        document.getElementById(arrArticleLead[i]).style.KhtmlOpacity = 0;
        document.getElementById(arrArticleLead[i]).style.filter = "alpha(opacity=0)";
        document.getElementById(arrArticleLead[i]).style.opacity = 0;
    }
    
    //set the first article to display
    nClickedArticleLeadLink = 0;

    //initiate the change
    changeLeads();              
}

// move to the previous article
function changeLeads_Prev()
{
    // stop moving at the first article
    if(nCurrentLead == 0)
    {
        nClickedArticleLeadLink = 0;
    }
    else
    {
        nClickedArticleLeadLink = nCurrentLead - 1;
    }
    
    // clear the timer
    clearTimeout(timerArticleLeads);
    
    //initiate the change
    changeLeads();
}

// move to the next article
function changeLeads_Next()
{
    // stop moving at the last article
    if(nCurrentLead == arrArticleLead.length-1)
    {
        nClickedArticleLeadLink = arrArticleLead.length-1;
    }
    else
    {
        nClickedArticleLeadLink = nCurrentLead + 1;
    }
    
    // clear the timer
    clearTimeout(timerArticleLeads);
    
    // initiate the change
    changeLeads();
}

// move to the selected article
function changeLeads_onClick(obj, nArticleLeadLink)
{
    // adjust the story number for the array
    nClickedArticleLeadLink = nArticleLeadLink - 1;
    
    // clear the timer
    clearTimeout(timerArticleLeads);
    
    // initiate the change
    changeLeads();
}

// change the article
function changeLeads()
{
    // set the previous article to the last current
    var nPreviousLead = nCurrentLead;

    // if a change has been initated outside of time
    if(nClickedArticleLeadLink >= 0)
    {
        clearTimeout(); // clear the timer
        nCurrentLead = nClickedArticleLeadLink; // set the current to the selected
        nClickedArticleLeadLink = -1; // clear out the selected for next time
    }
    else
    {
        if(nCurrentLead != arrArticleLead.length-1) // determine if we reached the end
        {nCurrentLead = nCurrentLead + 1;} // if not continue to the next article
        else 
        {nCurrentLead = 0;} // or move to the first article
    }
    
    fadeOut(nPreviousLead); // fade out the previous article
    fadeIn(nCurrentLead); // fade in the current article
    
    // change the selected story number
    for(i=0;i<=arrArticleLead.length-1;i++)
    {
        document.getElementById("article_lead_" + i + "_link").className = "story"; // set all to normal
    }
    document.getElementById("article_lead_" + nCurrentLead + "_link").className = "story selected"; // select the current lead aricle link
    
    timerArticleLeads = setTimeout("changeLeads()", 10000); // initate the time to change automatically
}

// fade out
function fadeOut(articleLead)
{   
    // retrieve the article's div
    var object =  document.getElementById(arrArticleLead[articleLead]).style;

    // test if the article is completely faded
    if(nFadeOutOpacity > 0)
    {
        // set the opacity levels for the different browsers
        object.opacity = (nFadeOutOpacity / 100);
        object.MozOpacity = (nFadeOutOpacity / 100);
        object.KhtmlOpacity = (nFadeOutOpacity / 100);
        object.filter = "alpha(opacity=" + nFadeOutOpacity + ")"; 
        
        nFadeOutOpacity = nFadeOutOpacity - 5; // set the next fade out level
        setTimeout("fadeOut(" + articleLead + ")", 50); // continue the fade out
    }
    else
    {
        object.display = "none"; // completely hide the div
        nFadeOutOpacity = 100; // reset the opacity for the next fade out
    }    
}

// fade in
function fadeIn(articleLead)
{
    // retrieve the article's div
    var object =  document.getElementById(arrArticleLead[articleLead]).style;
    
    // set it to visible
    object.display = "block";
    
    // test if the article is completely visible
    if(nFadeInOpacity < 100)
    {
        // set the opacity levels for the different browsers
        object.MozOpacity = (nFadeInOpacity / 100);
        object.KhtmlOpacity = (nFadeInOpacity / 100);
        object.filter = "alpha(opacity=" + nFadeInOpacity + ")";
        object.opacity = (nFadeInOpacity / 100);
                           
        nFadeInOpacity = nFadeInOpacity + 5; // set the next fade in level
        setTimeout("fadeIn(" + articleLead + ")", 50); // continue the fade in
    }
    else
    {
        nFadeInOpacity = 0; // reset the opacity for the next fade in
    }  
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) 
{
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot = str.indexOf(dot)
    
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail Address")
        return false
    }

    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail Address")
        return false
    }

    return true 
}

function ValidateForm() {

    var emailID = document.getElementById("txtEmail");

    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value)==false){
        emailID.value=""
        emailID.focus()
        return false
    }
    
    return true
}

function submitNewsletter() 
{
    var bValid = ValidateForm();

    if (bValid) {
        window.open('', 'newsletter', 'menubar=1,resizable=1,width=350,height=250');

        var newsletterForm = document.getElementById('aspnetForm');
        newsletterForm.action = 'http://www.robbreportcollection.com/code/newsletter.asp';
        newsletterForm.target = 'newsletter';
        newsletterForm.submit();
        newsletterForm.action = '';
        newsletterForm.target = '_self';
    }

    return false
}

function resize(height) {
    document.getElementById("multimediaGallery").style.height = height + "px";
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function MediaGallery_DoFSCommand(command, args) {
    var MediaGalleryObj = isInternetExplorer ? document.all.MediaGallery : document.MediaGallery;
    if (command == "resize") {
        if (!isNaN(args)) {
            if (document.getElementById("multimediaGallery") != null)
                document.getElementById("multimediaGallery").style.height = Math.round((args * (345 / 439)) - (66 * (args / 499))) + "px";

            if (document.getElementById("ctl00_cphBodyContent_mlcMedia") != null)
                document.getElementById("ctl00_cphBodyContent_mlcMedia").style.height = Math.round((args * (345 / 439)) - (66 * (args / 499))) + "px";            
        }
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<script language=\"VBScript\"\>\n');
    document.write('On Error Resume Next\n');
    document.write('Sub MediaGallery_FSCommand(ByVal command, ByVal args)\n');
    document.write('	Call MediaGallery_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('</script\>\n');
} else {

}
