/**
 * @author weijie
 * @version: 1.0
 */

/*******************************************************message flash***********************************************************/
if (typeof(rdcjs) == "undefined")
	_rdc = rdcjs = {};
	
if (typeof(_rdc.FlashMessage) == "undefined")
	_rdc.FlashMessage = {};
else
	alert("FlashMessage is already set!");

//var FlashMessage = {};
_rdc.FlashMessage.isMoving = false;
_rdc.FlashMessage.currentTimer = null;
_rdc.FlashMessage.opacityTimers = new Array();
_rdc.FlashMessage.opacity = function(id, opacStart, opacEnd, millisec) {
	
	if( !document.getElementById( id ) )//for ajax.net compatible.
		return;
	
	_rdc.FlashMessage.isMoving = true;
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			(function(){
			var t = setTimeout("_rdc.FlashMessage.changeOpac(" + i + ",'" + id + "')",(timer * speed));
			_rdc.FlashMessage.opacityTimers.push( t );
			timer++;
			})();
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
		{
			(function(){
			var t = setTimeout("_rdc.FlashMessage.changeOpac(" + i + ",'" + id + "')",(timer * speed));
			_rdc.FlashMessage.opacityTimers.push( t );
			timer++;
			})();
		}
	}
};

//change the opacity for different browsers
_rdc.FlashMessage.changeOpac = function(opacity, id) {
	
	if( !document.getElementById( id ) )//for ajax.net compatible.
		return;
	//$('debug').innerHTML +=( 'ch ' );
			
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";

	if( opacity == 5 ){
		var h = parseInt(document.getElementById(id).scrollHeight);
		_rdc.FlashMessage.resizeHeight( id, h , 0 ,500 );
	}
};

_rdc.FlashMessage.doFlash = function( holdTime ){
	if( !document.getElementById("divFlash") ){
		alert("Sorry, but i can't find flash container, did you have a div with id 'divFlash' in you page?");
		return;
	}
	//resizeHeight('divFlash',1, 20,2000 );
	var f = function(){ _rdc.FlashMessage.opacity('divFlash', 100,0, 2000);}
	
	
	if( _rdc.FlashMessage.currentTimer != null )
		window.clearTimeout( _rdc.FlashMessage.currentTimer );
			
	if( _rdc.FlashMessage.isMoving )
	{	
		for( var i = 0; i < _rdc.FlashMessage.opacityTimers.length; i++ ){
			window.clearTimeout( _rdc.FlashMessage.opacityTimers[i] );
		}
	}
	_rdc.FlashMessage.currentTimer = window.setTimeout( f  , holdTime );

	
};

_rdc.FlashMessage.doStaticFlash = function(){
	//nothing to do
};

_rdc.FlashMessage.resizeHeight = function(id, hStart, hEnd, millisec) {

	if( !document.getElementById( id ) )//for ajax.net compatible.
		return;
	
	//alert(hStart + " " + hEnd);
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(hStart > hEnd) {
		for(i = hStart; i >= hEnd; i--) {
			(function(){
			var t = setTimeout("_rdc.FlashMessage.changeHeight(" + i + ",'" + id + "')",(timer * speed));
			_rdc.FlashMessage.opacityTimers.push( t );
			timer++;
			})();
		}
	} else if(hStart < hEnd) {
		for(i = hStart; i <= hEnd; i++)
		{
			(function(){
			var t = setTimeout("_rdc.FlashMessage.changeHeight(" + i + ",'" + id + "')",(timer * speed));
			_rdc.FlashMessage.opacityTimers.push( t );
			timer++;
			})();
		}
	}
};

_rdc.FlashMessage.changeHeight = function( height, id) {
	if( !document.getElementById( id ) )//for ajax.net compatible.
		return;

	var h = parseInt( height );
	document.getElementById(id).style.height = height + "px";
	if( h == 0 ){
		document.getElementById(id).style.display = "none";
		_rdc.FlashMessage.isMoving = false;
	}
};