/**
 * @author Alexander Farkas
 * v. 1.02
 * bugfix IE
 * Anderson de Oliveira
 * anderson_prog@hotmail.com
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
				/* ie bugfix */
				if (navigator.appName.indexOf('Microsoft') != -1){
					if(typeof start == 'undefined'){
						start = fx.elem.currentStyle.backgroundPositionX+" ";
						start += fx.elem.currentStyle.backgroundPositionY;
					}
				}
				
                start = toArray(start);
					fx.start = [start[0],start[2]];
					var end = toArray(fx.end);
					fx.end = [end[0],end[2]];
					fx.unit = [end[1],end[3]];
				
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
			
			if (navigator.appName.indexOf('Microsoft') != -1){ 			
				/*
					I used in two tags, in <li> and <a>:
					li :: left  background
					a  :: right background
					<ul>
						<li><a href="">Home</a></li>
						<li><a href="">A MediClin</a></li>
						<li><a href="">Serviços</a></li>
						<li><a href="">Equipe Médica</a></li>
						<li><a href="">Agende sua Consulta</a></li>
					</ul>
					Some times the IE print this error because ?, good question
					Detalhes dos erros da página da Web
					Agente de Usuário: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)
					Carimbo de data/hora: Tue, 18 Jan 2011 13:40:30 UTC
					Mensagem: Argumento inválido.
					Linha: 44
					Caractere: 6
					Código: 0
					URI: http://localhost/Projetos/mediclin/site/js/jquery.bgpos.modif.js
				*/
				fx.elem.style.backgroundPositionX = nowPosX[0];//44 line
				fx.elem.style.backgroundPositionY = nowPosX[1];
				/* if(typeof nowPosX[0] == 'undefined'){
					document.write(typeof nowPosX[0]);
				} */
			}else{
				fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
			}
						
           function toArray(strg){
				   strg = strg.replace(/left|top/g,'0px');
				   strg = strg.replace(/right|bottom/g,'100%');
				   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
				   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
			   
           }
        }
	});
})(jQuery);
