var agent = navigator.userAgent;
if(agent.match(/iPhone/i) || agent.match(/Windows CE/i) || agent.match(/Symbian/i) || agent.match(/BlackBerry/i) || agent.match(/Android/i) && page != "PC" )
	top.location.href='/mobile';

jQuery(function($)
{
	// 새창 처리
	$('a[rel="blank"]').click(function(e)
	{
		window.open($(this).attr('href'));
		e.preventDefault();
	});


	$('#martialarts-movie').find('div.cover').each(function(index)
	{
		var t = $(this),
			p = t.parent();

		t.css({
			'position' : 'absolute',
			'z-index' : '8888',
			'left' : 0,
			'top' : 0,
			'width' : p.width(),
			'height' : p.height(),
			'background-image' : 'url(/_library/common/images/bg_blank.gif)'
		});
	});

	$('#martialarts-movie').each(function(index)
	{
		var t = $(this),
			body = $('body'),
			video = t.find('video'),
			src = video.attr('poster'),
			bg = $('<div class="martialarts-movie-box"></div>'),
			screen = $('<div class="martialarts-movie-screen"><div class="video-area"></div></div>'),
			cover = $('<div class="martialarts-movie-cover"></div>'),
			cn='', vw=0, vh=0, ow=0, oh=0;
		
		ow = video.width();
		oh = video.height();

		try
		{
			cn = t.get(0).className;
			vw = (cn.match(/width\-([0-9]{1,})/i))[1];
			vh = (cn.match(/height\-([0-9]{1,})/i))[1];

			vw = !isNaN(vw) ? parseInt(vw, 10) : null;
			vh = !isNaN(vh) ? parseInt(vh, 10) : null;
		}
		catch(e)
		{
			vw = t.width();
			vh = t.height();
		}

		cover.css({
			'position' : 'absolute',
			'z-index' : '7777',
			'left' : 0,
			'top' : 0,
			'width' : t.width(),
			'height' : t.height(),
			'background-image' : 'url(/_library/common/images/bg_blank.gif)'
		});
		t.append(cover);
		cover.click(openBigMovie);

		bg.hide().css({
			'position' : 'absolute',
			'z-index' : '8888',
			'left' : 0,
			'top' : 0,
			'width' : body.width(),
			'height' : body.height(),
			'background-color' : '#000',
			'opacity' : 0.8
		});
		body.append(bg);
		bg.click(closeBigMovie);
		
		screen.hide().css({
			'position' : 'absolute',
			'z-index' : '8889',
			'left' : (body.width() - vw) / 2,
			'top' : (body.height() - vh) / 2,
			'background-color' : '#000',
			'border' : '5px solid #000',
			'text-align' : 'center'
		}).find('div.video-area').css(
		{
			'border' : '1px solid #fff',
			'width' :vw,
			'height' : vh
		});
		body.append(screen);

		var close = $('<span>닫기</span>');
		close.css({
			'display' : 'block',
			'padding' : '5px',
			'color' : '#555',
			'font-size' : '13px',
			'font-weight' : 'bold',
			'background-color' : '#000',
			'cursor' : 'pointer'
		});
		screen.append(close);
		close.click(closeBigMovie);


		function openBigMovie(e)
		{
			screen.find('div.video-area').append(video);
			video.attr('controls', true);

			bg.show();
			screen.show();

			try
			{
				video.get(0).play();
			}
			catch(e1){}

			e.preventDefault();
		}

		function closeBigMovie(e)
		{
			cover.before(video);
			video.attr('controls', false);

			bg.hide();
			screen.hide();

			try
			{
				video.get(0).stop();
			}
			catch(e1){}

			e.preventDefault();
		}
	});
});
