(function($){
	/**
	 * init
	 */
	$(function() {
		// message
		if(typeof message === 'string' && $.trim(message) != '') {
			setTimeout(function() {alert(message);}, 1);
		}
	});
	
	/**
	 * cookie
	 * get : $.cookie(key)
	 * set : $.cookie(key, value [,options])
	 */
	$.cookie = function(key, value, options) {
		if (arguments.length > 1) {
			var o = $.extend({}, $.cookieOptions, options);
	        if (value === null || value === undefined) {
	            value = '';
	            o.expires = -1;
	        }
	        if (o.expires.constructor != Date) {
				var today = new Date();
				today.setDate(today.getDate() + o.expires);
				o.expires = today;
			}
			// Create the cookie string
			document.cookie = 
				key + '=' + value +
				'; expires=' + o.expires.toUTCString() +
				(o.path? '; path=' + (o.path) : '') +
				(o.domain? '; domain=' + (o.domain) : '') +
				(o.secure? '; secure' : '');
		} else {
			if (result = new RegExp(key + '=(.*?)(?:;|$)').exec(document.cookie))
				return decodeURIComponent(result[1]);
			return '';
		}
	};
	$.cookieOptions = {
		expires: 365,
		path: '/'
	};
	
	// String prototype extend
	$.extend(String.prototype, {
		// 숫자만 가져오기
		num: function() {
			return $.trim(this).replace(/[^0-9]/g, '');
		}
	});
	
	// mask
	$.mask = function(fn) {
		$('#mask').css({width: $(window).width(), height: $(document).height(), opacity: 0.7}).fadeIn('slow', fn || function() {});
	}
	
	// vod click
	$('a.moviedata').live('click', function(e) {
		e.preventDefault();
		
		var vod = $(this).attr('title');
		var html = '';
		html += '<object id="flashplayerlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="611" height="454">';
		html += '<param name="movie" value="/flash/project_player.swf?flvpath=' + vod + '" />';
		html += '<param name="wmode" value="transparent" />';
		html += '<!--[if !IE]> <-->';
		html += '<object type="application/x-shockwave-flash" data="/flash/project_player.swf" width="611" height="454">';
		html += '<param name="wmode" value="transparent" />';
		html += '<param name="flashvars" value="flvpath=' + vod + '" />';
		html += '<!--> <![endif]-->';
		html += '<p>동영상 자료</p>';
		html += '<!--[if !IE]> <-->';
		html += '</object>';
		html += '<!--> <![endif]-->';
		html += '</object>';
		
		$('#flash').css('left', $(window).width() / 2 - 305).html(html);
		$.mask(function() {
			$('#flash').show();
		});
	});
	
	$('#mask, #flashplayerlayer, #flash').live('click', function() {
		$('#flash').html('').hide(function() {
			$('#mask').fadeOut();
		});
	});
	
})(jQuery);


/**
 * Small plug-in
 */
(function($) {
	/**
	 * iframe upload
	 */
	$.fn.fileUpload = function(url) {
		return $(this).each(function() {
			var frame = $('<iframe frameborder="0" name="file" src="' + url + '"></iframe>');
			frame.insertAfter($(this)).css({
				width: $(this).width(),
				height: $(this).height(),
				overflow: 'hidden',
				zIndex: 99,
				position: 'absolute',
				marginLeft: -($(this).width()),
				opacity: 0
			});
		});
	};
	
	/**
	 * 숫자만 입력 받기
	 */
	$.fn.onlyNum = function() {
		return $(this).each(function() {
			if($.browser.msie) {
				$(this).css({imeMode: 'disabled'}).keypress(
					function(e) {
						if(e.keyCode < 48 || e.keyCode > 57) {
							e.preventDefault();
						}
					}
				);
			} else {
				$(this).keypress(function() {
					$(this).val($(this).val().num());
				}).blur(function() {
					$(this).val($(this).val().num());
				}).keyup(function() {
					$(this).val($(this).val().num());
				}).keydown(function() {
					$(this).val($(this).val().num());
				});
				
			}
		});
	};
	
	$.fn.calendar = function() {
		setTimeout(function() {
			$('#ui-datepicker-div').css('z-index', 9999);
		}, 10);
		
		$(this)
			.attr({readonly: 'readonly'})
			.css({
				background: 'url(/images/admin/icon_calendar.gif) 110% center no-repeat'
			})
			.datepicker({
				dateFormat: 'yy.mm.dd',
				monthNames: ['01.', '02.', '03.', '04.', '05.', '06.', '07.', '08.', '09.', '10.', '11.', '12.'],
				dayNamesMin: ['일', '월', '화', '수', '목', '금', '토']
			});
	};
	
})(jQuery);

function playerClose() {
	$('#flash').html('').hide(function() {
		$('#mask').fadeOut();
	});
};
