/*
 * Default Javascript library file for LGC web.
 * All Script is protected by Copyright and may not be used without
 * permission.
 *
 * Written by HalogenLABS for LGC.
 * Original Script, Copyright© 2010 Halogen Graphics and Digital Design CC.
 *
 * For more information please contact Halogen Graphics at:
 * studio@halogengraphics.co.za
 *
 * Or visit the HalogenLABS website at:
 * http://www.halogenlabs.co.za
 *
 */

/**
 * Simple script initialization. Used mainly to initialize the DIV elements by
 * making sure they are all hidden.
 */
function Init() {
    var aboutMenu = document.getElementById('aboutMenu');
    var solutionsMenu = document.getElementById('solutionsMenu');
    var whyMenu = document.getElementById('whyMenu');
    var howMenu = document.getElementById('howMenu');

    aboutMenu.style.visibility = 'hidden';
    solutionsMenu.style.visibility = 'hidden';
    whyMenu.style.visibility = 'hidden';
    howMenu.style.visibility = 'hidden';

    // For the hiding and showing of the side bar components.
    var newsFeedContentDiv = document.getElementById('newsFeedContentDiv');
    newsFeedContentDiv.style.display = 'block';
    var articlesContentDiv = document.getElementById('articlesContentDiv');
    articlesContentDiv.style.display = 'block';
}

function IsIE() {
    var returnValue = false;
    if (window.navigator.appName == 'Microsoft Internet Explorer') {
        returnValue = true;
    }
    return returnValue;
}

function IsIE7() {
    var returnValue = false;
    if (window.navigator.appName == 'Microsoft Internet Explorer') {
        var userAgent = window.navigator.userAgent;
        var ieo = userAgent.indexOf('MSIE ');

        var browserMajorVersion = parseInt(userAgent.substring(ieo + 5, userAgent.indexOf(';', ieo)).substring(0,1));
        if (browserMajorVersion <= 7) {
            returnValue = true;
        }
    }
    return returnValue;
}

function CheckBrowser() {

    var navName = window.navigator.appName;
    var userAgent = window.navigator.userAgent;

    //alert(userAgent);
}

/**
 * Internet Explorer 7 won't size IFRAMES vertically to 100%, so we need to
 * set the size dynamically for IE7.
 */
function ResizeIFrame() {

    if (IsIE7()) {

        // We need the size of at least one page...
        var aboutPage = document.getElementById('aboutGenesisDiv');
        var pageHeight = aboutPage.offsetHeight;

        // Resize each IFRAME...
        var iFrames = document.getElementsByTagName('iframe');

        for (var i = 0; i < iFrames.length; i++) {
            if (iFrames[i].id.substr(iFrames[i].id.length - 3, 3) == 'ccc')
                iFrames[i].style.height = (pageHeight - 50) + 'px';
        }

        // The home frame suffers from the same problem, but has different
        // sizing requirements. We can use one of the BG image divs as reference....
        var bgImage = document.getElementById('imageDiv1');
        var bgImageHeight = bgImage.offsetHeight;

        var homeFrame = document.getElementById('homeFrame');
        homeFrame.style.height = bgImageHeight + 'px';
    }
}

function ResizeArticlesDiv() {
    var articlesContentDiv = document.getElementById('articlesContentDiv');

    var sideDivHeight = document.getElementById('sideDiv').offsetHeight;
    var newsFeedContentDiv = document.getElementById('newsFeedContentDiv');

    var newsFeedHeight = 0;
    if (newsFeedContentDiv.style.display == 'block') {
        newsFeedHeight = newsFeedContentDiv.offsetHeight;
    }

    var sidebarOffsetHeight = newsFeedHeight + 100;

    articlesContentDiv.style.height = (sideDivHeight - sidebarOffsetHeight) + 'px';

    //articlesContentDiv.style.height = (sideDivHeight - 300) + 'px';
}

/**
 * Another one for Internet Explorer 7. IE7 doesn't insert a break before
 * paragraphs as other browsers do. This will insert a line break for
 * IE7 and earlier. Returns null if another other browser.
 */
