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();
    });
});

/*
var body, sitemap, breadcrumb;
window.addEvent('domready', function() {

	body = $('body');
	
	// fix navigation hover
	if (Browser.Engine.trident4) { // ie6
		$('navigation').getElements('ul.menu>li').addEvents({
			'mouseenter': function() {
				this.addClass('hover');
			},
			'mouseleave': function() {
				this.removeClass('hover');
			}
		});
	}

	// apply sub-menu opacity
	$('navigation').getElements('ul.menu ul').setOpacity(0.85); // todo: only apply to first child

	// generate breadcrumb
	sitemap = new Sitemap('navigation');
	breadcrumb = new Breadcrumb('breadcrumb');

	// set page class
	//body.addClass(sitemap.map[sitemap.page].className);
	body.addClass(sitemap.page.replace(/\//g, ' '));
	
	// apply style to striped tables
	body.getElements('table.striped tr:even').addClass('odd');
});


var Sitemap = new Class({
	initialize: function(el) {
		
		this.el = $(el);
		this.anchors = this.el.getElements('li a[href!=#]');

		this.host = window.location.host;
		this.page = window.location.pathname;
		this.map = [];
		this.regex = {
			page: new RegExp('^/(?:web/|)(.*?)(?:/default|)(?:\.aspx|)$', 'ig'),
			href: new RegExp('^http(?:s{0,1})://' + this.host + '(/.*$)', 'i'),
			site: new RegExp('^/(.*?)/(?:.*)$', 'i')
		}; this.regex.page.exec(this.page);
		this.page = '/' + RegExp.$1; this.regex.site.exec(this.page);
		this.site = RegExp.$1;
		this.home = '/' + this.site + '/home';

		this.anchors.each(function(el, index) {
			var href = el.href.replace(this.regex.href, '$1');
			this.map[href] = {
				href: href,
				name: (Browser.Engine.trident ? el.innerText : el.text),
				className: el.getParent('li').id.replace(/^m-(.*)$/, '$1')
			}
		}, this);
	}
});

var Breadcrumb = new Class({
	initialize: function(el) {

		this.page	= sitemap.page + '/';
		this.el		= $(el); this.render();
		var back	= new Element('a', {
			'href': 'javascript:history.back()',
			'html': 'Back',
			'class': 'back'
		}).inject(this.el, 'top');
	},
	render: function() {
		if (this.page.indexOf('/') != this.page.lastIndexOf('/')) {
			var item = sitemap.map[this.page];
			if (item) {
				var el = new Element('a', {
					'href': item.href,
					'html': item.name.htmlEncode()
				}).inject(this.el, 'top');

				//$('body').addClass(item.className);
			}

			this.page = this.page.substring(0, this.page.lastIndexOf('/'));
			this.render();
		} else {
			var item	= sitemap.map[sitemap.home];
			var el		= new Element('a', {
				'href': item.href,
				'html': item.name,
				'class': 'home'
			}).inject(this.el, 'top');
		}
	}
});
*/
