﻿/// <reference path="../Javascript/jQueryIntellisense.js"/>
/*
* jQuery bannerAd Plugin
* Caudill Web
* @requires jQuery v.1.4+
*/

(function ($) {
    $.fn.bannerAd = function (options) {

        var defaults = {}; // set defaults in vb
        var config = $.extend(defaults, options);
        this.each(function () {

            var self = this, $self = $(this);
            // log the client impression for this banner ad
            var key = config.key;
            if (!!key) {
                $.ajax({
                    url: window.location.href,
                    type: "POST",
                    data: {
                        containerId: self.id,
                        action: "bannerimpression",
                        key: key
                    },
                    async: true,
                    success: function (msg) {
                        // 1 = success
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        // TODO - js error handling
                    }
                });

                $self.die("click").bind("click", submitClick);

                function submitClick(e) {
                    $.ajax({
                        url: window.location.href,
                        type: "POST",
                        data: {
                            containerId: self.id,
                            action: "bannerclick",
                            key: key
                        },
                        async: true,
                        success: function (msg) {
                            // 1 = success
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            // TODO - js error handling
                        }
                    });
                } // submitClick
            }
        }); // each

        return this; // don't break the chain

    }; // $.fn.bannerAd

})(jQuery);



