//plugin script
(function($) {
	$.fn.applySwiftDialog = function(options){
		var defaults = {
			linkMode: "self",			
			continueLabel: "Continue",
			actionLink: "javascript:void(0)",
			cancelLabel: "Cancel",
			applyPrettyButtons: true
		};
		var options = $.extend(defaults, options);
		var prettyButtonApplied = false;
		if(options.linkMode == "parent" && window.opener && !window.opener.closed) {
			var dialog = this;
			$(this).find("span.overlayLink").click(
				function(){				
					window.opener.location.href=options.actionLink;
					dialog.dialog("close");
				});
		} else {
			$(this).find("span.overlayLink").click(
				function() {
					window.location.href=options.actionLink;
				});
		}		
		var buttons = {};
		buttons[options.continueLabel] = function() {
			if (options.linkMode == "parent" && window.opener && !window.opener.closed) {
				window.opener.location.href = options.actionLink;
			} else {
				window.location.href = options.actionLink;
			}
			$(this).dialog("close");
		};
		buttons[options.cancelLabel] = function() {
			$(this).dialog("close");
		};
		$(this).dialog({
			buttons: buttons,
			draggable: true,
			modal: true,
			autoOpen: false,
			width: 350,
			height: 'auto',
			minHeight: 200,
			resizable: false,
			open: function(event, ui) {
				//FIXME work how out to apply prettyButton just the once.
				if(options.applyPrettyButtons && !prettyButtonApplied) {
					$(this).parent().find("button").prettyButton(
						{right: 13, left: 9, top: 30, bottom: -3, bgImagePre: imagePath + "image/GlowButtonSM_0", bgImageExt: "png"});
					//FIXME hack to add padding to top of smaller prettyButtons
					$("button div div").css("padding-top","6px");
					prettyButtonApplied = true;
				}
			}
		});
	};
})(jQuery);