//*******************************************************************************
//    File name: mini-album.js
//    Date: 2008/01/24
//    Remark: The java script of Mini-Album block.
//    Author: Mark Yang
//    Note:
//*******************************************************************************
// JavaScript Document

/*
<div id="ID_minialbum_template2" style="font-size: 0px;	font-family: Arial;	letter-spacing: 0px; display:none; visibility:hidden;">
    <div class="transON" id="$PHOTO.ID$"
        onclick="$FUNC.ONCLICK$"
        onmouseover="OnEntryMouseOver(this);" 
        onmouseout="OnEntryMouseOut(this);" title="$PHOTO.DESC$" >
        <img class="minialbum_photo" name="ID_minialbum_photo" id='$IMG.OBJ.ID$' src="$PHOTO.THUMB.URL$" alt="$PHOTO.DESC$" width="80px"/>           
    </div>
</div>
*/


function OnEntryMouseOver (obj) {
    obj.className='transOFF';
}

function OnEntryMouseOut (obj) {
    obj.className='transON';
}

function OnAlbumClick (strId) {
    var ma = g_MainFrame.getObj(MAId);
    if (ma != null) {
        ma.onClick(strId);
    }
}


    

// Object: CMiniAlbum(minialbumId, userdata)
// Parameters: minialbumId=mini-album template's Id. ex:"ID_minialbum"
//             userdata=array to the user's data.
//             OnClickActCB=call back function for 'onclick' event.
//             ***NOTE: the entry index of userdata is the onclick event's parameter.
// Remark: CMiniAlbum object is controlling the mini-album template!

// mini-ablum object apply contents' parameters!
var g_minialbumParams = {
  'strEmptyTemplateId' : 'ID_minialbum_template2',
  'strImgID': '$IMG.OBJ.ID$',
  'strMaID': '$PHOTO.ID$',
  'strMaClick' : '$FUNC.ONCLICK$',
  'strMaThumb' : '$PHOTO.THUMB.URL$',
  'strMaDesc': '$PHOTO.DESC$',
  'strMaDateTime': '$PHOTO.DATE$',
  'strMaDescHtml': '$PHOTO.DESC.HTML$'
}

// mini-ablum object apply info window's parameters!
var g_infowndParams = {
  'photodata' : null,
  'strEmptyTemplateId' : 'ID_Infownd_Template',
  'strMaWidth': '$PHOTO.WIDTH$',
  'strOriMaURL': '$ORI.PHOTO.URL$',
  'strMidMaURL': '$MID.PHOTO.URL$',  
  'strMaTitle': '$PHOTO.TITLE$',
  'strMaDesc': '$PHOTO.DESC$',
  'strMaDateTime': '$PHOTO.DATE$',
  'strMaPos': '$PHOTO.POS$',
  'strPhotoW': '111px', 
  'strDescH': '222px',
  'strEmbedW':'999px'
}    
/*[GUI Modify]********************************************************************************/
// ­×¥¿ miniAlbum photo size
//var _MaxThumbW = 65;
//var _MaxThumbH = 65;
var _MaxThumbW = 75;
var _MaxThumbH = 76;
/*[GUI Modify]********************************************************************************/

