function enableVideoPlayer(videoNodes)	{
        videoNodes.each(function() {
			config = {
				usePlayOverlay:true,
				clip: {
		            scaling: "fit",
		            autoBuffering: false,
		            autoPlay: true,
		            },
		
	            plugins:  {
					audio: {
						url: "%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.audio.swf",
					},						
					controls:  {
						url: "%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.controls.swf",
						volume:true,
						backgroundGradient: 'none',
						backgroundColor: 'transparent',
						all:false,
						scrubber:true,
						play: true,
						mute: true,
						time:true
					}	
				},

				canvas: {
					backgroundColor:'transparent',
					backgroundGradient: 'none'
				},
							
			}
			flowplayer(this, {src: "++resource++collective.flowplayer/flowplayer.swf", 
							  wmode: 'transparent'}, config).onLoad( function() { this.setVolume(50); });
        });
}



function realignBelowColumns(section1Selector, section2Selector, sectionToAlign, baseOffset){
		
	try {
		columnOnePosition = jq(section1Selector).position();
		columnOneHeight = jq(section1Selector).outerHeight();
		columnTwoHeight = jq(section2Selector).outerHeight();
	  	belowContentViewletPosition = columnOnePosition.top + Math.max(columnOneHeight, columnTwoHeight) + baseOffset;
		jq(sectionToAlign).css('top', belowContentViewletPosition);
		// movedEvent = jq.Event("JavaScriptLayoutChange");
		// jq(window).trigger(movedEvent);
	  }
	catch(err) {
	  //Handle errors here
	  }	

}

function enableMultiPromosScrollable () {
	try {
		// initialize scrollable and return the programming API

		var api = jq("#scroll").scrollable({
			items: '#tools'

		// use the navigator plugin
		}).navigator().data("scrollable");


		// this callback does the special handling of our "intro page"
		api.onBeforeSeek(function(e, i) {

			// when on the first item: hide the intro
			if (i) {
				jq("#intro").fadeOut("slow");

				// dirty hack for IE7-. cannot explain
				if (jq.browser.msie && jq.browser.version < 8) {
					jq("#intro").hide();
				}

			// otherwise show the intro
			} else {
				jq("#intro").fadeIn(1000);
			}

			// toggle activity for the intro thumbnail
			jq("#t0").toggleClass("active", i == 0);
		});

		// a dedicated click event for the intro thumbnail
		jq("#t0").click(function() {

			// seek to the beginning (the hidden first item)
			jq("#scroll").scrollable().begin();

		});
	
	} catch(err) {
		// ignore and pass
	}
}

jq(window).load(function(){
		
	/* BIG NEWS HOME PAGE - POSITION VIEWLETS BELOW CONTENT ON RHS  */
	columnOne = "body.template-bignewshomepage #portal-column-one";
	columnTwo = "body.template-bignewshomepage #portal-column-two";
	sectionToAlign = "body.template-bignewshomepage #viewlet-below-content";
	realignBelowColumns(columnOne, columnTwo, sectionToAlign, 0);
	/* END BIG NEWS HOME PAGE */
	
	/*** START GALLERIAS ***/
	
    // Initialize Galleria
    jq('#galleria').galleria();
	addClassicGaleriaTheme();

	/*** END GALLERIAS ***/
	
	/*** START SCROLLABLES***/
	
	enableMultiPromosScrollable();
	// jq("#wizard").scrollable();
	//var root = jq("#wizard").scrollable();
	
	/*** END SCROLLABLES ***/
	
	/*** START VIDEO PLAYBACK ***/
	
	// start video playback for anything with splash class
	enableVideoPlayer(jq('.splash'));
	
	/*** END VIDEO PLAYBACK ***/
		
});


