$(window).load(function(){
	//initialize after images are loaded
	$('#content, #sidebar').equalbox();
});

$('a[rel=external]').click(function(){
	window.open($(this).attr('href'));
	return false;
});

$('.main_content a[rel=external]').each(function(){
	if ($(this).children().length < 1 && $(this).css('background-image') == 'none') {
		$(this).css({
			'padding-right':'30px',
			'background':'url(/img/outsite_link.png) center right no-repeat'
		});
	};
});

if (($.browser.msie) && (parseInt($.browser.version) == 6)){
	$('#header h1 img').attr('src', '/img/ares_logo.gif');
};

function mouse_over(){
	if (($.browser.msie) && (parseInt($.browser.version) == 6)){
		$(this).addClass('hover').find("div.level2").show();
	} else {
		$(this).addClass('hover').find("div.level2").stop().fadeIn('fast');
	}
};

function mouse_out(){
	if (($.browser.msie) && (parseInt($.browser.version) == 6)){
		$(this).find("div.level2").hide();
	} else {
		$(this).find("div.level2").stop().fadeOut('fast');
	}
	$("li.hover").removeClass('hover');
};

var config = {
	sensitivity: 2,
	interval: 150,
	over: mouse_over,
	timeout: 300,
	out: mouse_out
};

$("#nav_main li:has('div.level2')").hoverIntent(config);

if ($("#content").height() > $(window).height()){
	$("#icons").append('<img src="/img/back_to_top.png" alt="回頁首" title="回頁首" />')
	.find('img[title="回頁首"]').click(function(){
		$("html,body").animate({scrollTop: '0px'}, 2000);
	});
}

var defaultText = "站内搜寻";
$("#search_box input.text").css('color', '#aaa');
$("#search_box").show();
$("#search_box input.text").bind('focus', function(){
	if ($(this).val() == defaultText){
		$(this).val('');
	}
	$(this).css('color', '#555')
});
$("#search_box input.text").bind('blur', function(){
	if ($(this).val() == ''){
		$(this).val(defaultText);
	}
	$(this).css('color', '#aaa');
});

$('.main_content a').each(function(){
	var $href = $(this).attr('href');
	if ($(this).text().substring(0, 7) != 'http://') {
		$(this).append('<span class="print"> [' + $href + '] </span>');
	}
});

