/*
Author:The Wpbus Theme Team
Author URI: http://www.wpbus.com
*/

//Tabs
	$(function(){
		var $titleLi = $("#coms-title li"),
			hov = "current",
			$warp = $("#coms-content"),
			$warpUL = $warp.find(".tab-coms"),
			$warpUlone = $warpUL.eq(0);
		$warpUL.hide();
		$warpUlone.show();
		
		function Height (){
			$warpUL.each(function(){
				$warp.height("");
				$warpUL.height("");
			});			
		}
		$("*").bind("click",function(){ Height () })
		
		$titleLi.click(
			function(){
				var navLiindex = $(this).index(),
					$listUl = $warpUL.eq(navLiindex),
					boxheight = $listUl.innerHeight();	
				$(this).addClass(hov).siblings().removeClass(hov);
				$listUl.siblings().fadeOut(300);
				$warp.stop().animate({ height:boxheight}, function(){$listUl.fadeIn();Height ()});	
			}	
		);
	});

//switch
	$(document).ready(function() {

		$(".switch").click(function() {
				if ($('.user-form').css("display")=="none")
					$('.user-form').fadeIn('fast');
				else
					$('.user-form').fadeOut('slow');
		});
	});


//search
	$(function(){
		$("#s")
		.attr({value:"请输入搜索关键词"})		
		.blur(function(){$(this).val($(this).val())})
		.focus(function(){$(this).val("")})
	})


//Resize Large Images
jQuery(document).ready(function(){
	var size = 530;
	var image = jQuery('#content img');
	
	for (i=0; i<image.length; i++) {
		var bigWidth = image[i].width;
		var bigHeight = image[i].height;
	
		if (bigWidth > size) {	
			var newHeight = bigHeight*size/bigWidth;
			image[i].width = size;
			image[i].height = newHeight;
		}
	}
});

//sticky
	$(function(){
	var $title = $(".sticky .title h2 span"),
		$open = "open",
		$close = "close",
		$boxp = $(".sticky .sticky-intro");
		$boxp.height($boxp.innerHeight());
		$boxp.hide();
		function ani(){$boxp.animate({height:'toggle',opacity:'toggle'},200);}
		$title.click(function(){
		if( $(this).attr("class")==$open)
		{
			$(this).removeClass($open).addClass($close);
			ani();
		}else
		{
			$(this).removeClass($close).addClass($open);
			ani();
		}
	})
	
});


//标题提示效果处
var sweetTitles = {
	x : 10,	
	y : 20,	
	tipElements : "a",
	init : function() {
		$(this.tipElements).mouseover(function(e){
			this.myTitle = this.title;
			this.myHref = this.href;
			this.myHref = (this.myHref.length > 200 ? this.myHref.toString().substring(0,200)+"..." : this.myHref);
			this.title = "";
			var tooltip = "";
			if(this.myTitle == "")
			{
			    tooltip = "";
			}
			else
			{
			    tooltip = "<div id='tooltip'><p>"+this.myTitle+"</p></div>";
			}
			$('body').append(tooltip);
			$('#tooltip')
				.css({
					"opacity":"0.8",
					"top":(e.pageY+20)+"px",
					"left":(e.pageX+10)+"px"
				}).show('fast');	
		}).mouseout(function(){
			this.title = this.myTitle;
			$('#tooltip').remove();
		}).mousemove(function(e){
			$('#tooltip')
			.css({
				"top":(e.pageY+20)+"px",
				"left":(e.pageX+10)+"px"
			});
		});
	}
};
$(function(){
	sweetTitles.init();
});

