/**
 * @author ichi
 */


$(function(){
	// Tabs
	//console.log($('#tabs').tabs('option', 'fx'));

	$('#tabs').tabs({
		selected: 0,
		//fx: { height: 'toggle', duration:400 },
		//fx: { height: 'show', duration:400},

		show: function(event,ui){
			$(ui.tab).parent().parent().children().each(function(i){
				$(this).find('a').bind('mouseenter', function(){
					$(this).find("img").eq(0).css({display:'none'});
					$(this).find("img").eq(1).css({display:'block'});
				});
				$(this).find('a').bind('mouseleave', function(){
					if($($(this).attr('href')).css('display') == 'none'){
						$(this).find("img").eq(1).css({display:'none'});
						$(this).find("img").eq(0).css({display:'block'});
					}
				});
			});
		},

		select: function(event, ui) {
			// Objects available in the function context:
			$(ui.tab).children().eq(0).css({display:'none'});
			$(ui.tab).children().eq(1).css({display:'block'});
			$(ui.tab).parent().parent().children().each(function(i){
				if(i != ui.index){
					$(this).children().find("img").eq(0).css({display:'block'});
					$(this).children().find("img").eq(1).css({display:'none'});
				}
			});
		}
	});
});


function InitDisplay(){
	//初期ページ読み込み
	var vPage = "";
	var vTabs = "";
	var vDt = new Date();
	var vRnd = vDt.getMilliseconds();
	var vParameter = location.search.substring(1);
//	alert(vParameter);
//	alert(vRnd);

	switch(vParameter){
		case "":
			$(function(){
				$('#tabs-1').load('news.html' + '?' + vRnd);
			});
			break;
		case "news":
			$(function(){
				$('#tabs-1').load('news.html' + '?' + vRnd);
			});
			break;
		case "disco":
			$(function(){
				$('#tabs-2').load('disco.html' + '?' + vRnd,'',function(){
					$(this).children('#content').children('#tabs_s').tabs({
						selected: 0,

						show: function(event,ui){
							$(ui.tab).parent().parent().children().each(function(i){
								$(this).find('a').bind('mouseenter', function(){
								$(this).find("img").eq(0).css({display:'none'});
								$(this).find("img").eq(1).css({display:'block'});
								});

								$(this).find('a').bind('mouseleave', function(){
									if($($(this).attr('href')).css('display') == 'none'){
										$(this).find("img").eq(1).css({display:'none'});
										$(this).find("img").eq(0).css({display:'block'});
									}
								});
							});
						},

						select: function(event, ui) {
							// Objects available in the function context:
							$(ui.tab).children().eq(0).css({display:'none'});
							$(ui.tab).children().eq(1).css({display:'block'});
							$(ui.tab).parent().parent().children().each(function(i){
								if(i != ui.index){
									$(this).children().find("img").eq(0).css({display:'block'});
									$(this).children().find("img").eq(1).css({display:'none'});
								}
							});
						}
					});
				});
				$('#tabs').tabs('select',1);
			});
			break;
		case "media":
			$(function(){
				$('#tabs-3').load('media.html' + '?' + vRnd);
				$('#tabs').tabs('select',2);
			});
			break;
		case "live":
			$(function(){
				$('#tabs-4').load('live.html' + '?' + vRnd);
				$('#tabs').tabs('select',3);
			});
			break;
		default:
			$(function(){
				$('#tabs-1').load('news.html' + '?' + vRnd);
			});
			break;
	}
}


function ShowDivBlocks(divId){
	var vDt = new Date();
	var vRnd = vDt.getMilliseconds();
	switch (divId){
		case "tabs-1":
			$(function(){
				$('#tabs-1').load('news.html' + '?' + vRnd);
			});
			document.getElementById("tabs-2").style.display = "none";
			document.getElementById("tabs-3").style.display = "none";
			document.getElementById("tabs-4").style.display = "none";
			document.getElementById("tabs-1").style.display = "block";
			break;

		case "tabs-2":
//			$(function(){
//				$('#tabs-2').load('disco.html');
//			});
			document.getElementById("tabs-1").style.display = "none";
			document.getElementById("tabs-3").style.display = "none";
			document.getElementById("tabs-4").style.display = "none";

			$('#tabs-2').load('disco.html' + '?' + vRnd,'',function(){
				$(this).children('#content').children('#tabs_s').tabs({
					selected: 0,
					//fxShow: { height: 'show', opacity: 'show' },
//					fx: { duration:2000, opacity: 'show' },
					show: function(event,ui){
						//console.log("show");
						// console.log($(ui.tab).parent());
						
					$(ui.tab).parent().parent().children().each(function(i){
						$(this).find('a').bind('mouseenter', function(){
						$(this).find("img").eq(0).css({display:'none'});
						$(this).find("img").eq(1).css({display:'block'});
					});
					
					$(this).find('a').bind('mouseleave', function(){
					if($($(this).attr('href')).css('display') == 'none'){
						$(this).find("img").eq(1).css({display:'none'});
						$(this).find("img").eq(0).css({display:'block'});
					}
					});
						});
					},

					select: function(event, ui) {
						//console.log("select");
						// Objects available in the function context:
						$(ui.tab).children().eq(0).css({display:'none'});
						$(ui.tab).children().eq(1).css({display:'block'});
						$(ui.tab).parent().parent().children().each(function(i){
							if(i != ui.index){
								$(this).children().find("img").eq(0).css({display:'block'});
								$(this).children().find("img").eq(1).css({display:'none'});
							}
						});
					}
				});
			});
			document.getElementById("tabs-2").style.display = "block";
			break;

		case "tabs-3":
			//MEDIA読み込み
			$(function(){
				$('#tabs-3').load('media.html' + '?' + vRnd);
			});
			document.getElementById("tabs-1").style.display = "none";
			document.getElementById("tabs-2").style.display = "none";
			document.getElementById("tabs-4").style.display = "none";
			document.getElementById("tabs-3").style.display = "block";
			break;

		case "tabs-4":
			//LIVE読み込み
			$(function(){
				$('#tabs-4').load('live.html' + '?' + vRnd);
			});
			document.getElementById("tabs-1").style.display = "none";
			document.getElementById("tabs-2").style.display = "none";
			document.getElementById("tabs-3").style.display = "none";
			document.getElementById("tabs-4").style.display = "block";
			break;
	}
}
