﻿///<reference path='https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js' />


(function ($) {
    $.fn.recommend = function (options) {
        var opts = $.extend({}, $.fn.recommend.defaults, options);

        var start = 0;

        var $this = $(this);
        var container = $this.find('.view-container');
        var ul = container.find('ul');

        var items = $this.find('.view-container ul li');

        var len = items.size();

        var prev = $this.find('.prev-button');
        var next = $this.find('.next-button');

        var offset = ul.offset();


        if (opts.direction == 'horizontal') {
            var w = items.outerWidth(); //each width
            var view_width = w * opts.max; //view width
            container.width(view_width);
            ul.width(w * len); //total width

            prev.click(function (e) {
                e.preventDefault();
                if (start > 0) {
                    var l = 0 - (view_width * (start / opts.max -1));
                    ul.animate({ left: l }, opts.speed);
                    start = start - opts.max;
                    setButtons();
                }
                return false;
            });

            next.click(function (e) {
                e.preventDefault();

                if (start + opts.max < len) {
                    var l = 0 - view_width * (start / opts.max + 1);
                    ul.animate({ left: l }, opts.speed);
                    start = start + opts.max;
                    setButtons();
                }
                return false;
            });

        } else {
            var h = items.outerHeight(); //each height
            var view_height = h * opts.max; //view height
            container.height(view_height);
            ul.height(h * len); //total height

            prev.click(function (e) {
                e.preventDefault();

                if (start > 0) {
                    var l = 0 - (view_height * (start / opts.max - 1));
                    ul.animate({ top: l }, opts.speed);
                    start = start - opts.max;
                    setButtons();
                }

                
                return false;
            });

            next.click(function (e) {
                e.preventDefault();
                if (start + opts.max < len) {
                    var l = 0 - view_height * (start / opts.max + 1);
                    ul.animate({ top: l }, opts.speed);
                    start = start + opts.max;
                    setButtons();
                }
                return false;
            });
        }


        var setButtons = function () {
            if (start + opts.max < len) {
                next.removeClass('next-button-hover');
                next.removeAttr('disabled', true);
            } else {
                next.addClass('next-button-hover');
                next.attr('disabled', true);
            }

            if (start > 0) {
                prev.removeClass('prev-button-hover');
                prev.removeAttr('disabled');
            } else {
                prev.addClass('prev-button-hover');
                prev.attr('disabled', true);
            }
        }

        setButtons();


    }

    $.fn.recommend.defaults = {
        max: 5,
        direction: 'horizontal',
        speed: 1000
    };
})(jQuery);

$(function() {
    $(".horizontal").recommend({ max: 5, direction: 'horizontal', speed: 1000 });
    $(".vertical").recommend({ max: 3, direction: 'vertical', speed: 1000 });
});////******************************************************************************/////*----------Like This--------------*//*(function ($) {
    $.fn.likethis = function (options) {
        var opts = $.extend({}, $.fn.likethis.defaults, options);

        var $this = $(this);

        var url = encodeURIComponent(window.location.href);

        var like = opts.html.replace('{url}', url).replace(/\{width}/g, opts.width).replace(/\{height}/g, opts.height);
        $this.append(like);
    }

    $.fn.likethis.defaults = {
        html: '<iframe src="http://www.facebook.com/plugins/like.php?href={url}&amp;layout=standard&amp;show_faces=false&amp;width={width}&amp;action=like&amp;font&amp;colorscheme=light&amp;height={height}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:{width}px; height:{height}px;" allowTransparency="true"></iframe>',
        width: 450,
        height: 80
    }
})(jQuery);
*/
/*----------Print This--------------*/
/*
(function($) {
    $.fn.printthis = function(options) {
        var opts = $.extend({}, $.fn.printthis.defaults, options);
        $(this).addClass('print-button');
        $(this).click(function(e) {
            e.preventDefault();
            if (opts.id > -1) {
                window.open(opts.url + '?id=' + opts.id);
            }
        });
    }

    $.fn.printthis.defaults = {
    url: '/Catalog/ProductView.ascx',
        id: -1
    }
})(jQuery);
*/
/*----------Email This--------------*/
(function($) {
    $.fn.emailthis = function(options) {
        var opts = $.extend({}, $.fn.emailthis.defaults, options);
        $(this).addClass('email-button');
        $(this).click(function(e) {
            e.preventDefault();
            //$.post(opts.url, 'id=' + opts.id);
            window.open(opts.url + '?id=' + opts.id + '&url=' + encodeURIComponent(window.location.href), 'MyWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=470,height=515,left=100,top=100');
        });
    }

    $.fn.emailthis.defaults = {
    url: '/Catalog/ProductViewSendEmail.aspx',
        id: -1
    }
})(jQuery);
////***********************************************************************************////
$(function() {
    /*$('#likethis').likethis();*/
    /*$('#printthis').printthis({ id: 1 });*/
    $('#emailthis').emailthis({ id: 1 });
});
////***********************************************************************************////
