var cMsgId="o3msg";
var nX=0, nY=0;
var oThis;
$(document).bind('mousedown',function(e){ 
	nX=e.pageX;
	nY=e.pageY;
	oThis=e.currentTarget;
});
$(function() { $("a[rel^='prettyPhoto']").prettyPhoto({ default_width: 600, default_height: 400, social_tools: '', deeplinking: false}); });
$(function() { $('body').prepend('<div id="'+cMsgId+'" style="display:none;font-size:12pt"></div>'); });
$(function() { $("#"+cMsgId).dialog({ autoOpen: false, show: 'blind', hide: 'fade', modal: false }); });
function o3_ShowMsg( cSource, cTitle, cCloseTxt, nAutoClose, nMinWidth, nMinHeight ) {
	var cId = "#" + cMsgId;
	if( $(cId).dialog("isOpen") ) $(cId).dialog("close");
	cTitle = cTitle ? cTitle : "O<sub><small>3</small></sub>訊息視窗";
	nMinWidth = nMinWidth ? nMinWidth : 180;
	nMinHeight = nMinHeight ? nMinHeight : 120; 
	$(cId).dialog('option',{ title: cTitle, minWidth: nMinWidth, minHeight: nMinHeight });
	if (cCloseTxt)
		$(cId).dialog({ buttons: [ { text: cCloseTxt, click: function(){ $(this).dialog("close");} } ] });
	else
		$(cId).dialog({ buttons: [] });
	if (cSource) {
		if ( cSource.charAt(0)=="/" || cSource.substr(0,4).toLowerCase=="http" )
			$(cId).load( cSource );
		else
			$(cId).html( cSource );
		$(cId).dialog('open');
		if (nAutoClose) setTimeout("o3_HideMsg()",nAutoClose*1000);
		return true; }
	else
		return false ;
}
function o3_HideMsg() {
	if ( $("#"+cMsgId).dialog("isOpen") )
		$("#"+cMsgId).dialog('close');
}
function o3_CheckLogin( cId, nAllowCat ) {
if (cId=="") {
	var cURL = document.URL;
	o3_ShowMsg( "/hoper/Login2.asp?URL=" + cURL + "&fid=login3", "Login", null, null, 300, 180 );
	return false;
}
else
	if ( nAllowCat && nHoperCat ) 
		if ( (nAllowCat & nHoperCat) == 0 ) { o3_ShowMsg( "權限不足!" ); return false; }
	return true;
}
function o3_GetPos( cSelecter, oObj, nRelTop, nRelLeft, nRelBottom, nRelRight, nIdx ) {
	nIdx = nIdx ? nIdx : 0;
	if (!oObj) oObj = $(cSelecter).get(nIdx);
	if (!oObj) return( [0,0] );
	var nX, nY, oPos;
	oPos = oObj.offset();
	nX = oPos.left;
	nY = oPos.top;
	if (nRelTop) 
		nY = nY + nRelTop;
	else
		if (nRelBottom) nY = nY + oObj.outerHeight + nRelBottom;
	if (nRelLeft) 
		nX = nX + nRelLeft;
	else
		if (nRelRight) nX = nX + oObj.outerWidth + nRelRight;
	alert( nX + "," + nY );
	return( [ nX, nY ] );
}
// jQuery 外掛
;(function($) {
$.fn.extend( {
	"o3_SetLink": function( cLinkId, nRelTop, nRelLeft, nRelBottom, nRelRight, cImgURL, cHref ) {
	var aPos = o3_GetPos( null, this, nRelTop, nRelLeft, nRelBottom, nRelRight );
		this.prepend('<div rel="' + cLinkId + '" style="position:absolute;top:' + aPos[1] + 'px;' + 'left:' + aPos[0] + 'px;z-index:60000">' + cHref + '<img src="' + cImgURL + '" border="0"></a></div>');
	},
	"o3_ClearLink": function( cLinkId ) {
		$("div[rel='" + cLinkId + "']").remove();
	}
} );
})(jQuery);

