/**
 * 次のデータ
 * 
 * @param currentNumId 現在のnumId
 * @return
 */
function ajaxGetRelatedPostForHtml(postSeq) {

	var currentNum = document.getElementById(currentNumId).value;
	var plusHtml = "";  
	var inAjaxDataCount = 0;
  
	// gold all post
	if (whatData == 1) {
	   	$.ajax({
	   	  url: "/ajax/getRelatedPostForHtml.php?postSeq=" + postSeq, cache: false, success: function(html){
	   		$("#relate_post").append(html); // to add div
	   	  }
	   	});
	}
	
}

// search用
function goSortSearch(sort) {
	
	$('#sort').val(sort);

    $('#do_sort_search').submit();
	
}

// main rss Check
function rssApply()
{
	$("#red-notice").text("少々お待ちください。");

	$("#red-notice").show();

	if($("#input-url").val()=="") {
		$("#red-notice").text("RSSアドレスを入力して下さい。");
		return;
	}

	$.post('/ajax/requestrss.php' , { rss:$("#input-url").val()},function(script) { eval(script); },"script");	
}

// maxLength attributeを使ってください。 by. nkdk
function ismaxlength(obj){
 var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	 
 if (obj.getAttribute && obj.value.length>mlength) {
  alert("ツイッターの投稿は110文字以内に制限されています。");
  obj.value = obj.value.substring(0 , mlength);
  
 }
 
}

// url + keywordで処理する。
function searchKeywordAndType(type, keywordObjName) {

	var keyword=document.getElementById(keywordObjName).value;
	
	if (type == "blogs") {
		var typeText = "/search/blogs/";
	} else if (type == "news") {
		var typeText = "/search/news/";
	} else if (type == "photos") {
		var typeText = "/search/photos/";
	} else {
		var typeText = "/search/all/";
	}

	location.href = typeText + keyword; 

}

function spamInfoSend(postnum, postChoixerId) {
	
	var r = confirm("スパムで報告しますか？");
	
	if (r == true) {
		$.getJSON('/ajax/spamInfoSend.php?seq=' + postnum + "&choixerId=" + postChoixerId, function(data) {
	        $.each(data, function(index, entry) {
	        	var result = entry['result'];
	        	if (result == "ok") {
	        		alert("スパムとおして報告しました。");
	        	} else {
	        		alert("スパムとの報告が失敗しました。");
	        	}
	        });	        
	    });
	}
}

function facebookBookmark(postnum, title) {
	
	var d=document;
	var f='http://www.facebook.com/share';
	var l=d.location,e=encodeURIComponent;
	var p='.php?src=bm&v=4&i=1274234955&u='+e('http://choix.jp/getpost/' + postnum)+'&t='+e(title);
	
	try{
		if (!/^(.*\.)?facebook\.[^.]*$/.test(l.host))
			share_internal_bookmarklet(p)
	} catch(z) { 
		
		a=function() { 
			if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};
			if (/Firefox/.test(navigator.userAgent))
				setTimeout(a,0);
			else{
				a();
			}
	}
	
}

function facebookBookmarkForTwit(postnum, title) {
	
	var d=document;
	var f='http://www.facebook.com/share';
	var l=d.location,e=encodeURIComponent;
	var p='.php?src=bm&v=4&i=1274234955&u='+e('http://choix.jp/gettwitpost/' + postnum)+'&t='+e(title);
	
	try{
		if (!/^(.*\.)?facebook\.[^.]*$/.test(l.host))
			share_internal_bookmarklet(p)
	} catch(z) { 
		
		a=function() { 
			if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};
			if (/Firefox/.test(navigator.userAgent))
				setTimeout(a,0);
			else{
				a();
			}
	}
	
}


function openHref(obj, url) {
	
	obj.target='_blank';
	obj.href=url;
	
}
 
function changeTopic(key) {
  if (key == 0) {
    jQuery("#f_totals").hide();
    jQuery("#f_peoples").show();
    $("#current_status").val("people");    
  } else {
    jQuery("#f_peoples").hide();
    jQuery("#f_totals").show();
    $("#current_status").val("total");
  }

}

function changeTopicNext() {
  
  var key = $("#current_status").val();
  if (key == "people") {
	var currentCount = $("#f_people_count").val();
          currentCount = parseInt(currentCount);	
	if (currentCount < 3) {
          jQuery("#f_people" + currentCount).hide();
	  var nextCount = currentCount + 1;
	  jQuery("#f_people" + nextCount).show();
	  $("#f_people_count").val(nextCount);	  
	}
  } else { 
	var currentCount = $("#f_total_count").val();
        currentCount = parseInt(currentCount);
	if (currentCount < 3) {
          jQuery("#f_total" + currentCount).hide();
          var nextCount = currentCount + 1;
 
	  jQuery("#f_total" + nextCount).show();
	  $("#f_total_count").val(nextCount);
	}
  }
}

function changeTopicPrevious() {

  var key = $("#current_status").val();
  if (key == "people") {
	var currentCount = parseInt($("#f_people_count").val());
	if (parseInt(currentCount) > 0) {
		  jQuery("#f_people" + currentCount).hide();
                  var preCount = currentCount - 1;
		  jQuery("#f_people" + preCount).show();
		  $("#f_people_count").val(preCount);	  
	}	
  } else {
	var currentCount = parseInt($("#f_total_count").val());	
	if (parseInt(currentCount) > 0) {
	  jQuery("#f_total" + currentCount).hide();
          var preCount = currentCount - 1;
	  jQuery("#f_total" + preCount).show();
	  $("#f_total_count").val(preCount);
	}	
  }
}

