﻿/*
	slipnslider News Scroller plugin for jQuery
	Copyright (c) 2010-2011 Mark Bleshenski (markroy.com)
	Licensed under the MIT license 
	Version: 1.0.0 (11/19/2010 00:00:00)
*/
(function ($) {
    $.fn.slipnslider = function (options) {
        var o = {
            width: 300,
            height: 500,
            itemheight: 'auto',
            padding: 0,
            speed: 500,
            delay: 5000,
            easing: 'none',
            pause_button_id: null,
            resume_button_id: null,
            pause_on_mouseover: true,
        };
        var $Wrapper = $(this);
        $Wrapper.pause = false;
        $Wrapper.buttonpause = false;

        if (options) {
            $.extend(o, options);
        }

        if (o.pause_button_id != null) {
            $("#" + o.pause_button_id).click(function () {
                $("#" + o.resume_button_id).css({ 'display': 'block' });
                $("#" + o.pause_button_id).css({ 'display': 'none' });
                $Wrapper.buttonpause = true;
            });
        }

        if (o.resume_button_id != null) {
            $("#" + o.resume_button_id).click(function () {
                $("#" + o.pause_button_id).css({ 'display': 'block' });
                $("#" + o.resume_button_id).css({ 'display': 'none' });
                $Wrapper.buttonpause = false;
            });
            $("#" + o.resume_button_id).css({ 'display': 'none' });
        }

        if (o.pause_on_mouseover) {
            $Wrapper.mouseenter(function () {
                $Wrapper.pause = true;
            });
            $Wrapper.mouseleave(function () {
                    $Wrapper.pause = false;
            });
        }

        return this.each(function () {
            var $this = $(this);
            $this.pause = false;

            $this.wrap("<div id='slipnsliderWrapper' class='slipnsliderWrapper'></div>");

            $this.parent().css({
                "position": "relative"
    			, "width": o.width - (o.padding * 2)
	    		, "height": o.height
		    	, "padding": o.padding
			    , "overflow-x": "hidden"
    			, "overflow-y": "hidden"
	        });

            $this.children().addClass("itemSlidr");
            $this.children().css({
                "width": o.width - (o.padding * 2)
    	        , "overflow": "hidden"
                , "height": o.itemheight
            });


            function slipItem(dLay) {
                var w = $Wrapper.pause;
                setTimeout(function () {
                    if ($Wrapper.pause == false && $Wrapper.buttonpause == false) {
                        $this.find(".itemSlidr:first").slideUp(
                        { duration: o.speed,
                            easing: o.easing,
                            complete: function () {
                                $(this).appendTo($this).slideDown();
                            }
                        });
                    }
                    slipItem(dLay);
                }, dLay);
            };
            slipItem(o.delay);
        });
    };
})(jQuery);