function InsertBreak() {
    var returnValue = '';
    if (window.navigator.appName == 'Microsoft Internet Explorer') {
        var userAgent = window.navigator.userAgent;
        var ieo = userAgent.indexOf('MSIE ');

        var browserMajorVersion = parseInt(userAgent.substring(ieo + 5, userAgent.indexOf(';', ieo)).substring(0,1));
        if (browserMajorVersion <= 7) {
            // Have IE7...

            returnValue = "<br />";
        }
    }
    document.writeln(returnValue);
}

/**
 * Toggle the small arrow button on the right-side bar
 */
function ToggleArrowButton(buttonID) {
    var button = document.getElementById(buttonID);
    if (button.src.indexOf('images/small_arrow_button_off.png') > 0) {
        button.src = 'images/small_arrow_button_on.png';
    } else {
        button.src = 'images/small_arrow_button_off.png';
    }
}

function SwapClass(elementId, className) {
    var element = document.getElementById(elementId);
    element.classNameO = element.className;
    element.className = className;
}

function RestoreClass(elementId) {
    var element = document.getElementById(elementId);
    element.className = element.classNameO;
}

/**
 * Preload images used for mouse overs.
 * © Adobe Systems.
 */
function MM_preloadImages() { //v3.0
    var d=document;
    if (d.images) {
        if (!d.MM_p)
            d.MM_p = new Array();
    }
    var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
    for(i=0; i < a.length; i++)
    if (a[i].indexOf("#") != 0) {
        d.MM_p[j] = new Image;
        d.MM_p[j++].src = a[i];
    }
}

/**
 * Return the last image from a mouse over.
 * © Adobe Systems.
 */
function MM_swapImgRestore() { //v3.0
  var i, x, a = document.MM_sr;
  for(i=0; a && i< a.length && (x=a[i]) && x.oSrc; i++)
      x.src=x.oSrc;
}

/**
 * Find objects within the document.
 * © Adobe Systems.
 */
function MM_findObj(n, d) { //v4.01
    var p, i, x;
    if (!d)
        d = document;
    if ((p = n.indexOf("?")) > 0&& parent.frames.length) {
        d = parent.frames[n.substring(p+1)].document;
        n = n.substring(0,p);
    }
    if (!(x = d[n]) && d.all)
        x = d.all[n];
    for (i = 0; !x && i<d.forms.length; i++)
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById)
        x = d.getElementById(n);
    return x;
}

/**
 * Swap image during mouse over.
 * © Adobe Systems.
 */
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for(i = 0; i < (a.length-2); i += 3)
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) x.oSrc = x.src;
            x.src = a[i+2];
        }
}

/**
 * The Feed button reacts to mouse over requests.
 * Class: feedDivOver
 */
function FeedMouseOver(feedDiv) {
    var feedDivDom = document.getElementById(feedDiv);
    var feedImageDom = document.getElementById(feedDiv + 'Image');
    feedDivDom.className = 'feedDivOver';
    if (feedImageDom != null) {
        feedImageDom.src = 'images/news_button_on.png'
    }
}

/**
 * Return the feed button to it's original state.
 * Class: feedDiv
 */
function FeedMouseOut(feedDiv) {
    var feedDivDom = document.getElementById(feedDiv);
    var feedImageDom = document.getElementById(feedDiv + 'Image');
    feedDivDom.className = 'feedDiv';
    if (feedImageDom != null) {
        feedImageDom.src = 'images/news_button_off.png'
    }
}

/**
 * Sets an element to visible.
 */
function ShowElement(elementID) {
    var dom = document.getElementById(elementID);

    dom.style.visibility = 'visible';
}

/**
 * Sets an element to hidden
 */
function HideElement(elementID) {
    var dom = document.getElementById(elementID);

    dom.style.visibility = 'hidden';
}

function ToggleBlockDisplay(elementID) {
    var dom = document.getElementById(elementID);

    if (dom.style.display == 'block') {
        dom.style.display = 'none';
    } else {
        dom.style.display = 'block';
    }

    ResizeArticlesDiv();
}

/**
 * Deactivate a button by replacing it with the standard "up" image.
 */
