/**
 * @member $.sydnews
 */
(function($){
	var gopts={};
	/**
	 * @private
	 * @memberOf $.sydnews
	 */
	function inpage() {
		// replace links in page by loading within the div
		$('.nwslink,.nwsfolderslink').click(function(e){
			e.preventDefault();
			var url = $(this).attr('href');//+'/sydneylayout/no';
			$('.nwslist').html('Loading...').load( url, {'sydneylayout' : 'no'} );
		});
		// autoload one news if any
		var loc = window.location.toString();
		var la = loc.split('/');
		for (var i=0; i < la.length-1; i++)
		{
			var k = la[i];
			var v = la[i+1];
			if (k == 'id') break;
		}
		if (k == 'id') $('.nwslist').html('Loading...').load('/publicnews/index/viewone/id/'+v, { 'sydneylayout' : 'no' } );
		//$('.nwslist').html('Loading...').load(loc, {'sydneylayout' : 'no'} );
	};
	/**
	 * @private
	 * @memberOf $.sydnews
	 */	
	function directlink()
	{
		var o = gopts;
    	$('a.nwslatestlink').click(function(e){
			e.preventDefault();
			var url = $(this).attr('href');
			var up = url.split('/');
			var para = '';
			for (var i=4; i < up.length; i++) para += '/'+up[i];
			window.location =  o.url+para;
		});
	};
	/**
	 * @constructor
	 */
	$.sydnews = function(opts)
	{
		gopts = opts;
		if ( gopts.mode == 'inpage' ) inpage();
		if ( gopts.mode == 'directlink' ) directlink();
	};

})(jQuery);