function CMiniAlbum (minialbumId, objMainFrame) {
	this.mf = objMainFrame;
	this.tempid = minialbumId;
	this.id = minialbumId + '_' + this.mf.getUniqueId();
	this.objMiniAlbum = $(minialbumId);
	this.objAllUsrAlbum = this.mf.getUsrAlbum(); //userdata;
	//this.objTemplate = $("ID_minialbum_template");
	//this.funcOnClick = OnClickActCB;
	this.strEntryLeadText = "minialbumidx_";
	this.strImgLeadText = "imgidx_";
	this.strEntryStartKeywd = "<!--$MINI.ALBUM.ENTRY.START$-->";
	this.strEntryKeywd = "<!--$MINI.ALBUM.ENTRY$-->";
	this.strEntryEndKeywd = "<!--$MINI.ALBUM.ENTRY.END$-->";
	
	// Function: IsObjExist()
	// Remark: Check is mini-album template html code exist!
	this.IsObjExist = function () {
		return (this.objTemplate != null);
	}

	this.getFixHeight = function () {
		return -1; //this.objTemplate.style.height;
	}
	
	this.getFixWidth = function () {
		return -1; //this.objTemplate.style.width;
	}	
	
	this.resize = function (w, h) {
		this.objMiniAlbum.style.width = w+"px";
		this.objMiniAlbum.style.height = h+"px";
	}
	
	// Function: ResetContent()
	// Remark: Reset the created content!
/*	this.ResetContent = function () {
        var myMiniAlbum = $(this.id).innerHTML;
        var nStartPos = myMiniAlbum.indexOf(strEntryStartKeywd);
        var nStopPos = myMiniAlbum.indexOf(strEntryStopKeywd) + strEntryStopKeywd.length + 1;
        if (nStartPos != -1 && nStopPos != -1) {
            var strResetContent = myMiniAlbum.replace(myMiniAlbum.slice(nStartPos, nStopPos), strEntryStartKeywd+strEntryKeywd+strEntryStopKeywd);
            $(this.id).innerHTML = strResetContent;
        }
	}
*/

/*    this.CalRatioImgSize = function (objSrc, nDestW, nDestH) {
	    var nSrcW = objSrc.width;
	    var nSrcH = objSrc.height;
        if(nSrcW>0 && nSrcH>0){
	        if(nSrcW/nSrcH >= nDestW/nDestH){
	            if(nSrcW > nDestW){  
		            objSrc.width = nDestW;
		            objSrc.height=(nSrcH*nDestW)/nSrcW;
	            }
	        }
	        else{
	            if(nSrcH > nDestH){  
		            objSrc.height = nDestH;
		            objSrc.width = (nSrcW*nDestH)/nSrcH;        
	            }
	        }
        }
    } 
*/
	//
	this.updateUsrAlbum = function () {
	
	}
	//
	this.onClick = function (strId) 
	{
		var testObj = __get(MAId);
		if (__get(CPId).nPlayStatus == _cpsPlay) {
			__get(CPId).onCpPause();
		}
		var photodata = this.mf.getOneAlbumItemById(strId);
		var curSelTrk = this.mf.getCurSelTrk();
		if (curSelTrk != null && photodata[_MaTrkId] != curSelTrk.id) {
			// select chang the track!
			
			this.mf.setCurSelTrk(photodata[_MaTrkId]);
			this.mf.updateTrk();
		}
		this.mf.fireUsrEvent(this.id, _evtMf_SelChgAlbumEntry, MAId, photodata[_MaId]);
	}

	/*
	this.addItem = function (params) {
	}
	this.deleteItem = function (params) {
	}
	this.modifyItem = function (params) {
	}
	*/
	
	this.onAlbumChanged = function (params) {
		/*		
		if (params.op == 'additem') {
			this.addItem(params);
		}
		else if (params.op == 'deleteitem') {
			this.deleteItem(params);
		}
		else if (params.op == 'modifyitem') {
			this.modifyItem(params);
		}*/
		this.applyContent(g_minialbumParams, this.mf.getCurSelTrk());
	}
	
	//
	//this.onWayptSelChg = function () {
	//}
	//
	//this.onSlideChgPos = function () {
	//}
		
	// ex:  this.showAlbumByType(0, 1);
	//		this.showAlbumByType(0);
/*	this.showAlbumByType = function () {
		var tmpAry = [];
		for (var i=0; i<arguments.length; i++) {
			tmpAry.push(arguments[i]);
		}
		var strEnabledAttr =tmpAry.toString();
		if (this.objAllUsrAlbum != null && this.objAllUsrAlbum.length > 0) {
			for (var i=0; i<this.objAllUsrAlbum.length; i++) {
				var curMyAlbum = this.objAllUsrAlbum[i].getAllItems();
				for (var j = 0; j<curMyAlbum.length; j++) {
					var photodata = curMyAlbum[j];
					this.ShowEntry(photodata[_MaId], (strEnabledAttr.indexOf(_PicTypeVal[photodata[_MaOri][_sbType]]) != -1));
				}
			}
		}	
	}
*/
	
	this.showAlbumForGMap = function () {
		if (this.objAllUsrAlbum != null && this.objAllUsrAlbum.length > 0) {
			for (var i=0; i<this.objAllUsrAlbum.length; i++) {
				var curMyAlbum = this.objAllUsrAlbum[i].getAllItems();
				for (var j = 0; j<curMyAlbum.length; j++) {
					var photodata = curMyAlbum[j];
					this.ShowEntry(photodata[_MaId], true);
				}
			}
		}	
	}

	this.showAlbumForSlideShow = function () {
		if (this.objAllUsrAlbum != null && this.objAllUsrAlbum.length > 0) {
			for (var i=0; i<this.objAllUsrAlbum.length; i++) {
				var curMyAlbum = this.objAllUsrAlbum[i].getAllItems();
				for (var j = 0; j<curMyAlbum.length; j++) {
					var photodata = curMyAlbum[j];
					this.ShowEntry(photodata[_MaId], (_PicTypeVal[photodata[_MaOri][_sbType]] == _MaTypeVal['photo'] && photodata[_MaOri][_sbURLAddr] != ""));
				}
			}
		}	
	}

	//
	this.onViewModeSelChg = function (strPageId) {
		if (strPageId.indexOf(GMId) != -1) { // map mode. display all album.
			//this.showAlbumByType(_MaTypeVal['photo'], _MaTypeVal['placemark']); // show user photo & placemark.
			this.showAlbumForGMap();
		}
		else if (strPageId.indexOf(SSId) != -1) { // slide-show mode. display only user photo.
			//this.showAlbumByType(_MaTypeVal['photo']); // display only user photo.	
			this.showAlbumForSlideShow();
		}
	}

	// Function: applyContent()
	// Remark: Apply all user data to create mini-album content!
	this.applyContent = function (params, objCurTrk) {
	    // get the current selected track first!
		//var objCurTrk = this.mf.getCurSelTrk();
		if (objCurTrk == null) {
		    return false;
		}
		
	
		/* 	o: photoId
			1: time stamp
			2: Lat
			3: Lng
			4: trackId
			5: marker icon Id
			6: small info icon id
			7: type Id
			8: Original photo [URL, type, width, height]
			9: Middle size photo [URL, type, width, height]
			10: thumbnail size photo [URL, type, width, height]
			11: title
			12: description
		*/
		if (this.objAllUsrAlbum != null && this.objAllUsrAlbum.length > 0) {
/*[GUI Modify]********************************************************************************/
			//var strTotalHtml = null;
			var strTotalHtml = "";
/*[GUI Modify]********************************************************************************/
			var aryTrkName = this.mf.getAllTrackName();
			for (var i=0; i<aryTrkName.length; i++) { // for each track.
				var curMyAlbum = this.mf.getAlbumByTrkId(aryTrkName[i]).getAllItems();
				for (var j=0; j<curMyAlbum.length; j++) { // for each item in it.
					var strHtml = $(params.strEmptyTemplateId).innerHTML;
					var photodata = curMyAlbum[j];
					if (photodata[_MaState] == _EnableVal['disable']) {
						continue;
					}
					// replace the photo Id.
					strHtml = ReplaceAll(strHtml, params.strMaID/*"$PHOTO.ID$"*/, this.strEntryLeadText+photodata[_MaId]); //this.strEntryLeadText+i);
					strHtml = ReplaceAll(strHtml, params.strImgID/*"$IMG.OBJ.ID$"*/, /*this.strImgLeadText+*/photodata[_MaId]);
					// replace the 'onclick' call-back function!
					strHtml = ReplaceAll(strHtml, params.strMaClick/*"$FUNC.ONCLICK$"*/, 
					"OnAlbumClick('" + photodata[_MaId] + "');");
					// prepare the thumbnail's URL. (if thumbnail not specified, use original size one!
					var bUseThumb = photodata[_MaThm][_sbURLAddr] != '' //&& photodata[_MaThm][_sbURLW] >= 0 && photodata[_MaThm][_sbURLH] >= 0;
					var srcPhotoUrl =  bUseThumb ? photodata[_MaThm] : photodata[_MaOri];

					// create a Image object!
					//var tmpImg = new Image;
					//tmpImg.src = srcPhotoUrl;
					//photodata[0] = tmpImg; // keeps the image object!
					// replace the Image's URL.
					var now = new Date();
//* byFred			strHtml = ReplaceAll(strHtml, params.strMaThumb/*"$PHOTO.THUMB.URL$"*/, srcPhotoUrl[_sbURLAddr] + "?" + now.getTime());
					strHtml = ReplaceAll(strHtml, params.strMaThumb/*"$PHOTO.THUMB.URL$"*/, srcPhotoUrl[_sbURLAddr]);

					// replace the photo's description!
					strHtml = ReplaceAll(strHtml, params.strMaDesc/*"$PHOTO.DESC$"*/, TransDivTitle(photodata[_MaDesc]));
					// replace the photo's datetime.
					//var phototime = new Date();
					//phototime.setTime(photodata[_MaTStamp]*1000 + g_nTimeZone*60*1000);
					var phototime = _createDateTime(photodata[_MaTStamp], g_nTimeZone);
					strHtml = ReplaceAll(strHtml, params.strMaDateTime/*"$PHOTO.DATE$"*/, getDateTimeStr(phototime));
					// replace photo's descript!
					var strEscapeHtml = TransHtml2(photodata[_MaDesc]);
					strHtml = ReplaceAll(strHtml, params.strMaDescHtml/*"$PHOTO.DESC.HTML$"*/, strEscapeHtml);
					strTotalHtml += strHtml;
					if ((i+1)%2 == 0) {
						//strTotalHtml += '<br/>';
					}
									
					
				}
		    }
			this.objMiniAlbum.innerHTML = strTotalHtml;
		}
		g_bBusy = true;
		for (var i=0; i<this.objAllUsrAlbum.length; i++) { // for each Track
			var curMyAlbum = this.objAllUsrAlbum[i].getAllItems();
			for (var j=0; j<curMyAlbum.length; j++) { // for each item in it
				var photodata = curMyAlbum[j];
				var bUseThumb = photodata[_MaThm][_sbURLAddr] != ''; // && photodata[_MaThm][_sbURLW] >= 0 && photodata[_MaThm][_sbURLH] >= 0;
				var srcPhotoUrl =  bUseThumb ? photodata[_MaThm] : photodata[_MaOri];
				//[Mark Yang] [2008.05.23] if photodata is an URL of picture AND thumbnail W/H is invalid, we use the original W/H to calculate the target size.
				if (photodata[_MaOri][_sbType] == 'URL' && srcPhotoUrl[_sbURLW] <= 0 && srcPhotoUrl[_sbURLH] <= 0) {
					srcPhotoUrl = photodata[_MaOri];
				}
				_adjImgPad($(photodata[_MaId]), srcPhotoUrl[_sbURLW], srcPhotoUrl[_sbURLH], _MaxThumbW, _MaxThumbH, false);
			}
		}
		g_bBusy = false;
		
		// 2008/08/26 Ryan
		var ps = __get(PPId);
		if(ps)	{
			var curpage = __get(PPId).getCurpage();			
			if(curpage)	{
				this.onViewModeSelChg(curpage[0].id);
			}
		}
	}

	
	this.onSelChgTrk = function (strSelTrkId) {
		if (strSelTrkId != this.mf.getCurSelTrk()) {
			var objCurTrk = this.mf.getUsrTrack(strSelTrkId); //this.mf.getCurSelTrk();
			//this.applyContent(g_minialbumParams, objCurTrk);
		}
	}
	
	// Function: ShowEntry(nIdx, bShow)
	// Parameters: nIdx=the index of the Entry which we wanna show/hide.
	//             bShow='true' to show Entry, or 'false' to hide it!
	// Remark: Change the hide or show status of one entry!
	this.ShowEntry = function (strId, bShow) {
		var CurEntry = $(this.strEntryLeadText+strId);
		if (CurEntry != null) {
			CurEntry.style.display = (bShow) ? "block" : "none";
			CurEntry.style.visibility = (bShow) ? "visible" : "hidden";
		}
	}
	
	//
	this.RemoveEntry = function (nIdx) {
		// NOTE: FF is not workable!
        var CurEntry = $(this.strEntryLeadText+nIdx);
        if (CurEntry != null) {
            CurEntry.parentElement.removeChild(CurEntry);
        }
        // var strTargetId = this.strEntryLeadText+nIdx;
        // var ParObj = $("ID_minialbum");
        // var childAry = ParObj.getElementsByTagName("div");
        // for (var i=0; i<childAry.length; i++) {
        // 	if (childAry[i].id == strTargetId) {
        // 		ParObj.removeChild(childAry[i]);
        // 		break;
        // 	}
        // }
	}
	
	this.calculateDescHeight = function (strDesc) {
		var strTmp = strDesc;
		strTmp = strTmp.replace(/\r/g, '\n');
		strTmp = strTmp.replace(/\n\n/g, '\n');
		var aryStr = strTmp.split('\n');
		var nRet = 0;
		for (var i=0; i<aryStr.length; i++) {
			nRet += Math.ceil(aryStr[i].length/30);	
		}
		return nRet;
	}
	//
	this.estimateEmbedSize = function (strEmbed) {
		var aryStr = strEmbed.split(' ');
		var retParam = {
			'width':-1,
			'height':-1 
		}
		for (var i=0; i<aryStr.length; i++) {
			if (aryStr[i].toLowerCase().indexOf('width') != -1) {
				var strOutput = aryStr[i];
				strOutput = strOutput.replace(/[^0-9]/g, "");
				retParam.width = parseInt(strOutput);		
			}
			//else if (aryStr[i].toLowerCase().indexOf('height') != -1) {
			//	var strOutput = aryStr[i];
			//	strOutput = strOutput.replace(/[^0-9]/g, "");
			//	retParam.height = strOutput;					
			//}
		}
		return retParam;
	}
	//
	this.prepareInfoWnd = function (params) {
		if (this.objAllUsrAlbum != null && this.objAllUsrAlbum.length > 0) {
		    var photodata = params.photodata; //this.objAllUsrAlbum[params.nIdx];
		    if (photodata != null) {
				var infoWnd = (photodata[_MaLat] != 0 && photodata[_MaLng] != 0) ?
						$(params.strEmptyTemplateId + _PicTypeVal[photodata[_MaOri][_sbType]]) : //$('ID_Infownd_Template');
						$('ID_Infownd_NoLoc');
				var strHtml = infoWnd.innerHTML;
				
				// replace the photo Id.
				//strHtml = ReplaceAll(strHtml, "$PHOTO.ID$", this.strEntryLeadText+i);
				var targetText = "";
				
				// calculate the image size!
				var bUseMid = (photodata[_MaMid][_sbURLW] > 0 && photodata[_MaMid][_sbURLH] > 0);
				var nTmpWidth = (bUseMid) ? photodata[_MaMid][_sbURLW] : photodata[_MaOri][_sbURLW];
				var nTmpHeight = (bUseMid) ? photodata[_MaMid][_sbURLH] : photodata[_MaOri][_sbURLH];
				if (nTmpWidth > nTmpHeight) {
					var retParam = getResizeInfo(null, nTmpWidth, nTmpHeight, 320, 240, true);
					strHtml = ReplaceAll(strHtml, params.strMaWidth/*"111px"*/, retParam.newW+'px');
				}
				else {
					var retParam = getResizeInfo(null, nTmpWidth, nTmpHeight, 240, 320, true);
					strHtml = ReplaceAll(strHtml, params.strMaWidth/*"111px"*/, retParam.newW+'px');
				}

				var nRowCount = this.calculateDescHeight(photodata[_MaDesc]);
				if (nRowCount > 5) {
					strHtml = ReplaceAll(strHtml, params.strDescH/*"222px"*/, '70px');
				}
				else {
					// 2008/07/29 Bug#40346 Ryan
					 // strHtml = ReplaceAll(strHtml, params.strDescH/*"222px"*/, 'auto');
					 var s = "HEIGHT: " + params.strDescH;					 
					 // strHtml = ReplaceAll(strHtml, params.strDescH/*"222px"*/, 'auto');
					  strHtml = ReplaceAll(strHtml, s, 'HEIGHT: auto');
				}
				
				if (_PicTypeVal[photodata[_MaOri][_sbType]] == _MaTypeVal['placemark']) {
					var retEmbedParams = this.estimateEmbedSize(photodata[_MaOri][_sbURLAddr]);
					if (retEmbedParams.width > 0) {
						strHtml = ReplaceAll(strHtml, params.strEmbedW/*"999px"*/, (retEmbedParams.width)+'px');
					}
					else {
						strHtml = ReplaceAll(strHtml, params.strEmbedW/*"999px"*/, '340px');
					}
				}
				var now = new Date();
//* byFred		targetText = (photodata[_MaOri][_sbURLAddr] != null) ? (photodata[_MaOri][_sbURLAddr] + "?" + now.getTime()) : "\"\"";
				targetText = (photodata[_MaOri][_sbURLAddr] != null) ? (photodata[_MaOri][_sbURLAddr]) : "\"\"";
				strHtml = ReplaceAll(strHtml, params.strOriMaURL/*"$ORI.PHOTO.URL$"*/, targetText);
				
				var now = new Date();
//* byFred		targetText = (photodata[_MaMid][_sbURLAddr] != null) ? (photodata[_MaMid][_sbURLAddr] + "?" + now.getTime()) : "\"\"";
				targetText = (photodata[_MaMid][_sbURLAddr] != null) ? (photodata[_MaMid][_sbURLAddr]) : "\"\"";
				strHtml = ReplaceAll(strHtml, params.strMidMaURL/*"$MID.PHOTO.URL$"*/, targetText);
				
				targetText = (photodata[_MaTitle] != null) ? photodata[_MaTitle] : "\"\"";
				strHtml = ReplaceAll(strHtml, params.strMaTitle/*"$PHOTO.TITLE$"*/, targetText);
				
				targetText = (photodata[_MaDesc] != null) ? TransHtml2(photodata[_MaDesc]) : "\"\"";
				strHtml = ReplaceAll(strHtml, params.strMaDesc/*"$PHOTO.DESC$"*/, targetText);
				//var phototime = new Date();				
				//phototime.setTime((photodata[_MaTStamp]+g_nTimeZone*60)*1000);
				var phototime = _createDateTime(photodata[_MaTStamp], g_nTimeZone);
				targetText = getDateTimeStr(phototime); //.toLocaleString();
				if (photodata[_MaTStamp] <= 0) {
					targetText = "";
				}
				strHtml = ReplaceAll(strHtml, params.strMaDateTime/*"$PHOTO.DATE$"*/, targetText);
	            
	            targetText = ConvertLatLng2Str(photodata[_MaLat], photodata[_MaLng]);
	            strHtml = ReplaceAll(strHtml, params.strMaPos/*"$PHOTO.POS$"*/, targetText);
		        return strHtml;
		    }		
		}
	    return null;
	}
	
	this.OnMaStop = function () {
	    var curTrk = this.mf.getCurSelTrk();
	    if (curTrk != null) {
			var curAlbumlst = this.mf.getAlbumByTrkId(curTrk.id);
			var allItems = curAlbumlst.getAllItems();
			if (allItems.length > 0) {
				this.mf.fireUsrEvent(this.id, _evtMf_SelChgAlbumEntry, MAId, allItems[0][_MaId]);
			}
	    }
	}

	//
	this.initialize = function () {
		this.applyContent(g_minialbumParams, this.mf.getCurSelTrk());		
		// bind user event!
		this.mf.bindUsrEvent(this.id, _evtMf_SelChgWaypt, "onWayptSelChg");
		// this.mf.bindUsrEvent(this.id, _evtMf_ThumbPos, "onSlideChgPos");
		this.mf.bindUsrEvent(this.id, _evtMf_SwitchMode, "onViewModeSelChg");
		this.mf.bindUsrEvent(this.id, _evtMf_SelChgTrack, "onSelChgTrk");
		//this.mf.bindUsrEvent(this.id, _evtMf_Stop, "OnMaStop");
		this.mf.bindUsrEvent(this.id, _evtMf_AlbumChanged, "onAlbumChanged");
/*[GUI Modify]********************************************************************************/

	// 2008/08/13 Ryan		
		onmousewheel(
			$(MAId),
			function(delta) {
				_MA_handle(delta);
			}
		);	
	}
	
}


