﻿$(document).ready(function () {
	live.list();
	rank.load();
	$('input[name=comment]').inputfocus();
	$('#trailerimg').click(function () {
		$('.trailer_content').flash({
			'swf': 'http://www.youtube.com/v/ffBKMP7OkeE?version=3&autoplay=1&controls=0&rel=0',
			'width': 248,
			'height': 153, 
			'bgcolor': '#000000'
		}).show();
		$(this).hide();
	});
});




var live = {
	list: function () {
		$('.live_content').load('/home/livecomment');
	},

	submit: function () {
		var defaultmsg = 'Your message here!';
		var isLogin = arguments[0];
		var el = $('input[name=comment]');
		var comment = el.val();
		var nickname = $('input[name=nickname]').val();

		if (isLogin != 1) {
			alert('To post a message, you need to login or create nickname first.');
			return false;
		}

		if (comment == '' || comment == defaultmsg) {
			alert('Comment field cannot be left blank.');
			el.focus();
			return false;
		}

		$.post("/home/livecommentwrite",
            $("form[name=frmComment]").serialize(),
            function (data) {
            	alert(data.message);
            	if (data.result) {
            		el.val(defaultmsg).focusout();
            		live.list();
            	}
            },
            "json");

		return false;
	}
};


var rank = {
	load: function (server, course, type) {
		server = (typeof (server) == 'undefined') ? 'vallar' : server;
		course = (typeof (course) == 'undefined') ? 'alfheim' : course;
		type = (typeof (type) == 'undefined') ? 'total' : type;

		var path = '/ranking/mainranking/' + server + '/' + escape(course) + '/' + type;
		$('.ranking_content').load(path);
	}
};




