$(document).ready(
	function() {
		$('#pull').css('display', 'none');
		$('#howtoTab').css('cursor', 'pointer').click(function() {
			if ($('#pull').is(':hidden')) {
				$('#pull').slideDown('slow');
			}
			else {
				$('#pull').slideUp();
			}
		}).slideDown('slow');
		
		$(".bnr").each(function (i) {
			if ($(this).children().length > 0) {
				var cnt = i+1;
				if (cnt < 10) cnt = '00' + cnt;
				else if (cnt > 10 && cnt < 100) cnt = '0' + cnt;
				
				var ul = $(this).parent();
				var li = $(ul).children('li')[1];
				$(ul).append('<li><textarea><a href="http://www.skydiveguam.com/" target="_blank"><img src="http://www.skydiveguam.com/banner/' + cnt + '.gif" alt="スカイダイブグアム" width="140" height="140" style="border:solid #E6E6E6 10px" /></a></textarea></li>');
				$(ul).append('<li><img src="_img/close.gif" alt="閉じる" width="15" height="15" /></li>');
				$(li).append('<img src="_img/btn.gif" alt="バナーを貼る" width="92" height="25" />');
				
				$($(li).children('img')[1]).css('cursor', 'pointer').click(function() {
					var ul = $(this).parent().parent();
					var li = $(ul).children('li')[2];
					
					if ($(li).is(':hidden')) {
						$(li).slideDown('slow', function() {
							//var t = $(this).children()[0];
							//t.focus();
							//t.select();
						});
						$($(ul).children('li')[3]).toggle();
					}
					else {
						$(li).slideUp();
						$($(ul).children('li')[3]).toggle();
					}
				});
				
				var t = $($(ul).children('li')[2]).css('display', 'none').children()[0];
				$(t).click(function() {
					this.focus();
					this.select();
				});
				
				$($(ul).children('li')[3]).css({'display':'none', 'cursor':'pointer'}).click(function() {
					if ($($(this).parent().children('li')[2]).is(':visible')) {
						$($(this).parent().children('li')[2]).slideUp();
						$($(this).parent().children('li')[3]).toggle();
					}
				});
			}
		});
	}
);

var trace = function(param) {
	console.log(param);
}