
// 初期実行
$(document).ready(function(){
	
	// ランダムロゴ実行
	$('#fragment-1 > ul').shuffle();
	
	// タブの中身を作成
	$('#fragment-1 li.icon_fashion').each(function(i){
		$('#fragment-2 > ul').append($(this).clone());
	});
	$('#fragment-1 li.icon_goods_shop').each(function(i){
		$('#fragment-3 > ul').append($(this).clone());
	});
	$('#fragment-1 li.icon_dining_cafe').each(function(i){
		$('#fragment-4 > ul').append($(this).clone());
	});
	
	// jQueryタブ
	$('#container-1').tabs({ selected: 0 });
	var tab_selected = 'fragment-1';
	
	// タブ選択時のイベント
	$('#container-1').bind('tabsselect', function(event, ui) {
		var panel = ui.panel.id;
		var old = $('#' + tab_selected);
		var old_ul = $('#' + tab_selected + ' > ul');
		var now = $('#' + panel);
		var now_ul = $('#' + panel + ' > ul');
		var old_h = old.height();
		var now_h = now.height();
		tab_selected = panel;
		$('#' + panel + ' li').hide();
		now_ul.height(old_h);
		now_ul.animate({height:now_h}, 'slow', function(){$('#' + panel + ' li').fadeIn('slow');});
		
	});
	
	// XML解析して「お知らせ」「アルバイト方法」「新着記事」を表示する
	$.ajax({
		type: 'GET',
		cache:true,
		url: './clefyinfo.php',
		dataType: 'xml',
		success: function(xml) { makeClefyInfo(xml); }
	});
	
	
});


// ランダムロゴ関数
(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);


// ClefyInfoXMLからエレメント生成
function makeClefyInfo(xml){
	
	// ブログ
	var blogList = {
		'36':{title:'ABAHOUSE LASTWORD',	category:'fashion',	url:'http://blog.clefy.jp/abahouse_lastword/'},
		'38':{title:'adidas concept shop',	category:'fashion',	url:'http://blog.clefy.jp/adidas_concept_shop/'},
		'39':{title:'alfredoBANNISTER',	category:'fashion',	url:'http://blog.clefy.jp/alfredo_bannister/'},
		'40':{title:'asse KAINO',	category:'goods',	url:'http://blog.clefy.jp/asse_kaino/'},
		'41':{title:'BE AN ANGEL　ＣＯＣＵＥ',	category:'goods',	url:'http://blog.clefy.jp/be_an_angel_cocue/'},
		'43':{title:'Dip Drops',	category:'fashion',	url:'http://blog.clefy.jp/dip_drops/'},
		'44':{title:'ディズニーストア',	category:'goods',	url:'http://blog.clefy.jp/disney_store/'},
		'46':{title:'griffonner',	category:'goods',	url:'http://blog.clefy.jp/griffonner/'},
		'47':{title:'HARBS',	category:'dining',	url:'http://blog.clefy.jp/harbs/'},
		'49':{title:'喰喰アジアンプレミアム',	category:'dining',	url:'http://blog.clefy.jp/kuikui/'},
		'51':{title:'レストラン　ロイン',	category:'dining',	url:'http://blog.clefy.jp/loin/'},
		'52':{title:'MISSHA',	category:'goods',	url:'http://blog.clefy.jp/missha/'},
		'53':{title:'どろ焼・鉄板ダイニング　喃風',	category:'fashion',	url:'http://blog.clefy.jp/nanpu/'},
		'54':{title:'NATURAL BEAUTY BASIC',	category:'fashion',	url:'http://blog.clefy.jp/natural_beauty_basic/'},
		'57':{title:'REV-OWN',	category:'goods',	url:'http://blog.clefy.jp/rev_own/'},
		'58':{title:'bulle de savon',	category:'fashion',	url:'http://blog.clefy.jp/savon/'},
		'60':{title:'SHIPS',	category:'fashion',	url:'http://blog.clefy.jp/ships/'},
		'62':{title:'STUSSY',	category:'fashion',	url:'http://blog.clefy.jp/stussy/'},
		'63':{title:'スイーツパラダイス',	category:'dining',	url:'http://blog.clefy.jp/sweets_paradise/'},
		'64':{title:'XLARGEX-girl',	category:'fashion',	url:'http://blog.clefy.jp/xlarge_x_girl/'},
		'65':{title:'Nomine',	category:'fashion',	url:'http://blog.clefy.jp/nomine/'},
		'66':{title:'PAR ICI',	category:'fashion',	url:'http://blog.clefy.jp/parici/'},
		'67':{title:'Seoul dining ワンス',	category:'dining',	url:'http://blog.clefy.jp/wansu/'},
		'68':{title:'ainz & tulpe アインス＆トルペ',	category:'goods',	url:'http://blog.clefy.jp/ainzandtulpe/'}
	};
	
	// Clefyからのお知らせ
	var info_html = '';
	var info = $(xml).find('info');
	info.find('item').each(function(){
		info_html += '<li><a href="'+ $(this).find('url').text() +'">'+ $(this).find('title').text() +'</a></li>' + "\n";
	});
	$('#clefy_info_area').html(info_html);
	
	// アルバイト情報
	var arbeit_html = '';
	var arbeit = $(xml).find('arbeit');
	arbeit.find('item').each(function(){
		arbeit_html += '<li><a href="'+ $(this).find('url').text() +'">'+ $(this).find('title').text() +'</a></li>' + "\n";
	});
	if(arbeit_html == ''){
		$('#clefy_arbeit_area').html('<li>現在アルバイトの募集はありません。</li>');
	}else{
		$('#clefy_arbeit_area').html(arbeit_html);
	}
	
	// 新着ブログ
	var newentry_html = '';
	var newentry = $(xml).find('newentry');
	newentry.find('item').each(function(){
		var url = $(this).find('url').text();
		var blog_id = $(this).find('blog_id').text();
		newentry_html += '<div class="pickupshop heightLine">' + "\n";
		newentry_html += '	<div class="cat-'+ blogList[blog_id].category +'">' + "\n";
		newentry_html += '		<h3><a href="'+ blogList[blog_id].url +'"><img src="img/blogs/'+ blog_id +'.jpg" alt="'+ blogList[blog_id].title +'" width="150" height="39" /></a></h3>' + "\n";
		if($(this).find('img_src').text() == ''){
			// ダミー画像
			newentry_html += '		<div align="center"><img src="img/thums/'+ blog_id +'.jpg" width="150" height="100" class="blog_img" /></div>' + "\n";
		}else{
			// ブログ記事内画像
			newentry_html += '		<div align="center"><img '+ $(this).find('img_src').text() +' width="'+ $(this).find('img_w').text() +'" height="'+ $(this).find('img_h').text() +'" class="blog_img" /></div>' + "\n";
		}
		newentry_html += '		<p class="date">'+ $(this).find('post_date').text() +'</p>' + "\n";
		newentry_html += '		<h4><a href="'+ url +'">'+ $(this).find('title').text() +'</a></h4>' + "\n";
		newentry_html += '		<p class="pickup-txt">'+ $(this).find('content').text() +'</p>' + "\n";
		newentry_html += '		<div class="pickup-detail"><a href="'+ url +'"><img src="img/btn_pickup-detail_off.jpg" alt="続きを読む" width="70" height="18" /></a></div>' + "\n";
		newentry_html += '	</div>' + "\n";
		newentry_html += '</div>' + "\n";
	});
	$('#pickup').append(newentry_html);

}