function DeactivateButton(buttonID, offFile, overFile) {
    var button = document.getElementById(buttonID);
    button.src = offFile;
    button.onmouseover = function() {
        button.src = overFile;
    }
    button.onmouseout = function() {
        button.src = offFile;
    }
}

/**
 * This function will close all menus. There should never be more than
 * one menu open at a time.
 */
function CloseAllMenus() {

    var aboutMenu = document.getElementById('aboutMenu');
    var solutionsMenu = document.getElementById('solutionsMenu');
    var whyMenu = document.getElementById('whyMenu');
    var howMenu = document.getElementById('howMenu');

    if (aboutMenu.style.visibility != 'hidden') {
        FadeDown(aboutMenu);
    }
    if (solutionsMenu.style.visibility != 'hidden') {
        FadeDown(solutionsMenu);
    }
    if (whyMenu.style.visibility != 'hidden') {
        FadeDown(whyMenu);
    }
    if (howMenu.style.visibility != 'hidden') {
        FadeDown(howMenu);
    }
}

// The current active button.
var currentButton = 'home';

/**
 * Activate the given button ID.
 */
function ActivateButton(buttonID, menuToggle) {

    var toggleMenu = true;
    if (menuToggle != null) {
        toggleMenu = menuToggle;
    }

    DeactivateButton('homeButton', 'images/button_bar/home_off.png', 'images/button_bar/home_over.png');
    DeactivateButton('aboutButton', 'images/button_bar/about_off.png', 'images/button_bar/about_over.png');
    DeactivateButton('solutionsButton', 'images/button_bar/solutions_off.png', 'images/button_bar/solutions_over.png');
    DeactivateButton('whyButton', 'images/button_bar/whychoose_off.png', 'images/button_bar/whychoose_over.png');
    DeactivateButton('howButton', 'images/button_bar/how_off.png', 'images/button_bar/how_over.png');
    DeactivateButton('partnersButton', 'images/button_bar/partners_off.png', 'images/button_bar/partners_over.png');
    DeactivateButton('memberButton', 'images/button_bar/membership_off.png', 'images/button_bar/membership_over.png');
    DeactivateButton('contactButton', 'images/button_bar/contact_off.png', 'images/button_bar/contact_over.png');

    CloseAllMenus();

    var homeDiv = document.getElementById('homeDiv');
    var aboutGenesisDiv = document.getElementById('aboutGenesisDiv');
    var aboutCoreDiv = document.getElementById('aboutCoreDiv');
    var aboutTeamDiv = document.getElementById('aboutTeamDiv');
    var solutionsBackgroundDiv = document.getElementById('solutionsBackgroundDiv');
    var solutionsWhereDiv = document.getElementById('solutionsWhereDiv');
    var solutionsOfferingDiv = document.getElementById('solutionsOfferingDiv');
    var whyUniqueDiv = document.getElementById('whyUniqueDiv');
    var whyIndustryDiv = document.getElementById('whyIndustryDiv');
    var howProjectDiv = document.getElementById('howProjectDiv');
    var howProblemDiv = document.getElementById('howProblemDiv');
    var partnersDiv = document.getElementById('partnersDiv');
    var membersDiv = document.getElementById('membersDiv');
    var contactDiv = document.getElementById('contactDiv');
    var searchDiv = document.getElementById('resultsDiv');

    var button = null;

    if (currentButton == 'home' && buttonID != 'homeButton') {
        if (IsIE()) {
            HideElement('homeDiv');
        } else {
            FadeDown(homeDiv);
        }
    } else if (currentButton == 'aboutGenesis' &&
        buttonID != 'aboutGenesisButton') {
        FadeDown(aboutGenesisDiv);
    } else if (currentButton == 'aboutCore' &&
        buttonID != 'aboutCoreButton') {
        FadeDown(aboutCoreDiv);
    } else if (currentButton == 'aboutTeam' &&
        buttonID != 'aboutTeamButton') {
        FadeDown(aboutTeamDiv);
    } else if (currentButton == 'solutionsBackground' &&
        buttonID != 'solutionsBackgroundButton') {
        FadeDown(solutionsBackgroundDiv);
    } else if (currentButton == 'solutionsWhere' &&
        buttonID != 'solutionsWhereButton') {
        FadeDown(solutionsWhereDiv);
    } else if (currentButton == 'solutionsOffering' &&
        buttonID != 'solutionsOfferingButton') {
        FadeDown(solutionsOfferingDiv);
    } else if (currentButton == 'whyUnique' &&
        buttonID != 'whyUniqueButton') {
        FadeDown(whyUniqueDiv);
    } else if (currentButton == 'whyIndustry' &&
        buttonID != 'whyIndustryButton') {
        FadeDown(whyIndustryDiv);
    } else if (currentButton == 'howProject' &&
        buttonID != 'howProjectButton') {
        FadeDown(howProjectDiv);
    } else if (currentButton == 'howProblem' &&
        buttonID != 'howProblemButton') {
        FadeDown(howProblemDiv);
    } else if (currentButton == 'partners' &&
        buttonID != 'partnersButton') {
        FadeDown(partnersDiv);
    } else if (currentButton == 'members' &&
        buttonID != 'memberButton') {
        FadeDown(membersDiv);
    } else if (currentButton == 'contact' &&
        buttonID != 'contactButton') {
        FadeDown(contactDiv);
    } else if (currentButton == 'articles' &&
        buttonID != 'articles') {
        FadeDown(articlesDiv);
    } else if (currentButton == 'search' &&
        buttonID != 'search') {
        FadeDown(searchDiv);
        }

    // One of the About options was selected.
    if (buttonID == 'aboutGenesisButton' ||
        buttonID == 'aboutCoreButton' ||
        buttonID == 'aboutTeamButton') {
        if (toggleMenu)
            ToggleMenu('aboutMenu');
        button = document.getElementById('aboutButton');
        button.src = 'images/button_bar/about_active.png';
        button.onmouseover = null;
        button.onmouseout = null;
        
        if (buttonID == 'aboutGenesisButton') {
            FadeUp(aboutGenesisDiv);
            currentButton = 'aboutGenesis';
        }
        if (buttonID == 'aboutCoreButton') {
            FadeUp(aboutCoreDiv);
            currentButton = 'aboutCore';
        }
        if (buttonID == 'aboutTeamButton') {
            FadeUp(aboutTeamDiv);
            currentButton = 'aboutTeam';
        }
    }
    // The home button was selected.
    else if (buttonID == 'homeButton') {
        button = document.getElementById('homeButton');
        button.src = 'images/button_bar/home_active.png';
        button.onmouseover = null;
        button.onmouseout = null;

        if (IsIE()) {
            ShowElement('homeDiv');
        } else {
            FadeUp(homeDiv);
        }
        currentButton = 'home';
    }
    // One of the Solutions options was selected
    else if (buttonID == 'solutionsBackgroundButton' ||
        buttonID == 'solutionsWhereButton' ||
        buttonID == 'solutionsOfferingButton') {
        if (toggleMenu)
            ToggleMenu('solutionsMenu');
        button = document.getElementById('solutionsButton');
        button.src = 'images/button_bar/solutions_active.png';
        button.onmouseover = null;
        button.onmouseout = null;

        if (buttonID == 'solutionsBackgroundButton') {
            FadeUp(solutionsBackgroundDiv);
            currentButton = 'solutionsBackground';
        }
        if (buttonID == 'solutionsWhereButton') {
            FadeUp(solutionsWhereDiv);
            currentButton = 'solutionsWhere';
        }
        if (buttonID == 'solutionsOfferingButton') {
            FadeUp(solutionsOfferingDiv);
            currentButton = 'solutionsOffering';
        }
    }
    // One of the Why buttons was selected
    else if (buttonID == 'whyUniqueButton' ||
        buttonID == 'whyIndustryButton') {
        if (toggleMenu)
            ToggleMenu('whyMenu');
        button = document.getElementById('whyButton');
        button.src = 'images/button_bar/whychoose_active.png';
        button.onmouseover = null;
        button.onmouseout = null;

        if (buttonID == 'whyUniqueButton') {
            FadeUp(whyUniqueDiv);
            currentButton = 'whyUnique';
        }
        if (buttonID == 'whyIndustryButton') {
            FadeUp(whyIndustryDiv);
            currentButton = 'whyIndustry';
        }
    }
    // One of the How buttons was selected
    else if (buttonID == 'howProjectButton' ||
        buttonID == 'howProblemButton') {
        button = document.getElementById('howButton');
        button.src = 'images/button_bar/how_active.png';
        button.onmouseover = null;
        button.onmouseout = null;

        if (buttonID == 'howProjectButton') {
            FadeUp(howProjectDiv);
            currentButton = 'howProject';
        }
        if (buttonID == 'howProblemButton') {
            FadeUp(howProblemDiv);
            currentButton = 'howProblem';
        }

    }
    // The partners button was selected
    else if (buttonID == 'partnersButton') {
        button = document.getElementById('partnersButton');
        button.src = 'images/button_bar/partners_active.png';
        button.onmouseover = null;
        button.onmouseout = null;
		
        FadeUp(partnersDiv);
        currentButton = 'partners';
    }
    // The members button was selected.
    else if (buttonID == 'memberButton') {
        button = document.getElementById('memberButton');
        button.src = 'images/button_bar/membership_active.png';
        button.onmouseover = null;
        button.onmouseout = null;
		
        FadeUp(membersDiv);
        currentButton = 'members';
    }
    // The contact Button was selected.
    else if (buttonID == 'contactButton') {
        button = document.getElementById('contactButton');
        button.src = 'images/button_bar/contact_active.png';
        button.onmouseover = null;
        button.onmouseout = null;
		
        FadeUp(contactDiv);
        currentButton = 'contact';
    }
    // This is for the articles link. Does not activate any button. Is used to
    // Deactivate the other buttons and load the articles DIV.
    else if (buttonID == 'search') {

        FadeUp(searchDiv);
        currentButton = 'search';
    }
}

