/**
 * @author frukt
 */

function generateButtons(id, attribs){
	var params = {
		'basePath': '',
		'extensionName': 'ext_gallery',
		'parentId': 0,
		'objectId': 0,
		'position': 0,
		'currentOp': '',
		'hidden': false,
		'inEditor' : false
	};
	Object.extend(params, attribs);
	
	var buttons = new DOMBuilder([
		'div', {
			'class': 'saurusEditorMenu'+(params.hidden ? ' arrowHidden' : ''),
			'events' : {
				'click' : function(){
					var menu = $(this).getElementsByTagName('ul')[0];
					menu.setStyle('display', 'block');
					menu.setStyle('z-index', '10000');
					
					if(params.hidden){ $(this).addClass('arrowHidden'); }
					$(this).addClass('arrowSelected');
				}
			}
		},
			['ul', {
				'events': {
					'mouseleave': function(){
						$(this).setStyle('display', 'none');
						$(this).setStyle('z-index', '');
						$(this).getParent().removeClass('arrowSelected');
					}
				}
			},
				['li',
					['a', {'href': params.basePath+'/extensions/'+params.extensionName+'/admin/edit.php?op='+params.currentOp+'&parent='+params.parentId+'&kesk='+params.position, 'rel':'popup[450,430]'},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/new.png', 'alt':''}],
						['span', 'New']
				]],
				['li',
					['a', {'href': params.basePath+'/extensions/'+params.extensionName+'/admin/edit.php?op='+params.currentOp+'&id='+params.objectId+'&parent='+params.parentId+'&kesk='+params.position, 'rel':'popup[450,430]'},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/edit.png', 'alt':''}],
						['span', 'Edit']
				]],
				['li',
					['a', {'href': params.basePath+'/admin/move.php?url='+escape(params.basePath+(params.inEditor ? '/editor' : ''))+'%3Fid%3D'+params.parentId+'&op=up&id='+params.objectId+'&kesk='+params.position},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/moveup.png', 'alt':''}],
						['span', 'Move Up']
				]],
				['li', 
					['a', {'href': params.basePath+'/admin/move.php?url='+escape(params.basePath+(params.inEditor ? '/editor' : ''))+'%3Fid%3D'+params.parentId+'&op=down&id='+params.objectId+'&kesk='+params.position},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/movedown.png', 'alt':''}],
						['span', 'Move Down']
				]],
				['li',
					['a', {'href': params.basePath+'/admin/publish.php?url='+escape(params.basePath+(params.inEditor ? '/editor' : ''))+'%3Fid%3D'+params.parentId+'&id='+params.objectId+'&op='+(params.hidden ? "publish" : "hide")+'&parent_id='+params.parentId},
						['img', {'src':params.basePath+'/px/px.gif', 'alt':''}],
						['span', params.hidden ? 'Publish' : 'Hide']
				]],
				['li',
					['a', {'href': params.basePath+'/admin/delete.php?id='+params.objectId+'&parent_id='+params.parentId, 'rel':'popup[450,430]'},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/delete.png', 'alt':''}],
						['span', 'Delete']
				]
			]
		]
	]);
	
	buttons.injectInside(id);
}

function generateNewButton(id, attribs){
	var params = {
		'basePath': '',
		'extensionName': 'ext_gallery',
		'parentId': 0,
		'objectId': 0,
		'position': 0,
		'currentOp': '',
		'hidden': false,
		'inEditor' : false
	};
	Object.extend(params, attribs);
	
	var buttons = new DOMBuilder([
		'div', {
			'class': 'saurusEditorMenu'+(params.hidden ? ' arrowHidden' : ''),
			'events' : {
				'click' : function(){
					var menu = $(this).getElementsByTagName('ul')[0];
					menu.setStyle('display', 'block');
					menu.setStyle('z-index', '10000');
					
					if(params.hidden){ $(this).addClass('arrowHidden'); }
					$(this).addClass('arrowSelected');
				}
			}
		},
			['ul', {
				'events': {
					'mouseleave': function(){
						$(this).setStyle('display', 'none');
						$(this).setStyle('z-index', '');
						$(this).getParent().removeClass('arrowSelected');
					}
				}
			},
				['li',
					['a', {'href': params.basePath+'/extensions/'+params.extensionName+'/admin/edit.php?op='+params.currentOp+'&parent='+params.parentId+'&kesk='+params.position, 'rel':'popup[450,430]'},
						['img', {'src':params.basePath+'/extensions/'+params.extensionName+'/images/new.png', 'alt':''}],
						['span', 'New']
				]]
			]
	]);
	
	buttons.injectInside(id+'_newbutton');
}
