window.addEvent('domready', function() {

	//Toggles more news and track users' awareness of interaction on Google Analytics
	if($('newsContainer')!=null){
		var moreNewsShown = 0;
		var moreNewsFx = new Fx.Tween('ol-news-set-one', {
			duration: 400, 
			transition: Fx.Transitions.Sine.easeOut, 
			onStart: function(){if(moreNewsShown==0){moreNewsShown=0;}}, 
			onComplete: function(){
				if(moreNewsShown==0){
					moreNewsShown=1;
					return loadNewsThumbs();
					//Google Analytics : will only be tracked once for this interaction
					pageTracker._trackPageview("home/_JS_more-news" );
				}
			}
		});
		
		$('newsMore').set('href','#');
		$('newsMore').addEvent('click', function(event){
			event.stop();
			elMarginLeft = $('ol-news-set-one').getStyle('margin-left');
			if (elMarginLeft=='0px' ||elMarginLeft== null) {moreNewsFx.start('margin-left', '-560');$('newsMore').setStyle('backgroundPosition','right -20px');}else {moreNewsFx.start('margin-left', '0');$('newsMore').setStyle('backgroundPosition','right 0px');}
		});
	}
	
	//Tracks external outbound links using GA
	if(pageTracker){ 
		$$('a.outbound','area.outbound').each(function(el){
			el.addEvent('click', function(){
				var trackCurrentPage = (document.URL.replace(document.domain+'/','').replace('http://',''));
				trackCurrentPage = (trackCurrentPage=="") ? (document.URL.replace('http://www.','')).replace('/','') : trackCurrentPage;
				var trackOutboundURL = (el.get('href').replace('http://www.','')).replace('http://','');
				var tracklink = '/outbound/<FROM>'+trackCurrentPage+'<TO>'+trackOutboundURL;
				pageTracker._trackPageview(tracklink);
			});
		});
	}

	

var hoverBackground= $$('#divNav li').each(function(el){
   if(el.id!=='current' && Browser.Engine.trident4==true){
		el.addEvent('mouseenter',function(){el.addClass('navHover');});
		el.addEvent('mouseleave',function(){el.removeClass('navHover');});
	}
});

	if($('welcome')!=null){

		var colorCandy = new Fx.Morph('welcome',{
			duration: 2800
		});
		
		var textColorLoop = function(){
			colorCandy.start('.text-green').chain(
				function(){this.start('.text-yellow')},
				function(){this.start('.text-orange')},
				function(){this.start('.text-red')},
				function(){this.start('.text-pink')},
				function(){this.start('.text-purple')},
				function(){this.start('.text-blue')},
				function(){this.start('.text-green')}
			);
		};
		
		textColorLoop.periodical(1000);	
	}
	
	

var mySmoothScroll = new SmoothScroll({
	duration: 500,
    links: '.smoothAnchors',
    wheelStops: false
});

});


window.addEvent('load',function(){
	KytePlayer();//call the function to embed Kyte player
	AudioVideoKytePlayer();//call the function to embed Kyte Player on Audio Video section
});


function loadNewsThumbs(){//function to load the reminded of the News thumb when a user initiates on more news
	var newsImageArrayAnchor = $$('#ol-news-set-two a.more-news-images').getProperty('id');

	
	newsImageArrayAnchor.each(function(el){
		var elTitle = $(el).getProperty('title');
		var elRel = $(el).getProperty('rel');
		$(el).removeProperty('rel');
		var myImage = new Asset.image(elRel, {alt: elTitle, onload:function(){this.inject(el);}, onerror: function(){alert('error');}});
	});
	

	return;
}


function KytePlayer(){
	if($('divKytePlayer')!=null && (Browser.Plugins.Flash.version >= 9)){
		var obj = new Swiff('http://www.kyte.tv/flash.swf?v=2&uri=channels/109965&appKey=MarbachViewerEmbedded&embedId=49226040', {
			id: 'kytevideo-bernardtomic',
			container : 'divKytePlayer',
			width: 300,
			height: 305,
			params: {
				wmode: 'opaque',
				bgcolor: '#444444',
				allowFullScreen: 'true',
				allowScriptAccess: 'always',
				movie: "http://www.kyte.tv/flash.swf?v=2&amp;uri=channels/109965&amp;appKey=MarbachViewerEmbedded&amp;embedId=49226040"
			},
			vars: {
				v:2,
				uri:'channels/109965',
				embedId:'49226040',
				appKey:'MarbachViewerEmbedded',
				disableShowNavigation:'false',
				hideProduceTab:'true',
				hideShowsTab:'true',
				preShowAction:'none',
				producerMode: 'never',
				premium:'false',
				postShowAction:'navForward'
			}
		});
	}
	if($('divKytePlayer')!=null && (Browser.Plugins.Flash.version <= 8)){
			$('divKytePlayer').set('html','<br /><br /><br /><br /><br /><br /><br /><br />You&rsquo;ll need Adobe Flash Player 9 plugin for the video player. Please click <a href="http://www.adobe.com/go/getflashplayer" target="_blank">here</a> to download');
	}
}

function AudioVideoKytePlayer(){
	if($('divSubMasthead').hasClass('sub-audio-video') && (Browser.Plugins.Flash.version >= 9)){
		var obj = new Swiff('http://www.kyte.tv/flash.swf?v=2&uri=channels/109965&appKey=MarbachViewerEmbedded&embedId=49226049', {
			id: 'kytevideo-bernardtomic',
			container : 'divSubMasthead',
			width: 850,
			height: 480,
			params: {
				wmode: 'opaque',
				bgcolor: '#444444',
				allowFullScreen: 'true',
				allowScriptAccess: 'always',
				movie: "http://www.kyte.tv/flash.swf?v=2&amp;uri=channels/109965&amp;appKey=MarbachViewerEmbedded&amp;embedId=49226049"
			},
			vars: {
				v:2,
				uri:'channels/109965',
				embedId:'49226049',
				appKey:'MarbachViewerEmbedded',
				disableShowNavigation:'false',
				layoutMode:'wide',
				hideShowsTab:'false',
				preShowAction:'none',
				producerMode: 'authorizedonly',
				premium:'true',
				postShowAction:'navForward',
				StartupAction: 'display:Menu'
			}
		});
	}
	if($('divSubMasthead').hasClass('sub-audio-video') && (Browser.Plugins.Flash.version <= 8)){
			$('divKytePlayer').set('html','<br /><br /><br /><br /><br /><br /><br /><br />You&rsquo;ll need Adobe Flash Player 9 plugin for the video player. Please click <a href="http://www.adobe.com/go/getflashplayer" target="_blank">here</a> to download');
	}
}