/*
These 3 functions are for the news article page and will create a video player and rollover
*/

var createVideoPlayer = function(option) {

	/*if (option == undefined) {
		option = Math.floor(Math.random()*2)+1;	
	}

	$('hero').empty();*/
	if (typeof(videoURL)!="undefined") {
		var videoPlayerObject = new Swiff('/flash/videoplayer.swf', {
    		id: 'videoPlayer',
			name: 'videoPlayer',
    		width: 526,
    		height: 266,
   			params: {
        		wmode: 'transparent',
        		bgcolor: '#FFFFFF',
      			loop: 'false',
				menu: 'false',
        		quality: 'high',
      			scale: 'noscale',
				allowScriptAccess: 'always',
	    		allowFullScreen: 'true',
				play: 'true'
    		},
			vars: {
        		videoURL: videoURL,
				videoTitle: videoTitle
    		}
		});

		videoPlayerObject.inject($('holder_video'));
	}

}


var doHolder = function() {
	if ($('holder')) {
		theElement = 0;
		$('holder').getChildren('div').each(function(el){
			el.getFirst('h4').addEvent('mouseover', doHolderFocus);
			el.getFirst('h4').addEvent('mouseout', function(){this.removeClass('over');});
			el.setStyle('zIndex', 10);
			theElement = el;
		});
	
		theElement.setStyle('zIndex', 20);
		theElement.getFirst('h4').addClass('selected');
		theElement.getFirst('h4').get('tween').start('height', 26);
	}
}

var doHolderFocus = function() {
	this.addClass('over');
	if (theElement != this.getParent()) {
		theElement.getFirst('h4').removeClass('selected');
		theElement = this.getParent();
		this.addClass('selected');
		this.get('tween').start('height', 26);
		$('holder').getChildren('div').each(function(el){
			if (el == theElement) {
				el.setStyle('zIndex', 20);
			} else {
				el.setStyle('zIndex', 10);
				el.getFirst('h4').get('tween').start('height', 23);
			}
		});
	}
	if (theElement != $('holder_video')) {
		//Call flash and tell it to stop playing!
		Swiff.remote($('videoPlayer'), 'pauseVideo', '0');
	} else {
		Swiff.remote($('videoPlayer'), 'playVideo', '0');
	}
}

window.addEvent('domready', doHolder);
window.addEvent('domready', createVideoPlayer);

/*
These 2 functions are for the news archive list
*/

theElement = 0;

var doBanner = function() {

	$$('.news_archive_date').each(function(el){
		el.addEvent('mouseover', doExpand);
	});
	
	
	$$('.news_archive_list').each(function(el) {
		el.setStyle('height',0);
		//el.setStyle('opacity',0);
		el.getChildren().each(function(el1) {
			el1.setStyle('opacity',0);	
			el1.get('tween',{duration:300,onComplete:function(el){
				if (el.getNext()) {
					el.getNext().get('tween').start('opacity',1);	
				}
			}});
		});
	});
	
}

var doExpand = function() {
	if (theElement != this.getNext()) {
		if (theElement != 0) {
			theElement.get('tween',{duration:500,onComplete:function(el){
				el.getChildren().each(function(e){
					e.setStyle('opacity',0);
				});
			}}).start('height',0);
		}
		theElement = this.getNext();
		theHeight = 0;
		theElement.getChildren().each(function(el){
			theHeight += el.getHeight();								   
		});
		theElement.get('tween',{duration:700,onComplete:function(el){
			//el.getFirst().get('tween').start('opacity',1);													 
		}}).start('height',theHeight);
		
		(function(){theElement.getFirst().get('tween').start('opacity',1)}).delay(200);
		
		/*theElement.getChildren().each(function(e){
			e.get('tween',{duration:300,onComplete:function(el){
				if (el.getNext()) {
					el.getNext().get('tween').start('opacity',1);	
				}
			}});
		});*/
		
		
	}
}


window.addEvent('domready', doBanner);