$(document).ready(function() {
	
	/**
	 * Make placeholders
	 */ 
	$("form li").each(function() {
		var label = $(this).find('label:hidden').text();
		$(this).find('input[type="text"], input[type="password"]').each(function() {
			$(this).prop('label', label);
			
			if ($(this).val() == '') {
				$(this).val(label);
			}
					
			$(this).focus(function() { 
				if ($(this).val() == label) $(this).val('');
			});			
			
			$(this).blur(function() {
				if ($(this).val() == '') $(this).val(label);
			});
		});
	});
	
	$("form").each(function() {
		$("form").submit(function() {
			$(this).find('input').each(function() {
				if ($(this).val() == $(this).prop('label'))
				{
					$(this).val('');
				}
			});
		});
	});
	
	/**
	 * Forms
	 */
	$(".confirm").click(function() {
		return confirm("Do you really want to continue?");
	});
	
	$(".confirm-dialog").click(function() {
		return confirm($(this).attr('title'));
	});
	
	$(".print").click(function() {
		window.print();
		return false;
	});
	
	/**
	 * Fancybox
	 */
	$("a[rel=fancybox]").fancybox({
		type: 'image'
	});	
	
	/**
	 * Message popup
	 */
	$("#popup-message").each(function() {
		$.fancybox({
			content: $(this).html(),
			onComplete: function() {				
				$('.popup-close').click(function() {
					$.fancybox.close();
					return false;
				});
			}
		});
	});
	
});

/**
 * Basename
 */
function basename(path) {
    return path.replace(/\\/g,'/').replace( /.*\//, '' );
}