function onmousewheel(element, callback) {

	
	function __onwheel(event) {
		var	delta = 0;
		if(event.wheelDelta) {
			delta = event.wheelDelta / 120;
			if(window.opera)
				delta = -delta;
		}
		else if(event.detail)
			delta = -event.detail / 3;
		if(delta)
			callback.call(element, delta);
		if(event.preventDefault)
			event.preventDefault();
		event.returnValue = false;
		return false;
	};
	
	if(element.addEventListener && !window.opera)
		element.addEventListener("DOMMouseScroll", __onwheel, false);
	else
		element.onmousewheel = (function(base){return function(evt){
			if(!evt) evt = window.event;
			if(base) base.call(element, evt);
			return __onwheel(evt);
		}})(element.onmousewheel);
};



/*[GUI Modify]********************************************************************************/
function CMiniAlbumScroll(_speed,_div,_id){
	_id._interval = setInterval(function(){
	document.getElementById(_div).scrollTop += _speed;
	},10)
}


// ·Æ¹«ºu½üºÊÅ¥
function _MA_handle(delta) {
	if (delta < 0)
		$(MAId).scrollTop += 20;
	else
		$(MAId).scrollTop += -20;
}

function _MA_wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		_MA_handle(delta);
}
function _WheelEvwntListener(_obj){
	if (_obj.addEventListener)
	_obj.addEventListener('DOMMouseScroll', _MA_wheel, false);
	_obj.onmousewheel = _MA_wheel;
}