dofile( XLCurPath().."Message.lua" )

TopLeftX = 124;
TopLeftY = 89;
BottonRightX = 38;
BottonRightY = 37;
CloseButtonWidth = 40;
MiniButtonWidth = 32;
ButtonHeight = 21;
CloseButtonX = 81;
CloseButtonY = 60;
MiniButtonX = 113;
MiniButtonY = 60;

function OnMainWndPaint( obj, wParm, lParam )
	XLDrawPicture( obj, 0, 0, 124, 89, XLCurPath().."border-top-left.png" );
	XLDrawPicture( obj, 124, 0, 94, 89, XLCurPath().."border-logo.png" );
	
	windowWidth = XLGetWindowRectWidth( obj );
	windowHeight = XLGetWindowRectHeight( obj );

	XLDrawPicture( obj, 218, 0, windowWidth -218 - 38, 89, XLCurPath().."border-top-fill.png");
	XLDrawPicture( obj, windowWidth - 38, 0, 38, 89, XLCurPath().."border-top-right.png" );

	XLDrawPicture( obj, 0, 89, 124 ,windowHeight - TopLeftY - BottonRightY, XLCurPath().."border-left.png" );
	XLDrawPicture( obj, 0, windowHeight - 37, 124, 37, XLCurPath().."border-bottom-left.png" );

	--XLDrawPicture( obj, 0, 0, 120, 544, XLCurPath().."ad-left.png" );

	XLDrawPicture( obj, windowWidth - 38, 89, 38, windowHeight - TopLeftY - BottonRightY, XLCurPath().."border-right.png" );

	XLDrawPicture( obj, 124, windowHeight - 37, windowWidth - 124 - BottonRightX, 37, XLCurPath().."border-bottom-fill.png" );
	XLDrawPicture( obj, windowWidth - 38, windowHeight - 37, 38, 37, XLCurPath().."border-bottom-right.png" );

	--XLDrawPicture( obj, 120, 0, 270, 60, XLCurPath().."ad-top.png" );
end

function OnDecratedWindowSize( obj, wParam, lParam )
	windowleft = XLGetWindowLeft( lParam );
	windowtop = XLGetWindowTop( lParam );
	windowWidth = XLGetWindowWidth( lParam );
	windowHeight = XLGetWindowHeight( lParam );
	
	left = windowleft - TopLeftX;
	top = windowtop - TopLeftY;
	Width = windowWidth + BottonRightX + TopLeftX;
	Height = windowHeight + BottonRightY + TopLeftY;
	
--	XLOutputString( "SkinDecorateWindow("..tostring( left )..","..tostring( top ) );
	XLSetRect( obj, left, top, Width, Height );
	XLMoveWindow( lParam, left + TopLeftX, top + TopLeftY, windowWidth, windowHeight );
	
	id = XLGetWindowElement( obj, "close" );
	XLSetRect( id, Width - CloseButtonX, CloseButtonY, CloseButtonWidth, ButtonHeight );
	
	miniid = XLGetWindowElement( obj, "minimize" );
	XLSetRect( miniid, Width - MiniButtonX, MiniButtonY, MiniButtonWidth, ButtonHeight );
	
	--leftadid = XLGetWindowElement( obj, "leftad" );
	--XLSetRect( leftadid, 0, 0, 124, 544 );
	--XLSetClickUrl( leftadid, "http://mediapv.sandai.net/fcg-bin/inmedia_skin?itemid=3&xlpeeruuid=&skinid=71&type=30&url=http://www.google.com " );
	
	--topadid = XLGetWindowElement( obj, "topad" );
	--XLSetRect( topadid, 120, 0, 270, 60 );
	--XLSetClickUrl( topadid, "http://mediapv.sandai.net/fcg-bin/inmedia_skin?itemid=3&xlpeeruuid=&skinid=71&type=31&url=http://www.baidu.com " );
	
	XLSetTransparentRect( obj, TopLeftX, TopLeftY, windowWidth, windowHeight );