/**
 * Fade between two elements. Fade the first one down, and the second one
 * up at the same pace.
 */
function FadeBetween(domFrom, domTo) {

    var upOpacity = 0;
    var downOpacity = 1;
    var ieUpOpacity = 0;
    var ieDownOpacity = 100;

    var faderUp = function() {

        upOpacity += 0.05;
        ieUpOpacity = upOpacity * 100;

        if (upOpacity < 1) {
            domTo.style.visibility = 'visible';
            domTo.style.opacity = upOpacity;
            domTo.style.filter = 'alpha(opacity=' + ieUpOpacity + ')';
        }
        if (upOpacity >= 1) {
            clearInterval(faderUpInterval);
        }
    }
    
    var faderDown = function() {
        downOpacity -= 0.05;
        ieDownOpacity = downOpacity * 100;

        if (upOpacity < 1) {
            domFrom.style.opacity = downOpacity;
            domFrom.style.filter = 'alpha(opacity=' + ieDownOpacity + ')';
        }
        if (downOpacity <= 0) {
            clearInterval(faderDownInterval);
            domFrom.style.visibility = 'hidden';
        }
    }
    var faderUpInterval = setInterval(faderUp, 100);
    var faderDownInterval = setInterval(faderDown, 100);

}

/**
 * Fade an element up. Sets an elements visibility to true.
 */
