/**
 * @author jordi.touza
 */
if (typeof(_funky.effects) == "undefined") _funky.effects = {};
else alert("var name 'effects' is already set!");

_funky.effects = function (){ 

	/**
	 * Para poder usar correctamente setTimeout sin dejar fuera del objeto la función changeOpac
	 * seria necesario llamar a esta con el mismo nombre de instancia con el que se ha declarado en la execución.
	 * ;) Pero pa no repetirse, la mejor solución es duplicar la función y una que se quede fuera, 
	 * la otra la dejamos dentro para que pueda ser llama por el objeto.
	 * 
	 * En firefox se pueden hacer llamadas a funciones dentro del mismo objeto en la función setTimeout, 
	 * pero no se le pueden passar valores a esta función. No obstante si pasamos los parametros de la función del objeto
	 * seguidos de los propios de setTimeout, funciona! :'
	 */
};

_funky.effects.prototype.opacity = function(obj, opacStart, opacEnd, millisec) { 
	
	if((typeof(obj) == "string"))  obj = document.getElementById(obj);
	if(!(typeof(obj) == "object")) return false;

    var speed 	= Math.round(millisec / 100); 
    var timer 	= 0; 
	this.obj 	= obj;
		
    if(opacStart > opacEnd) { 
     
	    for(i = opacStart; i >= opacEnd; i--) { 
            			
			//setTimeout(this.changeOpac,(timer * speed), obj.id, i); // Esto funciona bien en Firefox, pero no en IE
			
			setTimeout("changeOpac('" + obj.id +"'," + i + " );", timer * speed);
	
            timer++; 
        } 
		
    } else if (opacStart < opacEnd){ 
	
        for(i = opacStart; i <= opacEnd; i++){ 
	
   	        setTimeout("changeOpac('" + obj.id +"'," + i + " );", timer * speed);
            
			timer++; 
        } 
    } 
};

_funky.effects.prototype.changeOpac = function(obj, opacity){ 

	if((typeof(obj) == "string"))  obj = document.getElementById(obj);
	if(!(typeof(obj) == "object")) return false;
	
	obj.style.opacity 		= (opacity / 100); 
    obj.style.MozOpacity 	= (opacity / 100); 
    obj.style.KhtmlOpacity 	= (opacity / 100); 
    obj.style.filter 		= "alpha(opacity=" + opacity + ")"; 
};

function changeOpac(obj, opacity){ 

	if((typeof(obj) == "string"))  obj = document.getElementById(obj);
	if(!(typeof(obj) == "object")) return false;
	
	obj.style.opacity 		= (opacity / 100); 
    obj.style.MozOpacity 	= (opacity / 100); 
    obj.style.KhtmlOpacity 	= (opacity / 100); 
    obj.style.filter 		= "alpha(opacity=" + opacity + ")"; 
};
