document.observe('dom:loaded', function () {
	// fade from one news item into another
	$$('.news .flash').each(function (side) {
		
		var news_items = side.select('div.vx_block'), counter = 0, max_height = news_items.invoke('getHeight').max();
		
		side.setStyle({
			position: 'relative',
			height: (max_height + 50) + 'px'
		});
		
		news_items.invoke('hide').invoke('setStyle', {
			position: 'absolute',
			backgroundColor: '#ffffff',
			height: (max_height + 50) + 'px'
		});
		news_items.first().show();
		
		new PeriodicalExecuter(function () {
			Effect.Fade(news_items[counter]);
			counter = (counter == news_items.length - 1) ? 0 : counter + 1;
			Effect.Appear(news_items[counter]);
		}, 8);
	});
	
	(function () {
		var home_page_news = $$('div.news_holder').invoke('hide');
		if (home_page_news.length > 0) {
			home_page_news[0].show();
			var home_page_news_counter = 0;
			new PeriodicalExecuter(function () {
				home_page_news[home_page_news_counter].setStyle({zIndex : 10 });
				Effect.Fade(home_page_news[home_page_news_counter]);
				home_page_news_counter = (home_page_news_counter == home_page_news.length - 1) ? 0 : home_page_news_counter + 1;
				home_page_news[home_page_news_counter].setStyle({zIndex : 20 });
				Effect.Appear(home_page_news[home_page_news_counter], { delay: 0.3 });
			}, 8);
		}
	})();
	
	
	
	// add the 'first' classname to help lists float properly
	$$('.main .submenu ul li:nth-child(4n)').invoke('addClassName', 'first');
	
	// reorder the list down instead of across. this can be tidied
	$$('.main .list ul').each(function (list) {
		var items = list.select('li'),
			length = parseInt(items.length / 2, 10),
			half = (0 === items.length % 2) ? length - 1 : length,
			items = items.partition(function (member, index) { return (index <= half) ? true: false; }),
			top = items[0],
			bottom = items[1];
		items.invoke('invoke', 'remove');
		items = top.zip(bottom);
		items.each(function (item) {
			$A(item).each(function (element, index) {
				if (0 === index % 2) {
					element.addClassName('even');
				}
				list.insert(element);
			});
		});
	});
	
	// the modal box code
	$$('.gallery .photo a').invoke('observe', 'click', function (event) {
		event.stop();
		var href = this.href,
			modalbox = new Element('iframe', {
				src: href,
				width: 640,
				height: 428,
				scrolling: 'no',
				border: 0,
				className: 'modalbox' }),
			fader = new Element('div', { className: 'fade' }),
			close = new Element('div', { className: 'close' });
		
		$(fader, close).invoke('observe', 'click', function (event) {
			event.stop();
			$(fader, modalbox, close).invoke('remove');
		});
		
		close.insert(new Element('a', { href: '#close' }).update('Close&nbsp;&times;'));
		
		$(fader, modalbox, close).invoke('hide');
		$(document.body).insert({ top: fader });
		$(document.body).insert({ top: close });
		$(document.body).insert({ top: modalbox });
		
		new Effect.Parallel([Effect.Appear(modalbox), Effect.Appear(fader, {
			from: 0,
			to: 0.7
		}), Effect.Appear(close)]);
	});
	
	// add Of Counsel to Paul Bowman's name
	$$('#content .main .list ul li a[href$=/paul-bowman.asp]').invoke('insert', ' <span>*&nbsp;Of&nbsp;Counsel</span>');
	
	$$('.column.main .vx_menu.submenu.clearfix').each(function (menu) {
		var menu_items = menu.select('li');
		
		if (menu_items.size() == 4) {
			// var spacer = new Element('li', { style: 'border:0' });
			// option 1
			menu_items[0].setStyle({ marginLeft: '20px' });
			menu_items[1].setStyle({ paddingLeft: '20px' });
			menu_items[2].setStyle({ clear: 'left', border: 'none', marginLeft: '20px', paddingLeft: (Prototype.Browser.IE) ? '7px' : '0' });
			menu_items[3].removeClassName('first').setStyle({ paddingLeft: '20px' });
			
			// option 2
			// menu_items.invoke('setStyle', { marginLeft: '20px', paddingLeft: '20px' });
		}
		
		if (menu_items.size() == 2) {
			// var spacer = new Element('li', { style: 'border:0' });
			// option 1
			menu_items[0].setStyle({ marginLeft: '20px' });
			menu_items[1].setStyle({ paddingLeft: '20px' });
			
			// option 2
			// menu_items.invoke('setStyle', { marginLeft: '20px', paddingLeft: '20px' });
		}
	});
});

// VALIDATES THE SPECIALIST AREA SEARCH FORM AGAINST NULL VALUES
function validate_search(form) {

	if (form.topics.value == "" || form.subtopics.value == "") {

		alert("Please select a topic and sub topic");
		return false;
	
	} else { 
	
		return true;
		
	}


}


function reload_iframe(video_code) {

	var oiframe = document.getElementById("vimeo_player");
	oiframe.contentWindow.location.replace("http://player.vimeo.com/video/" + video_code);
	
	return true;

}


