var _tlad_box_classname = 'adverts';
var _tlad_language = 'EN';
var _tlad_country = 'GB';

Ticketlogic.register('Adverts', {
    Version: '0.1.0.0',
    Server: 'ads.clubtickets.com',
    Application: 'v0.1',

    types: new Array(),

    adverts: new Array(),

    initialise: function() {
        this.Application = 'v' + this.Version.split('.')[0] + '.' + this.Version.split('.')[1];
        this.types['banner'] = { width: 468, height: 60 };
        this.types['leaderboard'] = { width: 600, height: 90 };
        this.types['skyscraper'] = { width: 90, height: 600 };
        this.types['superskyscraper'] = { width: 120, height: 600 };
        this.types['mpu'] = { width: 300, height: 240 };
        this.add( 'advert-banner', 'banner' );
        this.add( 'advert-skyscraper', 'superskyscraper' );
    },

    add: function() {
        var _id = arguments[0], _type = arguments[1];
        this.adverts.push({ id: _id, type: _type });
    },

    display: function() {
        var _hrf = document.location.href, _url = '';
        _url += 'http' + ((_hrf.match(/^https/)) ? 's' : '') + '://' + this.Server + '/' + this.Application + '/ad?wp=' + _tlad_publisher;
        _url += '&wh=' + encodeURI(_tlad_hostname) + '&ws=' + _tlad_section + '&wl=' + _tlad_language + '&wc=' + _tlad_country;
        _url += '&nl=' + navigator.language + '&nt=' + encodeURI(document.title) + '&nj=' + navigator.javaEnabled();
        _url += '&nsw=' + screen.width + '&nsh=' + screen.height + '&nsc=' + screen.colorDepth; 
        for (var i=0; i<navigator.plugins.length; i++) {
            _url += '&npi=' + encodeURI(navigator.plugins[i].name);
        }

        for (var i=0; i<this.adverts.length; i++) {
            var ad = this.adverts[i];
            var box = document.getElementById(ad.id);
            if (box) box.innerHTML = this.displayUnit(_url, ad.type);
        }

        window.status = _url;
    },

    displayUnit: function() {
        var _url = arguments[0], _type = arguments[1];
        return '<iframe class="_tlad_iframe_' + _tlad_box_classname + '" src="' + _url + '&tp=' + _type + '" border="0" frameborder="0" width="' + this.types[_type].width + '" height="' + this.types[_type].height + '" scrolling="no"></iframe>';
    },

    get: function() {
        var _url = arguments[o];
        if (typeof _url == 'string') {
            var _wp = window, _i = 0;
            while (_wp.parent && (_i < 10)) {
                _wp = _wp.parent; _i++;
            }
            _wp.location.href = _url;
        }
    }

});

