Object.extend(Prototype.Browser, {
	IE6 : false /*@cc_on || @_jscript_version < 5.7 @*/,
	IE7 : false /*@cc_on || @_jscript_version == 5.7 @*/
});

(function() {
	var Jenkins = {
		Version: '1.3.2',
	
		clearForms: function()
		{
			$$('input[type=text]', 'textarea').each(function(f)
			{
				$(f).observe('focus', function() {
					if ( $F(f) === $(f).defaultValue ) {
						$(f).value = '';
					}
				}).observe('blur', function() {
					if ( $F(f).blank() ) {
						$(f).value = $(f).defaultValue;
					}
				});
			});
		
			$$('form .cancel').invoke('observe', 'click', function(e)
			{
				e.stop();
				$(this).up('form').reset();
			});
		},
	
		matchColumns: function()
		{
			var _match = function() {
				var height = 0;
				
				$$('div.column').each(function(column) {
					height = ( $(column).getHeight() > height ) ? $(column).getHeight() : height;
				}).invoke('setStyle', {
					minHeight : (height - 20) + 'px'
				});
			};
			
			_match();
			Event.observe(window, 'load', _match);
		},
	
		highlightMenu: function()
		{
			var page_link = document.location.href.replace(/^http:\/\/.+?\/([^\/])\/([^\/])$/, '../$1/$2');
			
			$$('#menu ul li a').each(function(link) {
				if ( link.href === page_link ) {
					link.addClassName('selected');
				}
			});
		},
		
		showHideForm: function() {
			if ( $('newsletter-signup-form') ) {
				var form = $('newsletter-signup-form');

				$('area').observe('change', function() {
					form.down('fieldset.hidden').show();
				});
			}
		},
		
		menuRollovers: function() {
			$$('#menu > ul > li').each(function(item)
			{
				$(item).observe('mouseover', function()
				{
					$$('#menu > ul > li > div > ul').invoke('hide').invoke('setStyle', {
						visibility: 'visible'
					});
					
					if ( $(item).down('div') ) {
						$(item).down('div > ul').show();
					}
				});
			});
		},
		
		breadCrumbs: function() {
			var page_name = document.title;
			page_name.sub(/Jenkins\s\|\s(?:Trade\sMark\sand\sPatent\sAttorneys\s\|\s)?(.+?)$/, function(match) {
				page_name = match[1];
			});

			var page_link = new Element('a', { href: window.location.href }).update(page_name);
			page_link = page_link.wrap('li');
			
			if ( typeof Vx == 'undefined' ) {
				try { $('breadcrumbs').down('ul').insert({ bottom: page_link }); } catch (no_breadcrumb) {}
			}
		},
		
		fixEmails: function() {
			$$('a[href]').each(function(link) {
				$(link).readAttribute('href').sub(/\/email\.asp\?name=(.+)$/, function(match) {
					if ( match[1] ) {
						$(link).writeAttribute({ href: 'mailto:' + match[1] + '@jenkins.eu' });
						$(link).update($(link).innerHTML.replace(/\(at\)/g, '@'));
					}
				});
			});
		}
	};

	document.observe('dom:loaded', function() {
		
		Jenkins.clearForms();
		Jenkins.showHideForm();
		Jenkins.menuRollovers();
		Jenkins.breadCrumbs();
		Jenkins.fixEmails();
		Jenkins.matchColumns();
		
	});
})();