$(document).ready(function(){
	$('a[rel="external"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	offset = $('#wp').offset();
	$('#sc-ads').css('left',offset.left + 1020);
	$(window).scroll(function(){
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		var yOffset = ns ? pageYOffset : document.documentElement.scrollTop;
		$('#sc-ads').css('top', yOffset);
	});
	$(window).resize(function(){
		offset = $('#wp').offset();
		//alert(offset.left);
		$('#sc-ads').css('left',offset.left + 1020);
	});
	$('.clip-item img').click(function(){
		
		$('#clipPlay').remove();
		clipId = $(this).attr('title');
		$.ajax({
			type: "GET",
			url: "clip.php?id="+clipId,
			success: function(embed){
				$('#clip-box').append('<div id="clipPlay"><div class="clip-close-wp"><strong class="clip-close-btn"></strong></div><div class="clip-wp">'+embed+'</div></div>');
				$('.videoClose').click(function(){ 
					$('#clipPlay').remove();
				});
			}
		});
	});
	$('.comment-button').click(function(){
		var o = $(this);
		o.toggleClass('hide');
		var parentTag = $(this).parent().parent();
		var commentId = $(this).attr('rel');
		var match = $(this).attr('title');
		var home = match.split(" - ")[0];
		var away = match.split(" - ")[1];
		$.ajax({
			type: "GET",
			url: "comments.php?id="+commentId+"&r=" + new Date().getTime(),
			success: function(comment){
				parentTag.after('<tr id="detail_'+commentId+'"><td colspan="8" class="comment-box-td"><div class="comment-box">'+comment+'</div></td></tr>');
				o.after('<span title="'+commentId+'" class="remove-button"><img src="/images/close.gif" alt="ปิดคอมเมนต์" /></span>');
				$('.remove-button').click(function(){
					var parentTagComment = $(this).parent().parent().next();
					$(this).remove();
					parentTagComment.remove();
					o.toggleClass('hide');
				});
			}
		});
	});
	$('.checkButton').click(function(){
		var n = $('#number').val();
		//alert(n);
		$.ajax({
			type: "GET",
			url: "lottery.php?id="+n+"&r=" + new Date().getTime(),
			success: function(result){
				alert(result);
			}
		});
	});
	
});