$(document).ready(function(){

	
	
	if($("#banner").children().size() != 0){
		 setTimeout(function() {
			//$("#banner").slideDown(1000);
			
			$("#banner").css("top", "2000px");
			$("#banner").show();
			
			$("#banner").animate({ 
				top: "140px"
			}, 2500);
		  }, 1000);
		
		$("#main").toggle(function () {
			$("#banner").fadeOut();
			},
			function () {
			$("#banner").fadeIn();
		}
		);
		
		$("#banner img").click(function(){
			location.href="event.html";								
		});

	}
	
	

	

	
	////////
	$(document.body).append('<div id="tabelog" style=""><img src="imgTop/ban_tabelog.gif" width="116" height="24"></div>');
	$("#tabelog img").click(function(){
			window.open("http://r.tabelog.com/chiba/A1202/A120204/12018732/", "_blank");
	});


	
	
	if($("#banner_event").size() != 0){

		$(document.body).append('<div id="twitter"><img src="images/twitarrow.png" id="twitarrow" /><a href="http://www.twitter.com/bijoujp" title="Follow us on Twitter" target="_blank" id="followbtn"><img src="images/follow_twitter_button_a.png" alt="Follow us on Twitter" width="121" height="24" /></a><div id="tweet"></div></div>');
		loadTweetData();
		$("#twitarrow").hide();
		$("#twitarrow").css({ left: "-1000px", width:"474px", height:"204px"});
		
		setTimeout(function() {
			$("#twitarrow").animate(
			{width: "120px", height: "53px", opacity: "100%", left:"-100px"},
			{duration: "slow", easing: "swing"})}, 1600);
		
			$("#twitter").toggle(
				function () {
					$(this).animate({right: "10px" }, 500 );
				},
				function () {
					$(this).animate({right: "-225px"}, 500 );
				}
				);
		
		$("#twitter a").click(function(){
							window.open($(this).attr("href"));
						});
		
		
		
		
			//$(document.body).append('<div id="space"><img src="imgTop/tropical.jpg" id="i6"><img src="imgTop/skk48.jpg" id="i2"></div>');

/*			$("#i1").hover(function () {
					$(this).css({opacity: "0.8"});
				  },
				  function () {
					$(this).css({opacity: "0.9"});
				  }
				);
			
			$("#space img").click(function(){
				$("#banner_event").hide();
				$("#banner_event").html("");
				var element = new Image();
				element.src = $(this).attr("src");
				element.onclick=function(){
				location.href="event.html";								
			}
			
			$("#banner_event").append(element).fadeIn("slow");
				
				
			});
			
			
			$("#main").click(function () {
				$("#banner_event").fadeOut();
				}
			);
		*/
		
		
	
	}
	
});



var recentID = 0;
var twitterID = 'bijoujp'


function init(data){
		
	$.each(data, function(i, val){
		//console.log(val.text);
		
		if(val.id > recentID){		
			var _d = new Date(val.created_at);
			var _ymd = new Array(_d.getYear()+1900, zero(_d.getMonth()), zero(_d.getDate()));
			var _his = new Array(zero(_d.getHours()), zero(_d.getMinutes()), zero(_d.getSeconds()));
			var date = _ymd.join("/") + " " + _his.join(":");
			
			var img = $("<img/>");
			img.attr("src", val.user.profile_image_url);
			
			var div = $("<div/>");
			div.attr("id", "user");
			var txt = $("<div/>").html(val.text)
			var username =  $("<a/>").html(val.user.name).attr({
												href: 'http://twitter.jp/' + val.user.screen_name,
												target: "_blank"
												});
			username.click(function(){
							window.open($(this).attr("href"));
							});
			
			var span = $("<span/>").html(" : "+date);
			span.prepend(username);
			
			txt.prepend(img);
			div.append(txt);
			div.append(span);
			div.hide();
	
			if(recentID === 0){
				$("#tweet").append(div);
			}else{
				$("#tweet").prepend(div);
			}
			div.fadeIn("slow");
		}
		
	});
	
	//recentID = data[0].id;
	//console.log(recentID);
	//setTimeout("loadTweetData()", 10000);
	
}

function zero(data){

	return ("0"+data).slice(-2);

}

function loadTweetData(){
	//console.log("loading");
  $.ajax({
    type:"GET",
    //cache: false,
	url:'http://api.twitter.com/1/statuses/user_timeline/'+twitterID+'.json?callback=init',
    dataType:"jsonp",
	jsonp : 'init',
    //success: function(xml){ init(xml);},
	error: function(xml){ alert("error"); }
	});
}


/*
$(document).ready(function(){
	
	$(document.body).css("background-image", 'url(images/backgroundHLWN.jpg)');
						   
	var url = "images/backgroundHLWNJack.png";
	//var ele = $(document.createElement('img')); 
	//ele.attr({ src: url, id: "jack"});
	//$(document.body).append(ele);
	//$("#jack").css({zIndex:1000, position: "fixed", top: "290px", right:"10px"});
	
	var element = new Image();
	element.src = url;
	element.id = "jack";
	$(document.body).append(element);
	
	//$("#jack").appendTo(document.body);//IE
		$(document.body).toggle(function () {
		$("#jack").animate({right:"-250px"}, 700 );
		},
		function () {
		$("#jack").animate({right:"10px"}, 700 );
		}
	);
$(document.body).append('<style type="text/css"><!--#jack{z-index:1000;position:fixed!important;position:absolute;top:290px;right:10px;} --></style>');

});
*/

/*$(document).ready(function(){
	
					   
	var url = "images/eventImage.png";
	
	var element = new Image();
	element.src = url;
	element.id = "eventImg";
	$(document.body).append(element);
	
	$(document.body).toggle(function () {
		$("#eventImg").animate({right:"-100px"}, 700 );
		},
		function () {
		$("#eventImg").animate({right:"10px"}, 700 );
	}
	);
$(document.body).append('<style type="text/css"><!--#eventImg{z-index:1000;position:fixed!important;position:absolute;bottom:10px;right:10px;} --></style>');

});*/
