/**
* SRAX Fx v0.1 beta (build 2)
* Visual Effects
* http://www.fullajax.ru
* Copyright(c) 2008-2009, Ruslan Sinitskiy.
*/


if (!window.SRAX) {
    SRAX = {
        get : function(obj){
            if (typeof obj == 'string') obj = document.getElementById(obj);
            return obj;
        },
        remove : function(arr){
            arr = arr instanceof Array ? arr : [arr];
            for (var i = 0, l = arr.length; i < l; i++){
                var el = SRAX.get(arr[i]);
                if (el) el.parentNode.removeChild(el);
            }
        },
        extend : function(dest, src, skipexist){
            var overwrite = !skipexist; 
            for (var i in src)
                if (overwrite || !dest.hasOwnProperty(i)) dest[i] = src[i];
          return dest;
        }
    }
    function id(id){
        return SRAX.get(id);
    }    
}

if (!SRAX.Fx){
  
  SRAX.Fx = function(el){
    var fx = new function (){
        var $ = this;
        this.get = function(el){
            return SRAX.extend($,{el:el});
        }
        var getStyle = $.getStyle = function (el, rule){
        	var val = "";
        	if(document.defaultView && document.defaultView.getComputedStyle){
        	   val = document.defaultView.getComputedStyle(el, "").getPropertyValue(rule);
        	   if (rule == 'opacity') return rule ? parseFloat(rule) : 1.0;
        	   if (val == 'auto') val = null;
        	}
        	else if(el.currentStyle){
            if (rule == 'opacity') {
              if (val = (getStyle(el, 'filter') || '').match(/alpha\(opacity=(.*)\)/))
                  if (val[1]) return parseFloat(val[1]) / 100;
              return 1.0;
            }
        	  if (rule == 'float') rule = 'styleFloat'; 
        		rule = rule.replace(/\-(\w)/g, function (match, str){
        			return str.toUpperCase();
        		})
        		val = el.currentStyle[rule];
            if (val == 'auto') {
              val = ((rule == 'width' || rule == 'height') && (getStyle(el, 'display') != 'none')) ? 
                 (el['offset' + rule.substring(0,1).toUpperCase() + rule.substring(1)] + 'px') : null
            }
        	}    	
        	return val;
        }
        
        var ua = navigator.userAgent.toLowerCase();
        var isIE7 = ua.indexOf('msie 7')>-1;
	var isIE=ua.indexOf('msie')>-1;
	var isCH=ua.indexOf('chrome')>-1;
	var el_p="";
        
        var getPos = $.getPos = function(obj, limit, scroll) {
            obj = SRAX.get(obj);
            var src = obj;
            if (!obj) return;
            var x = 0, y = 0;
            if (getStyle(obj, 'position') == 'fixed'){
                return {x:parseInt(getStyle(obj, 'left')), y:parseInt(getStyle(obj, 'top'))} 
            }
            if (obj.offsetParent) {
                x = obj.offsetLeft;
                y = obj.offsetTop;
                while (obj = obj.offsetParent) {
                    if (scroll){
                        x -= obj.scrollLeft;
                        y -= obj.scrollTop;
                    }
                    if (limit){
                        var pos = getStyle(obj, 'position');
                        if (pos == 'relative' || pos == 'absolute' || pos == 'fixed') {
                            break;
                        }
                    } 
                    x += obj.offsetLeft;
                    y += obj.offsetTop;

                }
                
                if (obj && isIE7 && getStyle(src, 'float') != 'none'){
                    var ml = getStyle(obj, 'margin-left');
                    x -= parseInt(ml);
                    var mt = getStyle(obj, 'margin-top');
                    y -= parseInt(mt);
                }            
            }
            if(scroll&&(isIE || isCH)){var M=KorScr(y,x).split('/'); y=M[0]; x=M[1];}
            return {x:x, y:y}
        }    
        
        var setPos = $.setPos = function (el, x, y){
            if (typeof x == 'object') {
                y = x.y
                x = x.x;
            }
            if (x != null) el.style.left = x + 'px';
            if (y != null) el.style.top = y + 'px';        
        }
    
        var setSize = $.setSize = function(el, w, h){
            if (typeof w == 'object'){
                h = w.offsetHeight;
                w = w.offsetWidth;
            }
            var s = el.style;
            if (w != null) 
                s.width = w + (typeof w == 'string' ? '' : 'px');
            if (h != null) 
                s.height = h + (typeof h == 'string' ? '' : 'px');
        }
    
        
        var setOpacity = $.setOpacity = function (el, val){
            var s = el.style;
            if (window.ActiveXObject) {
                s.filter = "alpha(opacity=" + val*100 + ")";
            } else {
                s.KHTMLOpacity = val; // Safari and Konqueror
                s.MozOpacity = val; // Old Mozilla and Firefox
                s.opacity = val;   
            }            
        }
        function isNan(val){
            return isNaN(val) || val == '' || val == null;
        }
        var getOpacity = $.getOpacity = function (el){
            var opacity = el.style.opacity;
            if (isNan(opacity)){
                opacity = getStyle(el, 'opacity');
                if (isNan(opacity)) {
                    opacity = getStyle(el, '-moz-opacity');
                    if (isNan(opacity)) {
                      opacity = getStyle(el, '-khtml-opacity')
                      if (isNan(opacity)) opacity = 1;
                    }
                }
            }
            return opacity ? parseFloat(opacity) : 0; 
        }
      
        var timer = $.timer = function(o) {
            setTimeout(function(){
                if (!o) o = {};
                var start = new Date().getTime();
                var duration = (o.duration || o.d || 1) * 1000;
                var timeout = o.timeout ? o.timeout : 0;
                if (!o.fn)
                  o.fn = [function() {}];
                else
                  if (!(o.fn instanceof Array))
                    o.fn = [o.fn];
                var stop = 0;
          
                function update() {
                  var percent = (new Date().getTime() - start) / duration;
                  if (percent > 1) percent = 1;
                  for (var i = 0; i < o.fn.length; i++)
                    o.fn[i]({percent:percent, ops:o});
                  if (percent == 1 || stop) {
                    if (o.cb) o.cb(o, fx);        
                    if (o.callback) o.callback(o, fx);
                  }
                  else
                    setTimeout(update, timeout);
                }
          
                this.stop = function() {
                  stop = 1;
                }
          
                this.isStoped = function() {
                  return stop;
                }
          
                update();
            }, pauseValue *1000);
            pauseValue = 0; 
            return this;
        }  
        
        var opacity = $.opacity = function(el, o){
            if (!o){
              o = el;
              el = this.el;
            }
            if (!o) o = {};
            el = SRAX.get(el);
            var s = el.style;
            if (!o.fn) o.fn = [];
            var start = o.start == null ? getOpacity(el) : o.start;
            var end = o.end == null ? (o.type == 'show' || !start ? 1 : 0) : o.end;        
            var delta = end - start;
            if (window.ActiveXObject) s.zoom = 1;
            o.fn.push(function(ops) {
                if (!ops.percent) return;
                var pos = start + delta * ops.percent;
                el = el.newEl || el;
                setOpacity(el, pos)
            })
            if (o.onlyfn) return o.fn; 
            new timer(o);
            return this;
        }
        
        var blink = $.blink = function(el, o){
            if (!o){
              o = el;
              el = this.el;
            }
            el = SRAX.get(el);
            if (!o) o = {};
            var count = o.count ? o.count : 3;
            if (!o.interval) o.interval = 0.5;
            var n = 0;
            o.type = getOpacity(el) == 0 ? 'show' : 'hide';
            function one(x){ 
                o.callback = function(){
                    setTimeout(function(){
                      new opacity(el, SRAX.extend({type:o.type == 'show' ? 'hide' : 'show', fn:[], callback:function(){
                          if (count == -1 || ++n < count) one(1);
                      }}, o, 1))
                    }, (o.pause || 0) * 1000); 
                }
                o.fn = [];
                setTimeout(function(){new opacity(el, o)}, o.interval * 1000 * x)
            }
            one(0);
            return this;        
        }
        function cloneNode(el){
            var pel = el;
            el = el.cloneNode(true)
            function cloneAttr(src, dest){
                for (var i in src){
                    try{
                      dest[i] = src[i]
                    } catch (ex){}
                }
                return dest; 
            }
            cloneAttr(pel, el)
            cloneAttr(pel.style, el.style)
            return el;
        }
        var move = $.move = function(el, o){
            if (!o){
              o = el;
              el = this.el;
            }
            if (!o) o = {};
            el = SRAX.get(el);
            var s = el.style;
            if (!o.fn) o.fn = [];
            var dT, dL, dB, dR;
            var startPos = getPos(el, 1);
            var pos = getStyle(el, 'position');
            if (pos != 'absolute'){
                var pel = el; 
                el = cloneNode(el)
                pel.newEl = this.el = pel.parentNode.insertBefore(el, pel);
                pel.style.visibility = 'hidden';
                setPos(el, startPos);
                el.style.position = 'absolute';
            }
            if (o.left != null) dL = o.left - startPos.x;
            if (o.top != null) dT = o.top - startPos.y;
	    if(!isIE && el_p){var M=KorScr(dT,dL).split('/'); if(el_p.offsetTop!=0)dT=M[0]; if(el_p.offsetLeft!=0)dL=M[1];}
            if (o.right != null) {
                startPos.r = parseInt(getStyle(el, 'right'));
                dR = o.right - startPos.r;
            }
            if (o.bottom != null) {
                startPos.b = parseInt(getStyle(el, 'bottom'));
                dB = o.bottom - startPos.b; 
            }
            if (dT == null && dL == null && dR == null && dB == null) return $;
            o.fn.push(function(ops) {
                var p = ops.percent;
                if (!p) return;
                var x,y,r,b;
                if (dT != null) y = startPos.y + dT * p;
                if (dL != null) x = startPos.x + dL * p;
                el = el.newEl || el;
                if (dR != null) {
                    r = startPos.r + dR * p;
                    el.style.right = r+'px';
                }
                if (dB != null) {
                    b = startPos.b + dB * p;
                    el.style.bottom = b+'px';
                }
                setPos(el, x, y);
            })
            if (o.onlyfn) return o.fn; 
            new timer(o);
            if (dL == null && dR != null) el.style.left = 'auto';
            if (dT == null && dB != null) el.style.top = 'auto';
            return this;        
        }
        
        var size = $.size = function(el, o){
            if (!o){
              o = el;
              el = this.el;
            }
            if (!o) o = {};
            el = SRAX.get(el);
            if (!o.fn) o.fn = [];
            var dW, dH, w, h;
            if (o.width != null) {
                w = el.clientWidth;
                dW = o.width - w;
            }
            if (o.height != null) {
                h = el.clientHeight;
                dH = o.height - h;
            }
            
            o.fn.push(function(ops) {
                var p = ops.percent;
                if (!p) return;
                var width, height;
                if (w != null){
                    width = w + dW * p;
                }
                if (h != null){
                    height = h + dH * p;
                }
                el = el.newEl || el;
                setSize(el, width, height);
            })
            if (o.onlyfn) return o.fn; 
            new timer(o);
            return this;        
        }
        
        var pauseValue = 0;
        var pause = $.pause = function(val){
            pauseValue = val;
            return this;
        }
        
        $.add = function(effect, ops){
            ops.onlyfn = 1;
            ops.fn = this.globalfn;
            this.globalfn = this[effect](ops);
            for (var i = 2; i < arguments.length; i+=2){ 
                this.add(arguments[i], arguments[i+1])
            }
            return this;
        }
        $.exec = function(ops){    
            if (!this.globalfn) return;
            if (!ops) ops = {};
            ops.fn = this.globalfn;
            new timer(ops);
            return this;
        }
        
        
        /**
         * Функция анимации трансформации одного обьекта в другой
         * для корректной работы требуется в стили добавить следующий класс                
         .trans{
           position:absolute;
           background:#ccc;
           opacity:0.2;
           -moz-opacity:0.2;
           filter:alpha(opacity=20);
           border:1px dashed #777;
           z-index:10000;
           top:-1000px;
           left:-1000px;
         }
      
         **/ 
        
        $.trans = function(trans, el, o, r){
		if (!o) o = {};
		trans = SRAX.get(trans);
		el = SRAX.get(el);
		var pos = getPos(trans, 0, 1);
		var w = trans.offsetWidth;
		var h = trans.offsetHeight;
		trans = document.body.appendChild(trans.cloneNode(true));
		if(!r)trans.style.cssText="";              
		trans.className = "trans";
		var wEl = el.offsetWidth;
		var hEl = el.offsetHeight;
		setSize(trans, o.reverse ? wEl : w, o.reverse ? hEl : h);
		var posEl = getPos(el); 
		el_p=el.offsetParent; 
              	setPos(trans, o.reverse ? posEl : pos , 0, 1);
              	new SRAX.Fx.get(trans)
                    .add('size', {width:o.reverse ? w : wEl, height: o.reverse ? h:  hEl})
                    .add('move', {top: o.reverse ? pos.y : posEl.y, left: o.reverse ? pos.x  : posEl.x })
                    .exec({d:o.duration || o.d || 0.3, callback:function(){
                                            SRAX.remove(trans);
                                            if (o.cb) o.cb(o, fx);
                                            if (o.callback) o.callback(o, fx);
                                       }
                          }
                    );    
        }
    }
    return el == null ? fx : fx.get(el);    
  }
  
  var fx = SRAX.Fx()
  for (var i in fx) SRAX.Fx[i] = fx[i]
}

function KorScr(y,x){
	y+=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	x+=Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
return y+'/'+x;
}