function FadeUp(dom, speed) {

    if (typeof speed == 'undefined') {
        speed = 10;
    }
    
    var opacity = 0;
    var ieOpacity = 0;

    var fader = function() {

        opacity += 0.05;
        ieOpacity = opacity * 100;

        if (opacity < 1) {
            dom.style.visibility = 'visible';
            dom.style.opacity = opacity;
            dom.style.filter = 'alpha(opacity=' + ieOpacity + ')';
        }
        if (opacity >= 1) {
            clearInterval(faderInterval);
        }
    }

    var faderInterval = setInterval(fader, speed);
}

/**
 * Fade an element down. Sets the elements visibility to false.
 */
function FadeDown(dom, speed) {
    if (typeof speed == 'undefined') {
        speed = 10;
    }
    var opacity = 1;
    var ieOpacity = 100;

    var fader = function() {

        opacity -= 0.05;
        ieOpacity = opacity * 100;

        if (opacity < 1) {
            //dom.style.visibility = 'visible';
            dom.style.opacity = opacity;
            dom.style.filter = 'alpha(opacity=' + ieOpacity + ')';
        }
        if (opacity <= 0) {
            clearInterval(faderInterval);
            dom.style.visibility = 'hidden';
        }
    }

    var faderInterval = setInterval(fader, speed);
}

