(function($) {
// Initialize editor
	if(livewhale.has_pages_editor) {
		var login = livewhale.getCookie('lw_pages_editor'), // get the login cookie
			initPagesEditor = function() {
				document.body.innerHTML='<div id="lw_page">'+document.body.innerHTML+'</div>'; // must happen before scripts are added to avoid webkit bug
				var head = $('head'),
					body = $('body');
				$.each(livewhale.pages_editor.styles,function() {
					head.append('<link rel="stylesheet" type="text/css" href="'+this+'"/>');
				});
				body.prepend(livewhale.pages_editor.html);
				$.each(livewhale.pages_editor.scripts,function() {
					var script = document.createElement('script');
					script.type='text/javascript';
					script.src=this;
					document.body.appendChild(script);
				});
			};
		if(login) { // if the login cookie exists
			if(livewhale.pages_editor) {
				initPagesEditor();
			} else {
				$.getJSON('?livewhale=ajax&function=getPagesEditorToolbar',function(data) { // get the toolbar
					if(data.html) { // (data has no properties if the login is invalid)
						livewhale.pages_editor = data;
				   		initPagesEditor();
				   	}
				});
			}				
		}
	}

// Common behaviors
	$('.lw_item_images').quickGallery(); // quick gallery for detail pages
// Gallery detail view

})(livewhale.jQuery);