/**
 * Default.js
 */

var Player = {
	launch: function(url, start, end) {
		var width = 560;
		var height = 280;
		var options = 'width=' + width + 
			', height=' + height + 
			', left=' + (screen.availWidth - width) + 
			', top=' + (screen.availHeight - height) + 
			', toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=yes, scrollbars=no';
		url += (typeof start != 'undefined' ? '/start:' + start : '') + (typeof end != 'undefined' ? '/end:' + end : '');
		window.open(url, '', options);
	}
};

function login(message, url)
{
	if (typeof message == 'undefined' || message == null)
		message = '로그인이 필요한 서비스입니다.\n로그인 하시겠습니까?';
	
	if (confirm(message))
	{
		if (typeof url == 'undefined' || url == null)
			url = location.href;
		//if (typeof root == 'undefined' || root == null)
		//	root = location.protocol + '//' + location.host + '/';
		window.location = 'https://' + location.host + ROOT_URL + 'member/login?from=' + encodeURIComponent(url);
		
		return true;
	}
	
	return false;
}

function initTargetBlank(element_name)
{
	$$(element_name).each(function(element) {
		element.writeAttribute('target', '_blank');
	});
}

function truncate_with_comment(comment_class_name, space)
{
	if (!space)
		space = 0;
	
	$$('div.' + comment_class_name).each(function(comment) {
		var parent = comment.up();
		var bound_right = parent.cumulativeOffset().left + parent.getWidth();
		var comment_right = comment.cumulativeOffset().left + comment.getWidth();
		
		if (comment_right > bound_right)
		{
			var title = comment.previous();
			var width = parent.getWidth() - comment.getWidth() - 5 - space;
			title.setStyle({cssFloat: 'left', width: width + 'px'});
			comment.setStyle({cssFloat: 'right', lineHeight: title.getHeight() + 'px'});
		}
	});
}

function initWordbreakMp3Player(id) {
	var codebase = Prototype.Browser.IE ? 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' : '';
	$(id).update(' \
		<object id="WordbreakMp3Player" type="application/x-shockwave-flash" data="' + ROOT_URL + 'swf/wordbreak_mp3_player.swf" ' + codebase + 'width="0" height="0"> \
			<param name="movie" value="' + ROOT_URL + 'swf/wordbreak_mp3_player.swf" /> \
			<param name="AllowScriptAccess" value="always" /> \
		</object> \
	');
}

function alarmNewMessage()
{
	new PeriodicalExecuter(function() {
		var sound_player = $('WordbreakMp3Player');
		if (sound_player)
		{
			sound_player.SetVariable('method:setUrl', ROOT_URL + 'sound/new_msg.mp3');
			sound_player.SetVariable('method:play', '');
		}
		this.stop();
	}, 1);
}

var Window = {
	popup: function(url, width, height, resizable) {
		if (width == undefined)
			width = 600;
		if (height == undefined)
			height = 500;
		if (resizable == undefined)
			resizable = true;
		
		var options = 'width=' + width + 
			', height=' + height + 
			', toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=' + (resizable ? 'yes' : 'no') + ', scrollbars=yes';
		
		window.open(url, '', options);
	},

	closeAfterReload: function() {
		if (window.opener && !window.opener.closed)
			window.opener.location.reload();
		window.close();
	},
	
	getWidth: function() {
		return window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	},
	
	getHeight: function() {
		return window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	}
};