/**
 * The function is used to fade the two background image DIV containers.
 */
function DivBGImageFader(nextImageFilename) {
    var div1 = document.getElementById('imageDiv1');
    var div2 = document.getElementById('imageDiv2');

    if (div1Visible) {
        div2.style.backgroundImage = 'url(' + nextImageFilename + ')';
        FadeBetween(div1,div2);
    } else {
        div1.style.backgroundImage = 'url(' + nextImageFilename + ')';
        FadeBetween(div2,div1);
    }
    div1Visible = !div1Visible;
}

//var imageCounter = 1;

/**
 * This toggles a menu. Will open a menu when closed, or close a menu when open.
 */
function ToggleMenu(menuID) {

    var aboutMenu = document.getElementById('aboutMenu');
    var solutionsMenu = document.getElementById('solutionsMenu');
    var whyMenu = document.getElementById('whyMenu');
    var howMenu = document.getElementById('howMenu');
    
    CloseAllMenus();

    // About menu
    if (menuID == 'aboutMenu') {
        if (aboutMenu.style.visibility != 'visible') {
            FadeUp(aboutMenu);
        } else {
            FadeDown(aboutMenu);
        }
    }
    // Solutions menu
    if (menuID == 'solutionsMenu') {
        if (solutionsMenu.style.visibility != 'visible') {
            FadeUp(solutionsMenu);
        } else {
            FadeDown(solutionsMenu);
        }
    }
    // Why menu
    if (menuID == 'whyMenu') {
        if (whyMenu.style.visibility != 'visible') {
            FadeUp(whyMenu);
        } else {
            FadeDown(whyMenu);
        }
    }
    // How menu
    if (menuID == 'howMenu') {
        if (howMenu.style.visibility != 'visible') {
            FadeUp(howMenu);
        } else {
            FadeDown(howMenu);
        }
    }
}

function ToggleFeed(pageId) {

    var ajax = new AJAX();
    var feedPage = document.getElementById('bdFeedDiv');
    var bdButton = document.getElementById('feed1');
    var nwButton = document.getElementById('feed2');

    if (pageId == 'bd') {
        if (feedPage.currentPage == 'businessday') {
            FadeDown(feedPage);
            feedPage.innerHTML = 'Loading feed. Please wait, this may take a few moments...';
            feedPage.currentPage = null;
        } else {
            if (feedPage.currentPage == null) {
                FadeUp(feedPage);
            }
            feedPage.innerHTML = 'Loading feed. Please wait, this may take a few moments...';
            ajax.AsynchronousGet('getfeed.php?provider=businessday');
            feedPage.style.top = '185px';
            feedPage.currentPage = 'businessday';
        }

    } else if (pageId == 'nw') {
        if (feedPage.currentPage == 'newsweek') {
            FadeDown(feedPage);
            feedPage.innerHTML = 'Loading feed. Please wait, this may take a few moments...';
            feedPage.currentPage = null;
        } else {
            if (feedPage.currentPage == null) {
                FadeUp(feedPage);
            }
            feedPage.innerHTML = 'Loading feed. Please wait, this may take a few moments...';
            ajax.AsynchronousGet('getfeed.php?provider=newsweek');
            feedPage.style.top = '255px';
            feedPage.currentPage = 'newsweek';
        }
    }

    ajax.OnRequestComplete = function(response) {
        feedPage.innerHTML = response;
    }

    ajax.OnRequestSent = function() {
        feedPage.innerHTML = 'Loading feed...';
    }
}

function WebSearch() {
    var SearchTextDOM = document.getElementById('searchText');
    var resultsDiv = document.getElementById('resultsDiv');

    if (SearchTextDOM.value.length > 0) {
        var ajax = new AJAX();
        ajax.AsynchronousGet('search.php?st=' + SearchTextDOM.value);

        ajax.OnRequestComplete = function(response) {
            ActivateButton('search');
            resultsDiv.innerHTML = response;
        }
    }
}

