﻿
function AddNewButton () {
    var container = document.id('UploadButtons');
    var button = new Element('input', { type: 'file' });

    container.grab(button);
}

window.addEvent('domready', function (optionId) {
    // Highlight the links that indicates the page we are viewing by looking at
    // the URI location.
    var pageUri = new URI(window.location);
    var fileName = pageUri.get('file') || '';
    var directory = pageUri.get('directory') || '';
    var host = pageUri.get('host') || '';

    console.log('Loaded directory: "' + directory + '" and fileName: "' + fileName + '"');
    console.log('Web site host: "' + host + '"');

    if (directory.match(/(20\d+)|category/i)) {
        // Modify the REGEX above when you want to highlight the BLOG link.
        console.log('(A) Looking for BLOG links');
        var objBlogLink = document.getElements('a[href$=/news/]');
        objBlogLink.addClass('hot');
    } else if (directory == '/') {
        // We have the home page.
        console.log('(B) Looking for ROOT links ending in: "a[href=/index.php]" or "a[href$=' + host + '/"');
        var objDefaultLink = document.getElements('a[href$=' + host + '/],a[href=/index.php]');
        objDefaultLink.addClass('hot');
    } else {
        console.log('(C) Looking for MENU links ending in: "a[href$=' + directory + ']"');
        var objLinks = (directory != '/') ? document.getElements('a[href$=' + directory + ']') : null;
        objLinks.addClass('hot');
    }  
    // Activate mouseover hovering for Menu items.
    var objMenuImages = $$('div.header-nav');

    objMenuImages.each(function (image) {
        if (!image.hasClass('hot')) {
            image.addEvent('mouseenter', function () {
                image.addClass('hover');
            });
            image.addEvent('mouseleave', function () {
                image.removeClass('hover');
            });
        }
    });

    // Activate mouseovers for all images in a page UNLESS it has a 'hot' class defined.
    var objHoverableImages = $$('img.hover');

    objHoverableImages.each(function (image) {
        if (!image.hasClass('hot')) {
            image.addEvent('mouseenter', function () {
                var source = image.get('src');

                image.set('src', source.replace(/\.(jpg|png)/i, '_on.$1'));
            });
            image.addEvent('mouseleave', function () {
                var source = image.get('src');

                image.set('src', source.replace(/_on\.(jpg|png)/i, '.$1'));
            });
        }
    });

});

