
var NEWS_JSON_URL = '/ajax/NewsItemList?keyword=';
var MOVIE_JSON_URL = '/ajax/VideoItemList?keyword=';
var IMAGE_JSON_URL = '/ajax/ImageItemList?keyword=';
var ITEM_JSON_URL = '/ajax/ShopItemList?keyword=';
var GRAPH_JSON_URL = '/ajax/TwitterGraph?keyword=';

var setGatesParts = function(id, key) {

	var paramId = id;
	var paramKey = encodeURI(key);
	// News -----------------------------------

	var newsObj = $("#News"+paramId);
	function NewsUpdate(data){
		var num = 0;
		newsObj.empty();
		newsObj.addClass('News');

		$.each(data,function(i,items){

			num = i+1;

			if(i >= 10){
				return;
			}
			newsObj.append('<dl><dt>'+items.publishDate+'</dt><dd><a href="'+items.url+'" target="news">'+items.summary+'</a></dd></dl>');
		});
		if(num==0){
			newsObj.html('<dl><dd>関連情報が存在しません。</dd></dl>');
		}

	}
	$.getJSON(NEWS_JSON_URL+paramKey,null,NewsUpdate)


	// Movie -----------------------------------
	var movieObj = $("#Movie"+paramId);
	function MovieUpdate(data){
		var num = 0;
		movieObj.empty();
		movieObj.addClass('Movie Clear');

		$.each(data,function(i,items){

			num = i+1;

			if(i >= 3){
				return;
			}

			if(items.url == ''){
				items.url = 'images/nf_movie.gif';
			}

//			$("#Movie"+paramId).append('<div class="Mov1"><span>'+items.title+'</span><p><a href="'+items.url+'" target="movie"><img src="'+items.thumbnail+'" alt="'+items.summary+'" width="120" height="90" /></a></p></div>');
//			movieObj.append('<div class="Mov1"><span>'+items.title+'</span><p><a href="'+items.url+'" target="movie"><img src="'+items.thumbnail+'" alt="'+items.summary+'" width="120" /></a></p></div>');
			movieObj.append('<div class="Mov1"><p><a href="'+items.url+'" target="movie"><img src="'+items.thumbnail+'" alt="" width="120" /></a></p><span>'+items.title+'</span></div>');

		});

		for(ii=num; ii < 3; ii++){
			movieObj.append('<div class="Mov1"><p><img src="images/nf_movie.gif" alt="" width="120" /></p></div>');
		}


	}
	$.getJSON(MOVIE_JSON_URL+paramKey,null,MovieUpdate)


	// Image -----------------------------------
	var imageObj = $("#Image"+paramId);
	function ImageUpdate(data){
		imageObj.empty();
		imageObj.addClass('Image Clear');
		var num = 0;

		$.each(data,function(i,items){

			num = i+1;

			if(i >= 3){
				return;
			}

			if(items.url == ''){
				items.url = 'images/nf_images.gif';
			}

//			imageObj.append('<div class="first"><span>'+items.title+'</span><p><a href="'+items.url+'" title="'+items.title+'" class="thickbox"><img src="'+items.thumbnail+'" alt="'+items.summary+'" width="147" height="147" /></a></p></div>');
//			imageObj.append('<div class="first"><span>'+items.title+'</span><p><a href="'+items.url+'" title="'+items.title+'" class="thickbox"><img src="'+items.thumbnail+'" alt="'+items.summary+'" width="147" /></a></p></div>');
			imageObj.append('<div class="first"><p><a href="'+items.url+'" title="'+items.title+'" id="thickboxImage'+i+'" onclick="return thickbox(this);"><img src="'+items.thumbnail+'" alt="'+items.summary+'" width="147" height="147"/></a></p><span>'+items.title+'</span></div>');

			var thickboxImage = $("#thickboxImage"+i);
			thickboxImage.addClass('thickbox');

		});

		for(ii=num; ii < 3; ii++){
			imageObj.append('<div class="first"><p><img src="images/nf_images.gif" alt="" width="147" /></a></p></div>');
		}

	}
	$.getJSON(IMAGE_JSON_URL+paramKey,null,ImageUpdate)


	// Item -----------------------------------
	var itemObj = $("#Item"+paramId);
	function ItemUpdate(data){
		itemObj.empty();

		var num = 0;
		$.each(data,function(i,items){

			num = i+1;

			if(i >= 5){
				return;
			}

			if(items.imageSmall == ''){
				items.imageSmall = 'images/nf_product.gif';
			}
			//itemObj.append('<dl><dt><img src="'+items.imageSmall+'" alt="'+items.name+'" height="79" /></dt><dd><p><a href="'+items.url+'" target="_blank">'+items.name+'</a></p><a href="'+items.url+'" target="_blank">'+items.description+'</a> <span>\\'+items.price+'</span></dd></dl>');

			if(items.price != '0'){
				itemObj.append('<dl><dt><img src="'+items.imageSmall+'" alt="'+items.name+'" width="108" height="79" /></dt><dd><p><a href="'+items.url+'" target="_blank">'+items.name+'</a></p><a href="'+items.url+'" target="_blank"></a> <span>\\'+items.price+'</span></dd></dl>');
			}else{
				itemObj.append('<dl><dt><img src="'+items.imageSmall+'" alt="'+items.name+'" width="108" height="79" /></dt><dd><p><a href="'+items.url+'" target="_blank">'+items.name+'</a></p><a href="'+items.url+'" target="_blank"></a></dd></dl>');
			}
		});

		for(ii=num; ii < 5; ii++){
			itemObj.append('<dl><dt><img src="images/nf_product.gif" alt="" height="79" /></dt><dd></dd></dl>');
		}

	}
	$.getJSON(ITEM_JSON_URL+paramKey,null,ItemUpdate)


	// Graph -----------------------------------
	$.getJSON(GRAPH_JSON_URL+paramKey,null,GraphUpdate)


}