function menuOn(imgEl)
{
 imgEl.src = imgEl.src.replace(".gif", "_on.gif");


}

function menuOut(imgEl)
{
imgEl.src = imgEl.src.replace("_on.gif", ".gif");
}

function closeMainFlash() {
document.getElementById('mainFlashArea').style.height='320px';
document.getElementById('close_contents01').style.display='none';
document.getElementById('close_contents02').style.display='none';
document.getElementById('close_contents03').style.display='none';
document.getElementById('close_contents04').style.display='none';

}

function openMainFlash() {
document.getElementById('mainFlashArea').style.height='100px';
document.getElementById('close_contents01').style.display='block';
document.getElementById('close_contents02').style.display='block';
document.getElementById('close_contents03').style.display='block';
document.getElementById('close_contents04').style.display='block';

}



function toggleMenu(currMenu) {
thisMenu = eval(document.getElementById(currMenu).style)
if (thisMenu.display == "block") {
thisMenu.display = "none";
} else thisMenu.display = "block";
return false
}

// Tab Content
function initTabMenu(tabContainerID, typeNum) {
	if (typeNum == null) {
		typeNum = 0
	}
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;

			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
				} else {
					currentmenu.className = currentmenu.className.replace(" on", "");
				}
			}
			this.targetEl.style.display = "";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
			} else {
				this.className += " on";
			}
			this.container.current = this;
			return false;
			
		};
		if (i == typeNum) {
			if (!thismenu.container.first)
				thismenu.container.first = thismenu;
		}
	}

	if (tabContainer.first)
		tabContainer.first.onclick();
}

//----------------------------------------------
//Floating v1.1 Source By Bermann
//dobermann75@gmail.com
//----------------------------------------------

//new Floating(적용할개체 , X축여백 , Y축여백 , 미끄러지는속도:작을수록빠름..기본20 , 빠르기:작을수록부드러움..기본10);

function Floating(FloatingObj,MarginX,MarginY,Percentage,setTime) {
	this.FloatingObj = FloatingObj;
	this.MarginX = (MarginX) ? MarginX : 0;
	this.MarginY = (MarginY) ? MarginY : 0;
	this.Percentage = (Percentage) ? Percentage : 20;
	this.setTime = (setTime) ? setTime : 10;
	this.FloatingObj.style.position = "absolute";
	this.Body = null;
	this.setTimeOut = null;
	this.Run();
}

Floating.prototype.Run = function () {
	if ((document.documentElement.scrollLeft + document.documentElement.scrollTop) > (document.body.scrollLeft + document.body.scrollTop)) {
		this.Body = document.documentElement;
	} else {
		this.Body = document.body;
	}

	var This = this;
	var FloatingObjLeft = (this.FloatingObj.style.left) ? parseInt(this.FloatingObj.style.left,10) : this.FloatingObj.offsetLeft;
	var FloatingObjTop = (this.FloatingObj.style.top) ? parseInt(this.FloatingObj.style.top,10) : this.FloatingObj.offsetTop;
	var DocLeft = this.Body.scrollLeft + this.MarginX;
	var DocTop = this.Body.scrollTop + this.MarginY;

	var MoveX = Math.abs(FloatingObjLeft - DocLeft);
	MoveX = Math.ceil(MoveX / this.Percentage);
	var MoveY = Math.abs(FloatingObjTop - DocTop);
	MoveY = Math.ceil(MoveY / this.Percentage);

	if (FloatingObjLeft < DocLeft) {
		this.FloatingObj.style.left = FloatingObjLeft + MoveX + "px";
	} else {
		this.FloatingObj.style.left = FloatingObjLeft - MoveX + "px";
	}

	if (FloatingObjTop < DocTop) {
		this.FloatingObj.style.top = FloatingObjTop + MoveY + "px";
	} else {
		this.FloatingObj.style.top = FloatingObjTop - MoveY + "px";
	}

	window.clearTimeout(this.setTimeOut);
	this.setTimeOut = window.setTimeout(function () { This.Run(); },this.setTime);
}


function chgSearchStatus(sel_category) {
	
	if (sel_category == 'total') {
		$('#search_total').attr("class", "current");
		$('#search_blog').attr("class", "");
		$('#search_news').attr("class", "");
		$('#search_artwork').attr("class", "");
		
		$('#search_form_id').attr('action', '/search/all');
		
	} else if (sel_category == 'blog') {
		$('#search_total').attr("class", "");
		$('#search_blog').attr("class", "current");
		$('#search_news').attr("class", "");
		$('#search_artwork').attr("class", "");
		
		$('#search_form_id').attr('action', '/search/blogs');
		
	} else if (sel_category == 'news') {
		$('#search_total').attr("class", "");
		$('#search_blog').attr("class", "");
		$('#search_news').attr("class", "current");
		$('#search_artwork').attr("class", "");
	
		$('#search_form_id').attr('action', '/search/news');
		
	} else if (sel_category == 'artwork') {
		$('#search_total').attr("class", "");
		$('#search_blog').attr("class", "");
		$('#search_news').attr("class", "");
		$('#search_artwork').attr("class", "current");
	
		$('#search_form_id').attr('action', '/search/photos');
		
	}
	
}

