$(document).ready(function(){
	//初始化
	init();
	/*
	//菜单首次载入的时候自动算出宽度来
	$('#featuredCates .c .subs').hover(function(){
		//alert(1);
		if (!$(this).hasClass('adjusted')){
			//统计有几列
			p = $('.sub', this).length;
			//一列的时候去掉边框，计算宽度
			if (p > 1){
				$('.sub', this).parent().addClass('part');
				$('.sub:last', this).parent().css('border', 0);
				$('.areas', this).css('width', 170*p+'px')
				$(this).addClass('adjusted');
			}
		}
		//如果是seeAll加载
		if ($(this).hasClass('seeAll') && !$(this).hasClass('loaded')){
			$.get($('#ROOT').val()+'ajax.php', {'ajax':'1', 'act':'nav_see_all', 'lang':$('#LANG').val(), 'is_static':is_static_page()}, function(r_seeAll){
				$('#featuredCates .seeAll .area').HTML(r_seeAll).removeClass('load');
			});
			$(this).addClass('loaded');
			r_seeAll = '';
		}
	}, function(){
	});
	$('#featuredCates li:first').hover(function(){
		$('#featuredCates .left').addClass('h');
	},function(){
		$('#featuredCates .left').removeClass('h');
	});
	$('#featuredCates li:last').hover(function(){
		$('#featuredCates .right').addClass('h');
	},function(){
		$('#featuredCates .right').removeClass('h');
	});
	*/
	//点击H1隐藏
	$('h1').click(function(){
		$(this).hide();
		$('#searchKey').focus();
	});

	//header 搜索
	$('#searchArea form').submit(function(){
		var k = $.trim($('#searchKey').val());
		if (k == ''){
			jAlert(DEFINE_PLZ_FILL_KEYWORDS, DEFINE_NOTICE);
		} else {
			var reg = /\s/g;
			k = k.replace(reg,"+");
			location.href = $('#ROOT').val()+'search--'+k+'----1.html';
		}
		return false;
	});
	//站内信
	$('#fMsgSend').click(function(){
		if ($('#IS_LOGGED').val() != '1'){
			loginJoin('login');
		} else {
			var fMsgSub = $.trim($('#fMsgSub').val());
			var fMsgCont = $.trim($('#fMsgCont').val());
			if (fMsgSub == '' || fMsgCont == ''){
				jAlert(DEFINE_FILL_ALL_FIELDS, DEFINE_NOTICE);
			} else {
				jWait();
				$.post($('#ROOT').val()+'ajax.php', {'ajax':'1', 'msg_subject':fMsgSub, 'msg_content':fMsgCont, 'msg_type':'other', 'act':'interalMsg', 'msg_url':$('#URL').val(), 'newSub':1, 'lang':$('#LANG').val()}, function(r){
					if (r == 'OK!'){
						jOk(DEFINE_THX_FOR_YOUR_MSG);
						$('#fromContact select, #fromContact textarea').val('');
					} else {
						jError(DEFINE_MSG_SENT_FAILURE);
					}
				});
			}
		}
		return false;
	});
	//点击主题获得主题内容
	$('#fMsgSub').click(function(){
		var o = $(this);
		if (o.hasClass('wait')){
			if ($('#formPubSendMsg select').length>0){
				o.html($('#formPubSendMsg select').html()).removeClass('wait');
				return true;
			}
			jWait();
			$.get($('#ROOT').val()+'ajax.php', {'ajax':'1', 'act':'getMsgSubjectOption', 'lang':$('#LANG').val()}, function(r){
				o.append(r).removeClass('wait');
				jDone();
			});
		}
	});
	//go top
	$('#icons').css('z-index', '99999999');
	/*
	$('#icons a').fadeTo('slow', 0.25);
	$('#icons a').hover(function(){
		$(this).stop().fadeTo('slow', 1);
	}, function(){
		$(this).stop().fadeTo('slow', 0.25);
	});
	*/
	//top
	$('#icons .top').click(function(){
		$('html, body').animate({scrollTop: 0}, 500);
		return false;
	});
	//rss
	$('#icons .rss').click(function(){
		if (!$(this).hasClass('clicked')){
			$.get($('#ROOT').val()+'ajax.php', {'ajax':'1', 'act':'subscribe_rss', 'txt':$('#freeTo').text(), 'lang':$('#LANG').val()}, function(){
				$(this).addClass('clicked');
			});
		}
	});
	//icon account
	$('#icons .myAcc').click(function(){
		$('#icons .top').trigger('click');
		setTimeout(function(){
			$('#infos').hide();
			infosShow();
		}, 600);
		return false;
	});
	//add to my favious
	$('#addToFav').click(function(){
		if ($('#IS_LOGGED').val() == '0'){
			loginJoin('login');
			return false;
		}
		//jPrompt = function(message, value, title, callback) {
		var t = document.title.replace('- '+DEFINE_SITE_TITLE, '');
		var u = $("#URL").val();
		var msg = '<table width="100%" border="0" cellspacing="3" cellpadding="2"><tr><td>'+DEFINE_TITLE+':</td><td>'+t+'</td></tr><tr><td>'+DEFINE_URL+':</td><td>'+u+'</td></tr></table>';
		jPrompt(msg, DEFINE_MY_REMARKS, DEFINE_ADD_TO_MY_FAVORITE, function(r){
			if (r){
				$.post($('#ROOT').val()+'ajax.php?ajax=1&act=add_to_my_favorite', {'t':t, 'u':u, 'r':r, 'lang':$('#LANG').val()}, function(r){
					run(r);
				});
			}
		});
		return false;
	});

	//点击上面拉下来
	$('#infosAct').click(function(){
		$('p', this).toggleClass('o');
		if ($('#infos').hasClass('o')){
			infosHide();
		} else {
			infosShow();
		}
	});
	//分类排序
	$('#nwe_add_order').change(function(){
		$(this).closest('form').submit();
	});
	//翻译语言
	$('#footer .trans li').click(function(){
		window.open($('#ROOT').val()+'ajax.php?ajax=1&act=trans&URL='+$("#URL").val()+'&lang='+$(this).attr('class'), '_blank');
	});
	//判断是否是第一次进入是的话执行下面的操作
	cookie_to_input();
	if ($('#IS_FIRST_VISIT').val() == '1' && !$('body').hasClass('_blank')){
		$('#infosAct').trigger('click');
		setTimeout(function(){
			if ($.trim($('#infos .improtantNotice').html()) != ''){
				infosHide(78);
			} else {
				infosHide(28);
			}
		}, 5000);
	}
	//live function
	liveAll();
	//add addthis.com js code
	$('#hidden').append('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=buyincoins"></script>');
	$('#pubDailySale .X').click(function(){
		$('#pubDailySale').hide();
	});
});
