$(function(){
	UpdateThisPage.init( 'update-this-page-container', 'update-this-page', 'update-page-self', 'update-page-wsms' );
});


UpdateThisPage = function(){
	
	var container, button, linkbackid, updateSelf, updateWSMS;
	var server = 'http://edit:9992/Rhythmyx/linkback/aa?perc_linkback=';
	
	return {
		/*
		 * c = container id
		 * b = updatethispage id
		 */
		init : function(c, b, s, w){
			
			container = $('#' + c);
			update = $('#' + b);
			updateSelf = $('#' + s);
			updateWSMS = $('#' + w);
			
			linkbackid = $('meta[name=perc_linkback]').attr( 'content' );
			
			container.hide();
			
			update.click( function(e){
				e.preventDefault();
				container.show();
				$.facebox(container);
				$("#facebox .body").css( 'background', '#fff url(/resources/images/journalist-writing-latest-news-small200.jpg) no-repeat 95% 40%' );
			});
			
			updateSelf.click( function(e){
				e.preventDefault();
				//document.location.href = $(this).attr('href') + escape(linkbackid);
				window.open( $(this).attr('href') + escape(linkbackid) );
				$.facebox.close();
			});
			
			updateWSMS.click( function(e){
				e.preventDefault();
				//document.location.href = $(this).attr('href') + '&cmsLink=' + escape(linkbackid);
				window.open( $(this).attr('href') + '&cmsLink=' + escape(linkbackid) );
				$.facebox.close();
			});
			
		}
	};
}();
