$(function(){
	
	$("#search_text").keypress(function(e){
		if (e.keyCode == 13) {
			location.href="/trend/search/k/"+$("#search_text").val()+"/";
		}
	});
	$("#seartch_submit").click(function(){
		location.href="/trend/search/k/"+$("#search_text").val()+"/";
		
	});
	$("#search_text2").keypress(function(e){
		if (e.keyCode == 13) {
			location.href="/trend/search/k/"+$("#search_text2").val()+"/";
		}
	});
	
	$("#seartch_submit2").click(function(){
		location.href="/trend/search/k/"+$("#search_text2").val()+"/";
		
	});
	$(".showdescription").click(function(){
		var description = $(this).parent().find(".visibledescription");
		description.css("display","inline");
		$(this).empty();
		
	});  
	$('.imgo').lightBox({
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif'
	});
	$('.imgn').lightBox({
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif'
	});
	//Select all anchor tag with rel set to tooltip
	$('a[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY + 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
		
	});
	
});
function waitView(item){
	item.css("position","relative");
	var left = (item.width()-32)/2;
	var top = (item.height()-32)/2;
	var wrapper = item.append("<div class='wait_view_wrapper' style='position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:#fff;filter: alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;'></div>");
	wrapper.append("<img class='wait_view_img' style='position:absolute;margin:auto;left:"+left+"px;top:"+top+"px;' src='/images/loading.gif' />");
}
function nowaitView(item){
	item.find(".wait_view_img").each(function(){
		$(this).remove();
		
	});
	item.find(".wait_view_wrapper").each(function(){
		$(this).remove();
		
	});
}
