if (location != top.location) top.location.replace(location);

window.addEvent('domready', function() {

    // toshiba logo
    $$('#masthead h1').addEvent('click', function() {
        window.open('/home', '_self');
    });

    // global search
    $('submit').addEvent('click', function(e) {
        e.stop();
        var value = $('q').get('value').trim();
        if (value.length > 0)
            window.open('/search/?q=' + value, '_self');
    });

    // fix navigation hover
    if (Browser.Engine.trident4) { // ie6
        var select = $$('body.support div.wide #filters select');
        $('navigation').getElements('ul.menu>li').addEvents({
            'mouseenter': function() {
                this.addClass('hover');
                if (this.id.contains('green-toshiba'))
                    select.setStyle('visibility', 'hidden');
            },
            'mouseleave': function() {
                this.removeClass('hover');
                if (this.id.contains('green-toshiba'))
                    select.setStyle('visibility', 'visible');
            }
        });
    }

    // apply sub-menu opacity
    if (!(document.querySelectorAll && Browser.Engine.trident)) {
        $('navigation').getElements('ul.menu ul').setOpacity(0.85); // todo: only apply to first child
    }

    $$('div.buttons a.print').addEvent('click', function(e) {
        window.print();
    });

    // popup [intel]
    $('body').getElements('a[rel^=popup][rel*=intel]').addEvent('click', function(e) {
        e.preventDefault(); e.stopPropagation();
        new IntelPopup(this);
    });

});

var IntelPopup = new Class({
    Extends: Popup,
    initialize: function(item) {
        this.parent(item.href, { window: { height: 220, width: 360, resizable: true }});
    }
});

function SubmitOnEnter(field, e) {
    var keycode;

    if (window.event) 
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else 
        return true;

    if (keycode == 13) {
        var searchPath = '/search/';
		if (location.pathname.indexOf(searchPath) != -1) searchPath = location.pathname;
        window.location = searchPath + "?q=" + field.value;
        return false;
    }
    else
        return true;
}
