/********** show ul.children **********/
jQuery(document).ready(function($) {
	function showUl(menu) {
		menu.find('li ul.children').hide();
		menu.find('li:not(".current_page_item") > ul.children').each(function() {
			$(this).parent('li').hover(function() {
				$(this).children('.children:not(:animated)').animate({opacity: 'show', height: 'show'}, 'slow');
			}, function() {
				$(this).children('.children').animate({opacity: 'hide', height: 'hide'}, '100');
			});
		});
	}
	showUl($('#access'));
	showUl($('.widget-area'));
});

/********* sidebar ************/
/* search label */
jQuery(document).ready(function($) {
	$('#s').attr('value', 'Input keywords to search');
	$('#s').focus(function() {
		if ($(this).val() == 'Input keywords to search') {
			$(this).val('')
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val('Input keywords to search')
		}
	});
});
/* select */
jQuery(document).ready(function($) {
	$('.widget-area').find('select').wrap('<div class="select"></div>');
});

/********* wave background of img in hyper link ****************/
jQuery(document).ready(function($) {
    $('.entry-content a img').parent('a').css({'background': 'none', 'padding': '0'});
});

/********* odd background for related posts *******/
jQuery(document).ready(function($) {
	$('.related_post').find('li').filter(':odd').addClass('alt');
});

/**************** hide author info ***************/
jQuery(document).ready(function($) {
    if ($('#author').val()) {
        var info = $('#author_info');
        var author = $('#author').val();
        info.hide();
        $('#author').css('fontWeight', 'bold');
        info.before('<div id="welcome_back">Welcome Back '+author+'. <span id="edit_info" style="cursor: pointer; color: #BF514C;">Edit your info.</span></div>');
        var editInfo = $('#edit_info');
        editInfo.click(function() {
            info.animate({opacity: 'toggle', height: 'toggle'}, 'slow');
            if (editInfo.text() == 'Edit your info.') {
                $(this).text('Close.');
            } else {
                $(this).text('Edit your info.');
            }
        });
    }
});

/********** Reply with @ somebody **********/
jQuery(document).ready(function($) {
	$('.inner-wrap .reply').click(function() {
		var commentid = $(this).parent().parent().attr('id'); //取得所回复的评论id
		var name = $(this).parent().find('.comment-author .fn').text(); //取得所回复的评论用户名
		$('#comment').attr('value','<a href="#'+commentid+'">@'+name+'</a>: ').focus();
	});
	$('#cancel-comment-reply-link').click(function() {
		$('#comment').attr('value',''); //点击取消回复时清空输入框
	});
});

/********** submit comment with Ctrl+Enter **********/
window.onload = function() {
	if (!document.getElementById) return false;
	if (!document.getElementById("comment") || !document.getElementById("submit")) return false;
	document.getElementById("comment").onkeydown = function (moz_ev) {
		var ev = null;
		if (window.event){
			ev = window.event;
		}
		else{
			ev = moz_ev;
		}
		if (ev != null && ev.ctrlKey && ev.keyCode == 13) {
			document.getElementById("submit").click();
		}
	}
};
