$(document).ready(function(){
	if(!jQuery.browser.msie) $('.corner').corners()

	$('#new_list_a').click(function(){
		$('#new_list').dialog('open')
	})

	$('#add_sticky_note').click(function(){
		$('#add_sticky').dialog('open')
	})

	$('#add_sticky').dialog({
		modal: true,
		overlay: {
			opacity: 0.5,
			background: '#000'
		},
		height:'300px',
		width:'352px',
		draggable: false,
		resizable: false,
		autoOpen:false
	})

	$('#new_list').dialog({
		modal: true,
		overlay: {
			opacity: 0.5,
			background: '#000'
		},
		height:'330px',
		width:'352px',
		draggable: false,
		resizable: false,
		autoOpen:false
	})
	
	if($('.quick_sticky'))
	{
		$('.quick_sticky').draggable({
			opacity: 0.5,
			stop: function(e, ui) {
				$.post('/stickies/position/', {
					top: ui.position.top,
					left: ui.position.left,
					id: this.id
				})
				
			}
		})
		$('.quick_sticky').resizable({
			stop: function(e, ui)
			{
				$.post('/stickies/size', {
					height: ui.size.height,
					width: ui.size.width,
					id: this.id
				})
				
				this.height = ui.size.height
			},
			minHeight:'100'
		});						
		
		$('.quick_sticky>span>a>img').each(function(){
			$(this).click(function(){
				$.post('/stickies/delete', {id:this.id})
				$($($($(this).parent()[0]).parent()[0]).parent()[0]).remove()
			})
		})
		
		$('.quick_sticky>p').each(function(){
			$(this).editable("/stickies/update/" + $($(this).parent()[0]).attr('id'), { 
				indicator: "updating...",
				tooltip: "Double click to edit...",
				event: "dblclick",
				submit: 'Update',
				name: 'sticky_text',
				cssclass: 'inplaceEdit',
				type: "autogrow",
				autogrow: {
					maxHeight: ($($(this).parent()[0]).height() - 35)
				}
		  })
		
		})
	}
})				
