var newspage = null;

(function(jQuery) {
    //## SLIDE ##//
    jQuery.fn.slide = function(opt) {


        var params = {
            direction: 0,
            delay: 1,
            displaywidth: 0,
            easing: 'swing',
            evt: 'click',
            startpage: 1,
            stepwidth: 0
        };

        //initial for this
        var opt = jQuery.extend(params, opt);

        if (opt.direction == 0) {

            delay = opt.delay * 1000;
            (opt.displayheight == 0) ? displayheight = jQuery(this).height() + 'px' : displayheight = opt.displayheight;
            (opt.displaywidth == 0) ? displaywidth = jQuery(this).width() + 'px' : displaywidth = opt.displaywidth;
            (opt.stepwidth == 0) ? stepwidth = jQuery(this).width() + 'px' : stepwidth = opt.stepwidth;
            opt.totalPage = Math.ceil(parseFloat(opt.innerwidth) / parseFloat(opt.stepwidth)) - Math.ceil(parseFloat(opt.displaywidth) / parseFloat(opt.stepwidth));
            opt.newspage = opt.startpage - 1;

            return this.each(function() {
                obj = jQuery(this);
                obj.css({
                    'overflow': 'hidden',
                    'position': 'relative',
                    'width': (opt.displaywidth == 0) ? obj.width() + 'px' : opt.displaywidth,
                    'height': (opt.displayheight == 0) ? obj.height() + 'px' : opt.displayheight
                });
                jQuery(opt.innercontainer).css({
                    'width': opt.innerwidth,
                    'position': 'relative',
                    'left': (0 - ((opt.startpage - 1) * parseFloat(opt.stepwidth))) + 'px'
                });
                jQuery(opt.btnleft).attr('href', 'javascript:').bind(opt.evt, function() {
                    opt.newspage = (opt.newspage * 1) - 1;
                    if (opt.newspage < 0) {
                        opt.newspage = 0;
                    } else {
                        jQuery(opt.innercontainer).animate({
                            'left': (0 - (opt.newspage * (parseFloat(opt.stepwidth)))) + 'px'
                        }, delay);
                    }

                });
                jQuery(opt.btnright).attr('href', 'javascript:').bind(opt.evt, function() {
                    opt.newspage = (opt.newspage * 1) + 1;
                    if (opt.newspage > opt.totalPage) {
                        opt.newspage = opt.totalPage;
                    } else {
                        jQuery(opt.innercontainer).animate({
                            'left': (0 - (opt.newspage * (parseFloat(opt.stepwidth)))) + 'px'
                        }, delay);
                    }

                });


            });
        }

        //horizontal
        if (opt.direction == 1) {

            delay = opt.delay * 1000;
            (opt.displayheight == 0) ? displayheight = jQuery(this).height() + 'px' : displayheight = opt.displayheight;
            (opt.displaywidth == 0) ? displaywidth = jQuery(this).width() + 'px' : displaywidth = opt.displaywidth;
            (opt.stepwidth == 0) ? stepwidth = jQuery(this).height() + 'px' : stepwidth = opt.stepwidth;
            opt.totalPage = Math.ceil(parseFloat(opt.innerwidth) / parseFloat(opt.stepwidth)) - Math.ceil(parseFloat(opt.displayheight) / parseFloat(opt.stepwidth));
            opt.newspage = opt.startpage - 1;

            return this.each(function() {
                obj = jQuery(this);
                obj.css({
                    'overflow': 'hidden',
                    'position': 'relative',
                    'width': (opt.displaywidth == 0) ? obj.width() + 'px' : opt.displaywidth,
                    'height': (opt.displayheight == 0) ? obj.height() + 'px' : opt.displayheight
                });
                jQuery(opt.innercontainer).css({
                    'height': (opt.displayheight == 0) ? obj.height() + 'px' : opt.displayheight,
                    'overflow': 'hidden',
                    'position': 'relative',
                    'top': (0 - ((opt.startpage - 1) * parseFloat(opt.stepwidth))) + 'px'
                });
                jQuery(opt.btnleft).attr('href', 'javascript:').bind(opt.evt, function() {
                    opt.newspage = (opt.newspage * 1) - 1;
                    if (opt.newspage < 0) {
                        opt.newspage = 0;
                    } else {
                        jQuery(opt.innercontainer).animate({
                            'top': (0 - (opt.newspage * (parseFloat(opt.stepwidth)))) + 'px'
                        }, delay);
                    }

                });
                jQuery(opt.btnright).attr('href', 'javascript:').bind(opt.evt, function() {
                    opt.newspage = (opt.newspage * 1) + 1;
                    if (opt.newspage > opt.totalPage) {
                        opt.newspage = opt.totalPage;
                    } else {
                        jQuery(opt.innercontainer).animate({
                            'top': (0 - (opt.newspage * (parseFloat(opt.stepwidth)))) + 'px'
                        }, delay);
                    }

                });


            });
        }
    }
})(jQuery);
