getCurrentMode = function(urlstring){
	m = {
		site: 0,
		parent: "cover",
		child: ""
	}
	if(!urlstring) return
	if(urlstring.indexOf(".jpg")>=0){
		m.site = "image"
	}
	else{
		f1 = "deux.cfm"
		f2 = "http://www.transposon-jp.com/deux.cfm"
		if(urlstring.substring(0, f1.length) == f1 || urlstring.substring(0, f2.length) == f2) pos = urlstring.indexOf("deux.cfm")
		else pos = -1
		if(pos<0) m.site = "outside"
		else{
			m.site = "inside"
		}
	}
	query = urlstring
	if(pos>0){
		query = urlstring.substring(pos)
	}
	query = query.replace("deux.cfm", "")
	if(query == ""){
		m.parent = "top"
		m.child = "top"
	}
	else{
		query = query.substring(1)
		$.each(query.split("&"), function(i){
			varArray = this.split("=")
			if(varArray[0] == "mode"){
				if(varArray[1].indexOf(".")>0){
					m.parent = varArray[1].split(".")[0]
					m.child = varArray[1].split(".")[1]
				}
				else{
					m.parent = varArray[1]
					m.child = varArray[1]
				}
			}
		})
	}
	return m
}

pageFadeInOut = function(){
	if($(this).parent().hasClass("navi")) return
	url = $(this).attr("href")
	mode = getCurrentMode(url)
	//外部リンクには無効
	targetArea = "#leftArea"
	//通常ブラウザ
	if(jQuery.support.opacity || jQuery.support.style){
		$(targetArea).animate({"opacity": 0}, 1000,
			function(){
				$.fancybox.showActivity()
			}
		)
		$(targetArea).load(
			url,
			{ajax: "page"},
			function(){
				$(targetArea).animate({"opacity": 1}, 500, function(){
					$.fancybox.hideActivity()
					if(mode.parent == "blogwork") call_jsocializer()
					//イベントを再割当て
					CallFunction.common(targetArea)
				})
				$("body").attr({"class": mode.child})
				$(targetArea).attr({"class": mode.child})
			}
		)
	}
	//IE6 or 7
	else{
		$(targetArea).hide(1000,
			function(){
				$.fancybox.showActivity()
			}
		)
		$(targetArea).load(
			url,
			{ajax: "page"},
			function(){
				$(targetArea).show(500, function(){ $.fancybox.hideActivity()})
				$("body").attr({"class": mode.child})
				$(targetArea).attr({"class": mode.child})
				//イベントを再割当て
				CallFunction.common(targetArea)
			}
		)
	}
	return false
}

setATagonClick = function(baseTarget){
	$(baseTarget + " a").map(function(){
		url = $(this).attr("href")
		mode = getCurrentMode(url)
		//内部リンクのみ
		if(mode && mode.site=="inside") return this
	}).bind("click", pageFadeInOut)
	$(baseTarget + " a").map(function(){
		url = $(this).attr("href")
		mode = getCurrentMode(url)
		//画像へのリンクのみ
		if(mode && mode.site=="image") return this
	}).fancybox()
}

CallFunction = {}
CallFunction.common = function(baseTarget){

	setCloudPop = function(target){
		$(target).hover(
			function(e){
				COo = $(this)
				COe = e
				timerCloud = setTimeout(setCloudOpen, 500)
			},
			function(){
				clearTimeout(timerCloud)
				COo = $(this)
				COo.removeClass("over")
			}
		)
	}

	//上記のタイマー関数
	setCloudOpen = function(){
		path = COo.attr("href").replace("deux.cfm", "ajax.cfm")
		path = path.replace("iframe.cfm", "ajax.cfm")
		$("#cloudArea").load(path,
			function(){
				w = 600
				$("#cloudArea").css({
					"width": w,
					"display": "block",
					"top": 50 + $(document).scrollTop(),
					"left": ($(window).width() - w)/2 + $(document).scrollLeft()
				})
				$("#cloudArea").animate({"opacity": 0.9}, 500)
				setCloudPop("#cloudArea .cloudPop")
			}
		)
	}
	setATagonClick(baseTarget)
	$(".hoverAttribute").hoverAttribute()
	setNaviHover()
}

$(function(){
	$("#cloudArea").hover(
		function(){},
		function(){
			$(this).fadeOut("slow")
		}
	)
	$("#cloudArea").click(
		function(){
			$(this).fadeOut("slow")
		}
	)
	CallFunction.common("body")
})


