$(document).ready(function () {
	$('#loading').fadeOut(500);
	
	$('a#logout').click(function () {$.getdata('source=user&act=logout&redirect=?pager/index'); });
	
	$('#myForm input').keydown(function(e) {
		if (e.keyCode == 13) {
			if($(this).attr('id') != 'searchkey') {
				formCheck();
			} else {
				$('#q').val($('#searchkey').val());
				$('#cse-search-box').submit();
			}
		}
	});
	
	$('div#logo img').mouseover(function (){
			$('div#logo').css('cursor','pointer');
		}).click(function (){
			$.goto({url:'?pager/'});
	});
	
	$('input#btnsearch').click(function() {
		$('#q').val($('#searchkey').val());
		$('#cse-search-box').submit();
	});
	
	/*$('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });*/
	
});

captchaReload = function () {
Recaptcha.reload();
}

showMessage = function (msg){
	var msgBox=$("<div>").addClass("msgBox");
	$("body").append(msgBox);
	msgBox.append("You click on: <br>"+msg);
	setTimeout(function(){msgBox.fadeOut(500,function(){msgBox.remove();})},3000)
}

show_article = function (source, action, frame, ptype, offset, page) {
	if(parseInt(page) > 0) { $.pagination(page); }
	$.addField('offset',offset);
	$.addField('frame',frame);
	$.addField('ptype',ptype);
	$('#source').val(source);
	$('#act').val(action);
	$('html, body').animate({scrollTop:'94px'}, 'slow');
	$.sendform();
	return false;
}

showArticleFeedbackForm = function (reply_id,title) {
	if(typeof nickname == 'undefined') {
		$.msgshow({type:'MEMBER',title:'Member Alert',cont:'Please login to post comments!',funct:'$.goto({\'url\':\'?user/index\'})'});
		return ;
	}

	var str = '<div id="msg_overall"><div id="msg_title"><div class="caption">Leave your Comment: ' + title + '</div></div><div id="msg_content">' +
		'<div class="style3">' +
		'	<div class="content">' +
		'		<div class="art-reply-left">' +
		'			<span class="text">Display Name</span>' +
		'			<span class="value">' + nickname + '</span>' +
		'		</div>' +
		'		<div class="art-reply-right">' +
		'			<span class="text"><span>Comment</span></span>' +
		'			<textarea id="reply_post" name="reply_post" style="width:300px"></textarea>' +
		'			<input id="reply_id" name="reply_id" value="' + reply_id + '" type="hidden" />' +
		'			<div class="clearboth"></div>' +
		'		</div>' +
		'	</div>' +
		'</div><div id="msg_footer"></div></div></div>';

	if($('div#frame_id').exists()) { $('div#frame_id').remove(); }
	// Create new element typeof DIV
	$.maskall();
	$("<div/>").attr("id", "frame_id").addClass('hidden').removeClass('show').appendTo('form#myForm');
	$('div#frame_id').html(str);
	$('#frame_id').fadeIn('slow',function(){$(this).show().addClass('show').removeClass('hidden');});
	
	var btn_str = '<input type="button" value="Cancel" onclick="$.msghide()" class="submit" /> <input type="button" onclick="reply_comment()" value="Ok" class="submit" />'
	$('#msg_footer').html(btn_str);
}

function reply_comment() {
	$('#source').val('article');
	$('#act').val('reply');
	$.sendform();
	return false;
}
