/*******************************************************************
**--> Intro: For Beeteam Customize WordPress Themes；
**--> Author: 51hack@gmail.com
**--> WebSite: http://beeteam.cn
*******************************************************************/

jQuery.noConflict();

jQuery(document).ready(function(){
	jQuery("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])").addClass("external").attr("target","_blank");

});

jQuery(document).ready(function(){
	jQuery("#tagview").toggle(function(){
		jQuery('#trand').hide();
		jQuery('#randTags').hide();
		jQuery('#hrand').hide();
		jQuery('#hlist').show();
		jQuery('#tlist').show();
		jQuery('#listTags').show();
		jQuery('#listroll').show();
		return false;
	},function(){
		jQuery('#trand').show();
		jQuery('#randTags').show();
		jQuery('#hrand').show();
		jQuery('#hlist').hide();
		jQuery('#tlist').hide();
		jQuery('#listTags').hide();
		jQuery('#listroll').hide();
		return false;
	});
	jQuery('#rt').bind('click',function(){
		var st=Math.abs(parseInt(jQuery('#listTags .wp-tag-cloud').css('top')));
		if(!st){
			st=0;
		}
		var total=jQuery('#listTags .wp-tag-cloud').height()-244;
		if(total<0){
			return;
		}
		if(st>23){
			jQuery('#listTags .wp-tag-cloud').css({top:-(st-23)});
			rrdo(st-23);
		}else if(st<=23){
			jQuery('#listTags .wp-tag-cloud').css({top:0});
			rrdo(0);
		}
	});
	jQuery('#rb').bind('click',function(){
		var st=Math.abs(parseInt(jQuery('#listTags .wp-tag-cloud').css('top')));
		if(!st){
			st=0;
		}
		var total=jQuery('#listTags .wp-tag-cloud').height()-244;
		if(total<0){
			return;
		}
		if(st<total-23){
			jQuery('#listTags .wp-tag-cloud').css({top:-(st+23)});
			rrdo(st+23);
		}else if(st>=total-23){
			jQuery('#listTags .wp-tag-cloud').css({top:-total-10});
			rrdo(total);
		}
	});
	var bclick=false;
	var ey='';
	var rpos='';
	jQuery('#rr').bind('mousedown',function(e){
		bclick=true;
		ey=e.clientY;
		jQuery('#rr').html(ey);
		rpos=parseInt(jQuery(this).css('top'))-24;
	});
	jQuery('#rr').bind('mouseup',function(){
		bclick=false;
	});
	jQuery('#rr').bind('mouseout',function(){
		bclick=false;
	});
	jQuery('#rr').bind('mousemove',function(e){
		if(bclick==false){
			return;
		}
		var eyt=e.clientY;
		var el=eyt-ey;
		if(el<-rpos){
			jQuery(this).css({
				'top':'24px'
			});
			jQuery('#listTags .wp-tag-cloud').css({top:0});
			return;
		}
		if(el<169-rpos){
			jQuery(this).css({
				top:Math.ceil(rpos+el+24)+'px'
			});
			var total=jQuery('#listTags .wp-tag-cloud').height()-244;
			var got=Math.ceil(((rpos+el)/169)*(total+10));
			jQuery('#listTags .wp-tag-cloud').css({top:-got});
		}
	});
});

function rrdo(n){
	var total=jQuery('#listTags .wp-tag-cloud').height()-244;
	if(total<0){
		return;
	}
	var l=169;
	jQuery('#rr').css({
		top:Math.ceil(24+(n/total)*169)+'px'
	});
}

jQuery(document).ready(function(){
	jQuery('#sidebar-tags .textwidget a').each(function(){
		jQuery(this).css({
			color:random_color()
		});
	});
});

function random_color(){
	var n=Math.ceil(Math.random()*3);
	switch(n){
		case 1:
			return '#fff';
			break;
		case 2:
			return '#5b5b5b';
			break;
		case 3:
			return '#02aef0';
			break;
	}
}

jQuery(document).ready(function(){
	jQuery('#index a.liked img').hide();
	jQuery('#index a.like').html('likes');
});

jQuery(document).ready(function (){
	var d=new Date();
	var showtime='';
	showtime=d.getMonth()+1+'/'+d.getDate()+'/'+d.getFullYear()+' @ '+d.getHours()+':'+d.getMinutes();
	jQuery('#timeshow').html(showtime);
});

jQuery(document).ready(function (){
	jQuery('#searchform').bind('submit',function (){
		if (jQuery('#s',this).val()=='' || jQuery('#s',this).val()=='Search China Travel blog'){
			alert('Looking for something? Enter your search terms and try again.');
			return false;
		}
	})
});


jQuery(document).ready(function (){
	jQuery('#commentform').bind('submit',function (){
		if (jQuery('#author').val()=='' || jQuery('#email').val()=='' || jQuery('#comment').val()=='' || jQuery('#email').val().indexOf('@')<1){
			alert('An error occurred during submission. Please try again.');
			return false;
		}
	})
});
