if ( ! window.GDEFON ) {

window.GDEFON = function() {

    var gdefon = function(){};

    gdefon.prototype.init = function(options)
    {
        var array = {
            'site'      : 'http://www.gdefon.ru/',
            'host'      : 'http://api.gdefon.ru/',
            'count'     : 'tty=19778',
            'comments'  : 'comments/',
            'rating'    : 'rating/'
        };
        var site = options.site || 0;

        this.globals = $.extend({}, array);

        if(site)
        {
            var mainOptions = [
                'id="gdefonwidget1"',
                'src="' + this.globals.site + '?' + this.globals.count + '"',
                'name="test"',
                'style="overflow: hidden;"',
                'width="0px"',
                'height="0px"'
            ];
           
            this._addFrame('gdefon_site',mainOptions);
        }
    };

    gdefon.prototype.Rating = function(objId, options, id) {
        var id_wallpaper = id || 0;
        id_wallpaper = 'id/' + id_wallpaper;
        
        this._initOptions(options);
        var height = this.options.height ? this.options.height : 30;
        var width = this.options.width ? this.options.width : 100;

        var ratingOptions = [
            'id="gdefonwidgetrate"',
            'src="' + this.globals.host + this.globals.rating + id_wallpaper + '"',
            'name="test"',
            'style="overflow: hidden;"',
            'width="' + width + 'px"',
            'height="' + height + 'px"'
        ];

        this._addFrame(objId,ratingOptions);

    };



    gdefon.prototype._addFrame = function(objId, allOptions) {
        var params = this._implodeParams(allOptions);
        if(objId)
        {
            $('#' + objId).empty().append('<iframe ' + params + '  frameborder="0" scrolling="no"></iframe>');
        }

    };

    gdefon.prototype._initOptions = function(options) {
        this.options = $.extend({}, options);
    };

    gdefon.prototype._implodeParams = function(array) {
        return array.join(' ');
    }

    return new gdefon;
}();

}
$(document).ready(function(){
     GDEFON.init({site: true});
});