end

function OnCloseMouseMove( obj, wParam, lParam )
	if XLIsCapture( obj ) == 1 then
		if XLIsMouseInRect( obj ) == 1 then
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."close-click.png" );
		else
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."Close-hover.png" );
		end
	else
		if XLIsMouseInRect( obj ) == 1 then
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."Close-hover.png" );
		else
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."Close-normal.png" );
		end
	end
end

function OnCloseLMouseButtonDown( obj, wParam, lParam )
	XLSetCapture( obj );
	XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."close-click.png" );
end

function OnClosePaint( obj, wParam, lParam )
	XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."close-normal.png" );
end

function OnCloseLMouseButtonUp( obj, wParam, lParam )
	if XLIsMouseInRect( obj ) == 1 then
		XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."close-hover.png" );
	else	
		XLDrawPictureNoCoverAlpha( obj, 0, 0, 40, 21, XLCurPath().."close-normal.png" );
	end
end

function OnMinimizeMouseMove( obj, wParam, lParam )
	if XLIsCapture( obj ) == 1 then
		if XLIsMouseInRect( obj ) == 1 then
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-click.png" );
		else
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-hover.png" );
		end
	else
		if XLIsMouseInRect( obj ) == 1 then
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-hover.png" );
		else
			XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-normal.png" );
		end
	end
end

function OnMinimizeLMouseButtonDown( obj, wParam, lParam )
	XLSetCapture( obj );
	XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-click.png" );
end

function OnMinimizePaint( obj, wParam, lParam )
	XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-normal.png" );
end

function OnMinimizeLMouseButtonUp( obj, wParam, lParam )
	if XLIsMouseInRect( obj ) == 1 then
		XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-hover.png" );
	else
		XLDrawPictureNoCoverAlpha( obj, 0, 0, 32, 21, XLCurPath().."mini-normal.png" );
	end
end

function OnInitSkin( obj, wParam, lParam )
	XLSetCanDrag( obj );
	XLSetLayerWindow( obj );
end

MainWndID = XLRegisterWindow( "XLTipsMainWnd" );
XLRegisterMessage( MainWndID, WM_PAINT, "OnMainWndPaint" );
XLRegisterMessage( MainWndID, WM_DECORATEDWINDOWSIZE, "OnDecratedWindowSize" );
XLRegisterMessage( MainWndID, WM_INITSKIN, "OnInitSkin" );

CloseID = XLRegisterWindowElement( MainWndID, "close", 0, 0, 1, 1, SC_CLOSE );
MiniID = XLRegisterWindowElement( MainWndID, "minimize", 0, 0, 1, 1, SC_MINIMIZE );
XLRegisterElementMessage( CloseID, WM_PAINT, "OnClosePaint" );
XLRegisterElementMessage( CloseID, WM_MOUSEMOVE, "OnCloseMouseMove" );
XLRegisterElementMessage( CloseID, WM_LBUTTONDOWN, "OnCloseLMouseButtonDown" );
XLRegisterElementMessage( CloseID, WM_LBUTTONUP, "OnCloseLMouseButtonUp" );
XLRegisterElementMessage( MiniID, WM_PAINT, "OnMinimizePaint" );
XLRegisterElementMessage( MiniID, WM_MOUSEMOVE, "OnMinimizeMouseMove" );
XLRegisterElementMessage( MiniID, WM_LBUTTONDOWN, "OnMinimizeLMouseButtonDown" );
XLRegisterElementMessage( MiniID, WM_LBUTTONUP, "OnMinimizeLMouseButtonUp" );

--leftad = XLRegisterWindowElement( MainWndID, "leftad", 0, 0, 1, 1, -1 );
--topad = XLRegisterWindowElement( MainWndID, "topad", 0, 0, 1, 1, -1 );	

XLSkinDecorateWindow( "XLTipsMainWnd", "XLTipsWnd" );
