 /**
# mod_jcslide - JV Slide
# @version 1.6.x
# ------------------------------------------------------------------------
# author    Open Source Code Solutions Co
# copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
# Websites: http://www.joomlavi.com
# Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/
if(!JVLib){
var J, j, JVLib;
(function () {
    Element.implement({
        append: function (e) {
            this.appendChild(e);
            return this;
        },
        prepend: function (e) {
            var child = this.child()[0];
            child ? child.before(e) : this.append(e);
            return this;
        },
        after: function (e) {
            var n = this.next();
            n ? n.before(e) : this.parent().append(e);
            return this;
        },
        before: function (e) {
            this.parent().insertBefore(e, this);
            return this;
        },
        css:function(css,val){
            if($type(css) == 'object') for(var x in css) this.css(x,css[x]);
            else if(val){
                this.setStyle(css,val);
                return this;
            }else return this.getStyle(css);
        },
        html: function (h) {
            return h ? this.setHTML(h) : this.innerHTML;
        },
        attr: function (a, b) {
            if (a) {
                if ($type(a) == 'object') {
                    for (var x in a) this.attr(x, a[x]);
                } else if (b) {
                    this.setProperty(a, b);
                    return this;
                } else return this.getProperty(a);
            } else return this.getProperties();
        },
        child: function (s) {            
            return this.getChildren(s);
        },
        parent: function (s) {
            return this.parentNode;
        },
        next: function () {
            return this.getNext();
        },
        prev: function () {
            return this.getPrevious();
        },
        last: function () {
            return this.getLast();
        },
        first: function () {
            return this.getFirst();
        },
        find: function (e) {
            return this.getElements(e);
        },
        morph: function (o) {
            if (o) this.fx = new Fx.styles(o);
            else return this.fx;
            return this.fx;
        },
        offset: function (o) {
            return this.getCoordinates(o);
        }
    });
    String.implement({
        toElements: function () {
            var obj = new Element('div');
            obj.html(this);
            return obj.child();
        }
    });
    Object.extend({});    
    J = j = JVLib = {
        drag: function(el,o){
            if(!o) o={};
            if(!o.delay) o.delay = 0;
            if(!o.start) o.start = function(){return true}
            if(!o.move) o.move = function(){return true}
            if(!o.end) o.end = function(){return true}
            var value = {
                start: false,
                move: false,
                startMove: null
            }
            var act = {
                start:function(e){
                    el.eventCall = o.start;
                    value.startMove = {
                        x: e.clientX,
                        y: e.clientY
                    }
                    if(el.eventCall(e)){
                        value.start = true;
                        setTimeout(function(){
                            if(value.start){
                                document.addEvent('mousemove',act.move);
                            }
                        },o.delay);
                        document.addEvent('mouseup',act.end);
                    }
                },
                move: function(e){
                    value.move = true;
                    el.eventCall = o.move;
                    e.move = {
                        x: e.clientX - value.startMove.x,
                        y: e.clientY - value.startMove.y
                    }
                    el.eventCall(e);
                },
                end: function(e){
                    value.start = false;
                    if(value.move){
                        el.eventCall = o.end;
                        e.move = {
                            x: e.clientX - value.startMove.x,
                            y: e.clientY - value.startMove.y
                        }
                        el.eventCall(e);
                        value.move= false;
                    }
                    document.removeEvent('mousemove', act.move);
                    document.removeEvent('mouseup', act.end);                    
                },
                destroy: function(){
                    el.removeEvent('mousedown',act.start);
                    delete this;
                }
            }
            el.addEvent('mousedown',act.start);
            this.destroy = act.destroy;
            this.end = act.end;
        },
        move: function(el, handle,o){
            if(!handle) handle = el;
            if(!o) o = {};
            if(!o.dir) o.dir = 'xy';
            if(!o.delay) o.delay = 100;
            if(!o.start) o.start = function(){return true}
            if(!o.move) o.move = function(){return true}
            if(!o.end) o.end = function(){return true}
            var pos = {};
            var dir = {
                x: o.dir.indexOf('x')!=-1?true:false,
                y: o.dir.indexOf('y')!=-1?true:false
            };
            var drag = new J.drag(handle,{
                delay: 100,
                start:function(e){                    
                    pos = {
                        top: Number.toInt(el.getStyle('top')),
                        left: Number.toInt(el.getStyle('left'))
                    }
                    el.eventCall = o.start
                    return el.eventCall(e);
                },
                move:function(e){
                    move(e);
                    el.eventCall = o.move;
                    el.eventCall(e);
                },
                end:function(e){
                    move(e);
                    el.eventCall = o.end;
                    return el.eventCall(e);
                }
            });
            var move = function(e){
                if(dir.y){ el.setStyle('top',pos.top + e.move.y);};
                if(dir.x){ el.setStyle('left',pos.left + e.move.x);};
            }
            this.destroy = function(){drag.destroy(); delete this;}
            this.end = function(){drag.end();}
        },
        resize: function(){
            
        },
        Morph:  Fx.Morph
    }
})();
}
