$(document).ready(function() {
	var jx = $(".rightadblock .skin_gen_tr");
	jx.click(function() {
		var div = $(".rightadblock .skin_gen_mcc > div").get(0);
		div.innerHTML = "";
		div.title = "";
		this.style.backgroundImage = "url('skin/gen_tir.png')";
		this.style.cursor = 'auto';
		delete this.title;
	});
	jx.each(function(x) {
		this.title = "Close";
	});
});

function addVideo(name, duration, w, h)
{
	var so = new SWFObject('/lib/player.swf',name+'_mpl',w,h+30,'9');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
	so.addParam('bgcolor','#0C3554');
	so.addVariable('duration',duration);
	so.addVariable('file',document.location.href + name + '.f4v');
	so.addVariable('backcolor','0C3554');
	so.addVariable('frontcolor','cccccc');
	so.addVariable('lightcolor','689EAA');
	so.addVariable('screencolor','000000');
	so.addVariable('playlistsize','200');
	so.addVariable('skin','/lib/stylish.swf');
	so.addVariable('stretching','none');
	so.write(name);
}

/************************ COMMENTS ************************/

function showCommentForm()
{
	$("#comment-prompt").slideUp("fast");
	$("#respond").show("slow");

	//var targetOffset = $("#comment-prompt").offset().top;
	//$('html,body').animate({scrollTop: targetOffset}, 1000);
	$.scrollTo('+=400px', 800, { axis:'y' });
}

function htmlspecialchars(string) { return $('<span>').text(string).html() }

$(document).ready(function() {
	$(".comment:odd").css('background-color', '#133C59');
	$(".admin-comment:even").css('background-image', "url(/darkstatic.gif)");
	$(".admin-comment:odd" ).css('background-image', "url(/static.gif)");
	
	$('#comment-form').submit(function() {
		var $t = $(this);
		var formData = $t.serialize();

		$t.find(':input').attr('disabled', 'disabled');
		$t.find(':submit').attr('value', 'Sending...');
		$('#comment-error').html('');

		$.ajax({
			type: "POST",
			url: '/postcomment.php',
			data: formData,
			success: function(r) {
				$t.find(':input').attr('disabled', false);
				$t.find(':submit').attr('value', 'Leave comment');

				var id = r.split(":", 1)[0];
				if (id != "ERROR") {
					$t.find('textarea').val('');
					if ($('#comment-list').length == 0) {
						$('#comment-prompt').before('<ul id="comment-list"></ul>');
					}
					$('#comment-list').css('display', 'block').append(r.substr(id.length+1));
					$('#comment-prompt').html("<a href='javascript:showCommentForm()'>Leave a comment?</a>").slideDown("fast");
					$("#respond").hide("slow");
					$('#comment-'+id).ready(function() {
						$('#comment-'+id).slideDown('slow');
					});
				} else {
					$('#comment-error').html(r.substr(id.length+1));
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$t.find(':input').attr('disabled', false);
				$t.find(':submit').attr('value', 'Leave comment');
				$('#comment-error').html(textStatus + '(' + htmlspecialchars(errorThrown) + ')');
			}
		});
		return false;
	});
});
