/*==================================================================
//
//  GALLERY
//
==================================================================*/
$(function(){
$(".thumbs a").click(function(){

var largePath = $(this).attr("href");
var largeAlt = $(this).attr("title");
var largeLink = $(this).attr("rel");
$(".largeImage img").fadeOut("slow", function() {
		$(this).attr({  src: largePath, alt: largeAlt }).fadeIn("slow");
});
$(".largeImage a").attr({ href: largeLink});
        return false;		
		
		
	})
});

/*==================================================================
//
//  FloatWINDOW
//
==================================================================*/
$(document).ready(function(){
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) })/*.prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>')*/;
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 0) / 2;
		var popMargLeft = ($('#' + popID).width() + 0) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
	}); //fade them both out
		
		return false;
	});

	
});



/*==================================================================
//
//  font_x.cssの切り替え
//
==================================================================*/
var rootPath = '/';
//==============================
//cookieのfsizeを取得
fsize = $.cookie('fsize');
//fsizeがnullじゃなかったら、#fontSize（css）のhref属性を置き換え
if(fsize != null) {
	$(function(){
		$("#fontSize").attr({href:rootPath + $.cookie('fsize')});
	});
}
//==============================
function fontSize(size){
	cssName = "css/" + size + ".css";
	cssPath = rootPath + cssName;
	//
	$('#fontSize').attr({href:cssPath});
	//fsizeにcssPathをセットして、30日間保存
	$.cookie('fsize',cssName,{expires:30,path:'/'});
}
//==============================
/*
function cookieControl(){
	lang=document.form1.language.value;
	size=document.form1.font_size.value;
	timer=document.form1.exp_date.value;
	//
	cssName="shared/css/"+size+".css";
	cssPath=currentPath+cssName;
	//
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('fsize',cssName,{expires:timer,path:'/'});
	//languageにlangをセットして、timer日間保存
	$.cookie('language',lang,{expires:timer,path:'/'});
	//
	$('#fontSize').attr({href:cssPath});
	window.opener.location.reload();
}
*/
//==============================
/*
function cookieReset(lang,size,timer){
	cssName="css/" + size + ".css";
	cssPath = rootPath + cssName;
	//
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('fsize',cssName,{expires:timer,path:'/'});
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('language',lang,{expires:timer,path:'/'});
	//
	$('#fontSize').attr({href:cssPath});
	window.opener.location.reload();
}
*/

/*==================================================================
//
//  Form 初期値
//
==================================================================*/
function cText(obj){
if(obj.value==obj.defaultValue){
obj.value="";
obj.style.color="#000";
}
}

function sText(obj){
if(obj.value==""){
obj.value=obj.defaultValue;
obj.style.color="#999";
}
}
/*==================================================================
//
//  LIKN
//
==================================================================*/
function clickLink(URL, target){
	if(URL != "" ){
		if(target == "top"){
			top.location.href = URL;
		}else if(target == "blank"){
			window.open(URL, "");
		}else if(target != ""){
			eval("parent.' + target + '.location.href = URL");
		}else{
			location.href = URL;
		}
	}
}

