/********************************************************************************

	IE用PNG対策フィルタセッター
		作成者	Masashi Kikkawa

	【説明】
		ページ内要素のclass属性に「iepngfilter」を入れると、
		その要素で使用しているPNG画像がIE5.5および6でも透過して表示される。

	【使用上の注意】
		対象PNGファイルが置いてある階層に「iepngfilter_blank.gif」を置くこと。
		背景画像ではタイリングされないので注意。

	【更新履歴】
		2008.07.03 v.1.02
			MacIEに対応。
		2008.05.17 v.1.01
			ロールオーバーセッターとの連動に対応。
		2008.05.15 v.1.00
			公開。

********************************************************************************/



//_______________________________________________________________________________
//	PNGフィルタ
var	eoPngFilter	=	new class_eoPngFilter();
function	class_eoPngFilter()
{
	this.objOnload	=	window.onload;	//	既存のonloadイベント

	//	定数
	this.cvIMG_BLANK	=	'iepngfilter_blank.gif';

	//___________________________________________________________________________
	//	フィルタ初期化
	this.Init	=	function()
	{
		var	aEleList	=	new Array();
		var	aTgtStock	=	new Array();

		//	既存のonLoadイベントを実行
		if( this.objOnload != null )	this.objOnload();

		//	動作環境判定
		if( !/MSIE (5\.5|6\.)/.test( navigator.userAgent ) )
		{	//	Win IE5.5 or 6でない場合
			return;
		}

		//	対応チェック
		if( !document.getElementsByTagName )
		{
			return;
		}

		//	タグの一覧を取得して検索
		aEleList	=	document.getElementsByTagName( '*' );
		for( var i=0; i<aEleList.length; i++ )
		{
			//	クラス名判定
			if( /(^|\s)iepngfilter(\s|$)/.test( aEleList[i].className ) )
			{
				aTgtStock[aTgtStock.length]	=	aEleList[i];
			}
		}

		//	フィルタセット
		for( var i=0; i<aTgtStock.length; i++ )
		{
			//	使用フラグをセット
			this.SetUseFlg( aTgtStock[i] );

			//	スタイルをセット
			if( (/\.png$/i).test( aTgtStock[i].src ) )
			{	//	img画像の場合
				var	vPath	=	aTgtStock[i].src.substring( 0, aTgtStock[i].src.lastIndexOf('/')+1 );
//				aTgtStock[i].style.width	=	aTgtStock[i].width + 'px';
//				aTgtStock[i].style.height	=	aTgtStock[i].height + 'px';
				this.SetAlphaImageLoader( aTgtStock[i], aTgtStock[i].src );
				aTgtStock[i].src			=	vPath + this.cvIMG_BLANK;
			}
			if( aTgtStock[i].currentStyle.backgroundImage.match(/^url[("']+(.*\.png)[)"']+$/i) )	//'
			{	//	背景の場合
				this.SetAlphaImageLoader( aTgtStock[i], RegExp.$1 );
				aTgtStock[i].style.backgroundImage	=	'none';
				if( !aTgtStock[i].style.width  && !aTgtStock[i].style.height )
				{
					aTgtStock[i].style.width	=	aTgtStock[i].offsetWidth;
				}
			}
		}
	};

	//___________________________________________________________________________
	//	AlphaImageLoaderをセット
	this.SetAlphaImageLoader	=	function( objImg, vImgName )
	{
		objImg.style.filter	=	'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + vImgName + ')';
	};

	//___________________________________________________________________________
	//	AlphaImageLoaderの画像名を取得
	this.GetAlphaImageLoaderSrc	=	function( objImg )
	{
		return	objImg.style.filter.substring( objImg.style.filter.lastIndexOf('=')+1, objImg.style.filter.lastIndexOf(')') );
	};

	//___________________________________________________________________________
	//	使用フラグをセット
	this.SetUseFlg	=	function( objEle )
	{
		objEle.setAttribute( 'iepngfilter', 1 );
	};

	//___________________________________________________________________________
	//	使用フラグを取得
	this.GetUseFlg	=	function( objEle )
	{
		return	objEle.getAttribute( 'iepngfilter' );
	};
}




//_______________________________________________________________________________
//	window.onloadにセット
window.onload	=	function()
{
	//	PNGフィルタ初期化
	eoPngFilter.Init();
}





