$(function(){
	$('ul.menu li:last').css('border','none');
	$('ul.menu li').each(function(){
		var theSon = $(this).find('ul');
		if(theSon.length==1){
			$(this).bind('mouseenter',function(){
				theSon.fadeIn(250);
			}).bind('mouseleave',function(){
				theSon.fadeOut(250);
			});
		}
	});
	$('.btn_over').each(function(){
		var theType = $(this).attr('src').match(/\.[a-z]{3}$/)[0].replace('.','');
		$(this).bind('mouseover', function(){
			this.src = this.src.replace("."+theType,"2."+theType);
		}).bind('mouseout', function(){
			this.src = this.src.replace("2."+theType,"."+theType);
		});
	});
	var displayTd = ($.browser.msie)?"block":"table-row";
	if(location.href.search('/press_releases.htm')!=-1){
		var theSelector = $('#year_selector');
		for(x in yearList){
			theSelector.append('<option value="'+yearList[x]+'">'+yearList[x]+'</option>')
		}
		theSelector.bind('change',function(){
			var theYear = $(this).find('option:selected').val();
			$('#select_table tr:not(.header)').each(function(){
				$(this).css('display',displayTd);
			});
			if(theYear!='-'){
				$('#select_table>tbody>tr:not(.header)').each(function(){
					if($(this).find('td:eq(0)').text().search(eval('/'+theYear+'$/'))==-1){
						$(this).css('display', 'none');
					}
				});
			}
		});
	}
});

function callBack(){
$(".tip").tooltip({
		tip: ".tooltip",
		effect: 'slide',
		offset: [-5,60],
		onBeforeShow: function() {
		//		$(this).pngFix();
			//alert(this.getTip().html());
			tips_obj = this.getTip();
			text1 = $('.tip').attr('alt');
			text2 = '<a href="'+$(".tip").attr('href')+'">'+text1+'</a>';
			//alert($(text2).text());
			tips_obj.html((text2));

			//tips_obj.wrap('<a href="'+$(".tip").attr('href')+'"></a>');
			tips_obj.append($('<span class="arrow">&nbsp;</span>'));
			//this.getTip().pngFix();
		},
		onHide: function() {
			this.getTip().find('.arrow').remove();
		}
	});
}

$(document).ready(function(){
	$.getScript(domain+'js/jquery.tools.min.js', function(){
		callBack();
	});
	var headID = document.getElementsByTagName("head")[0];
/*	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = 'http://www.512rjc.hk/js/jquery.tools.min.js';
	headID.appendChild(newScript);
	var newScript2 = document.createElement('script');
	newScript2.type = 'text/javascript';
	newScript2.src = 'http://www.512rjc.hk/js/onload.js';
	headID.appendChild(newScript2);*/
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = domain+'css/qtip.css';
	cssNode.media = 'all';
	headID.appendChild(cssNode);
//	$('body').append('<div class="tooltip"></div>');
});