function moveUp(id) {

    var ajax = new AJAX();

    ajax.OnRequestComplete = function(response) {
        if (response == 'refresh') {
            location.reload(true);
        }
    }

    ajax.AsynchronousGet('position.php?id=' + id + '&dir=up');

}
function moveFlashUp(id) {

    var ajax = new AJAX();

    ajax.OnRequestComplete = function(response) {
        if (response == 'refresh') {
            location.reload(true);
        }
    }

    ajax.AsynchronousGet('flashposition.php?id=' + id + '&dir=up');

}

function moveDown(id) {

    var ajax = new AJAX();

    ajax.OnRequestComplete = function(response) {
        if (response == 'refresh') {
            location.reload(true);
        }
    }

    ajax.AsynchronousGet('position.php?id=' + id + '&dir=down');

}
function moveFlashDown(id) {

    var ajax = new AJAX();

    ajax.OnRequestComplete = function(response) {
        if (response == 'refresh') {
            location.reload(true);
        }
    }

    ajax.AsynchronousGet('flashposition.php?id=' + id + '&dir=down');

}

function BlinkNewsFlash() {

    var newsFlashBarBG = document.getElementById('newsFlashBlink');
    var newsFlashBar = document.getElementById('newsFlashBar');

    newsFlashBarBG.style.opacity = 1;
    newsFlashBarBG.style.filter = 'alpha(opacity=100)';
    newsFlashBarBG.style.visibility = 'visible';
    newsFlashBarBG.style.height = newsFlashBar.offsetHeight + 'px';
    FadeDown(newsFlashBarBG, 50);

}

function GetNextNewsFlash() {
    

    var ajax = new AJAX();

    var header = '';
    var newsFlashSpan = document.getElementById('newsFlashSpan');
    var newsFlashContent = document.getElementById('newsFlashContent');
    if (newsFlashSpan.innerHTML != 'Loading News Flashes...') {
        header = '?header=' + escape(newsFlashSpan.innerHTML);
    }

    ajax.OnRequestComplete = function(response) {
        if (response) {

            var flash = response.split(';;');

            //var newsFlashText = document.getElementById('newsFlashText');
            var newsFlashBar = document.getElementById('newsFlashBar');

            if (flash[0].length > 0) {
                newsFlashBar.style.visibility = 'visible';
                //newsFlashText.style.visibility = 'visible';
                if (flash[0] != newsFlashSpan.innerHTML && flash[0].substr(0,30) + '...' != newsFlashSpan.innerHTML) {
                    var headerText = flash[0];
                    if (flash[0].length >= 30)
                        headerText = flash[0].substr(0, 30) + '...';
                    var subHeaderText = flash[1];
                    if (flash[1].length >= 100)
                        subHeaderText = flash[1].substr(0, 100) + '...';
                    newsFlashBar.innerHTML = '<a href="' + flash[3] + '" target="_blank" class="newsFlashLink" title="Click here to read more..."><span id="newsFlashSpan">' + headerText + '</span></a> - ' + subHeaderText;
                    var contentText = flash[2];
                    if (flash[2].length > 200)
                        contentText = flash[2].substr(0, 200) + '...';
                    newsFlashContent.innerHTML = flash[2];
                    FadeUp(newsFlashBar);
                    BlinkNewsFlash();
                }
            } else {
                newsFlashBar.style.visibility = 'hidden';
                //newsFlashText.style.visibility = 'hidden';
            }
        }
    }

    ajax.AsynchronousGet('getnewsflash.php' + header);

}

function highlightNewsFlash(mouseover) {

    var newsFlashBar = document.getElementById('newsFlashBar');
    var newsFlashContent = document.getElementById('newsFlashContent');
    newsFlashContent.style.top = newsFlashBar.offsetHeight + newsFlashBar.offsetTop + 'px';

    if (mouseover) {
        newsFlashBar.style.backgroundColor = '#1177bb';
        newsFlashContent.style.visibility = 'visible';
    } else {
        newsFlashBar.style.backgroundColor = '#006699';
        newsFlashContent.style.visibility = 'hidden';
    }

}

// -- EOF -- //
/**
 * HalogenLABS © Halogen Graphics and Digital Design CC 2010
 * http://www.halogenlabs.co.za
 */