/*==================================================================
//
//  ロールオーバー
//
==================================================================*/
function initClickableArea()
{
	//画像のロールオーバー
	var obj = $(".rollover a img, img.rollover");
	$.each(obj, function() {
		changeBt($(this), $(this));
	});
	//==============================
	//画像の透過
	$(".img_over a img").hover (
		function ()
		{
			$(this).fadeTo(100, 0.7);
		},
		function ()
		{
			$(this).fadeTo(100, 0.999999);
		}
	);
	//==============================
	//テキスト要素のみ
	$(".clickable_area").find("[onclick*='clickLink']").addClass("clickable");
	//
	var obj = $(".clickable_area .clickable");
	$.each(obj, function(){
		var _target = $(this).hover(
			function ()
			{
				$(this).addClass("over");
			},
			function ()
			{
				$(this).removeClass("over");
			}
		);
		//画像のボタンがある場合
		if (_target.find("div").is(".rolloverBt"))
		{
			changeBt(_target.find("a img"), _target);
		}
	});
	//==============================
	//画像を含む時
	$(".clickable_areaContainImg").find("[onclick*='clickLink']").addClass("clickableContainImg");
	//
	var obj = $(".clickable_areaContainImg .clickableContainImg");
	$.each(obj, function(){
		var _target = $(this).append("<span class='imgCover'></span>");
		//
		var imgCover = _target.find(".imgCover").css({
			width: _target.outerWidth(),
			height: _target.outerHeight(),
			background: "url('../images/common/spacer.gif')",
			display: "block",
			position: "absolute",
			top: "0px",
			left: "0px",
			zIndex: "100",
			cursor: "pointer"
		});
		//
		imgCover.hover(
			function ()
			{
				$(this).parent().find("img.mainImg").fadeTo(100, 0.7);
				//
				$(this).parent(".backNumberTopic").find(".backNumberTopicCapBg").animate({
					height: "40px",
					top: "117px"
				}, 100);
				//
				$(this).parent(".backNumberTopic").find("h4").animate({
					top: "117px"
				}, 100);
			},
			function ()
			{
				$(this).parent().find("img.mainImg").fadeTo(100, 0.999999);
				//
				$(this).parent(".backNumberTopic").find(".backNumberTopicCapBg").animate({
					height: "35px",
					top: "122px"
				}, 100);
				//
				$(this).parent(".backNumberTopic").find("h4").animate({
					top: "122px"
				}, 100);
			}
		);
		//
		//画像のボタンがある場合
		if (_target.find("div").is(".rolloverBt"))
		{
			changeBt(_target.find("a img"), _target.find(".imgCover"));
		}
	});
	//
	function changeBt(target, clickableArea)
	{
		var image_cache = new Object();
		//
		target.not("[src*='_on.']").each(function(i) {
			var _this = this; 
			var imgsrc = _this.src;
			var dot = _this.src.lastIndexOf('.');
			var imgsrc_on = _this.src.substr(0, dot) + '_on' + _this.src.substr(dot, 4);
			image_cache[_this.src] = new Image();
			image_cache[_this.src].src = imgsrc_on;
			//
			clickableArea.hover(
				function() { _this.src = imgsrc_on; },
				function() { _this.src = imgsrc; }
			);
		});
	};
}
//
$(document).ready(initClickableArea);


//検索ドロップボックス(国、都市)
function initDropDown(){
	if ($("#search") && $("#search_inner") && (typeof countries != "undefined") && (typeof centers != "undefined")){
		$('#select').change(function(){
			updateSelect($('#select').val());
		});
		updateSelect($('#select').val());
	}
}
function updateSelect(ctr) {
	var countryName = countries[ctr];
	var centersArr = centers[countryName];
	$('#select2').empty();
	//
	var html = "";
	$option_entries = new Array();
	if(centersArr != undefined){
		//国が選択されていた時
		html += '<option value="0">----</option>';
		html += '<optgroup label="'+countryName+'">';
		for(var i = 0 ; i<centersArr.length ; i++){
			//デフォルト選択設定
			var tmp = "";
			if(defaultCity == centersArr[i]){
				tmp = " selected=\"selected\"";
			}
			html += '<option'+tmp+' value="' + centersArr[i] + '">' + centersArr[i] + '</option>';
		}
		html += '</optgroup>';
		$option_entries.push(html);
	}else{
		//国が選択されていなかった時
		for(key in centers){
			if(key != ""){
				html += '<optgroup label="'+key+'">';
			}
			for(var i = 0 ; i<centers[key].length ; i++){
				//デフォルト選択設定
				var tmp = "";
				if(defaultCity == centers[key][i]){
					tmp = " selected=\"selected\"";
				}
				html += '<option'+tmp+' value="' + centers[key][i] + '">' + centers[key][i] + '</option>';
			}
			if(key != ""){
				html += '</optgroup>'
			}
		}
		$option_entries.push(html);
	}
	$('#select2').append($option_entries.join());	
}
$(document).ready(initDropDown);
/**
agor Login
*/
function goLogin(url) {
	f = document.formlogin;
	/**
	if ( f.txt_uid.value == "" ) {
		alert("IDを入力して下さい");
		return false;
	}
	if ( f.txt_uid.value.substr(0,2) != "OC" && f.txt_uid.value.substr(0,2) != "oc" ) {
		alert("ID不正です、再入力をお願いいたします");
		return false;
	}
	if ( f.txt_uid.value.length != 12 ) {
		alert("ID不正です、再入力をお願いいたします");
		return false;
	}
	if ( f.txt_passwd.value == "" ) {
		alert("Passwordを入力して下さい");
		return false;
	}
	**/
	f.target = "_top";
	f.action = url;
	f.submit();
}
function goLogout(url) {
	f = document.formlogin;
	f.target = "_top";
	f.action = url;
	f.submit();
}

