﻿jQuery(document).ready(function(){
	if (document.getElementById("sidebar_main_right")) {scroll_sidebar(1000);}
});
var tb_pathToImage = "http://www.fineemb.com/wp-includes/js/thickbox/loadingAnimation.gif";
var tb_closeImage = "http://www.fineemb.com/wp-includes/js/thickbox/tb-close.png";
var thickboxL10n = {
	next: "Next >",
	prev: "< Prev",
	image: "Image",
	of: "of",
	close: "Close",
	noiframes: "This feature requires inline frames. You have iframes disabled or your browser does not support them."
};
try{convertEntities(thickboxL10n);}catch(e){};

jQuery('.gotop').click(function(){jQuery('html,body').animate({scrollTop: '0px'}, 800);});
jQuery('.gobot').click(function(){$('html,body').animate({scrollTop:$('#footer').offset().top}, 800);});

////侧栏滑动  
function scroll_sidebar(duration){
        var sidebar = jQuery("#sidebar_main_right");
sidebar.css('position','relative');
        var sidebar_top = sidebar.offset().top; 
		var sidebar_height = sidebar.height()+25;
		
		if(jQuery(window).height() > sidebar_height) {
			if(jQuery(window).scrollTop() > sidebar_top){ 
				sidebar.animate({top : jQuery(window).scrollTop() - sidebar_top  +"px" },{ duration:duration || 350 , queue:false }); 
			}
			jQuery(window).scroll(function (){
				if(jQuery(window).scrollTop() > sidebar_top ){ 
					sidebar.animate({top : jQuery(window).scrollTop() - sidebar_top  +"px" },{ duration:duration || 350 , queue:false }); 
				}else{
					sidebar.animate({top : 0 },{ duration:duration || 350 , queue:false}); 	
				}
			});
		}else{
			 var content = jQuery("#contentleft");
			 var content_top = content.offset().top; 
			 var content_height = content.height();
			 
			 if(content_height < sidebar_height + 10 ) {
			 	content_height = sidebar_height + 10;
			 }
			 
			if(jQuery(window).scrollTop() +  jQuery(window).height() > sidebar_top + 10 + sidebar_height){ 
				if(content_height +  content_top < jQuery(window).height() + jQuery(window).scrollTop()){
					sidebar.animate({top : content_height + content_top - sidebar_top  - sidebar_height - 10 + "px" },{ duration:duration || 350 , queue:false}); 
				} else {
					sidebar.animate({top : jQuery(window).scrollTop() +  jQuery(window).height() - sidebar_top -  sidebar_height - 10 + "px" },{ duration:duration || 350 , queue:false }); 
				}
			}
			
			jQuery(window).scroll(function (){
				if(jQuery(window).scrollTop() + jQuery(window).height() > sidebar_top + sidebar_height ){
					if(content_height +  content_top < jQuery(window).height() + jQuery(window).scrollTop()){
						sidebar.animate({top : content_height + content_top - sidebar_top  - sidebar_height - 10 + "px" },{ duration:duration || 350 , queue:false}); 
					} else {
						sidebar.animate({top : jQuery(window).scrollTop() +  jQuery(window).height()- sidebar_top -  sidebar_height  -10 +"px" },{ duration:duration || 350 , queue:false }); 
					}
				}else{
					sidebar.animate({top : 0 },{ duration:duration || 350 , queue:false}); 
				}
			});
		} 
}

////wp-recentcomments
(function() {

var xmlHttp;

function getXmlHttpObject() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch(e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function page(wpurl, args, start, loading) {
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Oop! Browser does not support HTTP Request.")
		return;
	}

	var url = wpurl;
	url += "?action=rc_ajax";
	url += "&args=" + args;
	url += "&start=" + start;

	xmlHttp.onreadystatechange = function(){runChange(loading)};
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-type", "charset=UTF-8");
	xmlHttp.send(null);
}

function detail(id, wpurl, args, start, loading) {
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Oop! Browser does not support HTTP Request.")
		return;
	}

	var url = wpurl;
	url += "?action=rc_detail_ajax";
	url += "&id=" + id;
	url += "&args=" + args;
	url += "&start=" + start;

	xmlHttp.onreadystatechange = function(){runChange(loading)};
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-type", "charset=UTF-8");
	xmlHttp.send(null);
}

function runChange(loading) {
	var firstItem = document.getElementById('rc_item_1');
	var parent = firstItem.parentNode;
	var navigator = document.getElementById('rc_nav');

	if (xmlHttp.readyState < 4) {
		document.body.style.cursor = 'wait';
		if (navigator) {
			navigator.innerHTML = '<span class="rc_ajax_loader">' + ((loading == undefined) ? 'Loading...' : loading + '...') + '</span>';
		}

	} else if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete") {
		parent.innerHTML = xmlHttp.responseText;
		document.body.style.cursor = 'auto';
	}
}

window['RCJS'] = {};
window['RCJS']['page'] = page;
window['RCJS']['detail'] = detail;

})();


///Google自定义搜索
  google.load('search', '1');
  google.setOnLoadCallback(function(){
    new google.search.CustomSearchControl().draw('cse');
  }, true);
