
	function PavObj( objid ) {

		this.serviceUrl = 'http://service.net.hr/pav/pav.ashx';
		this.rootUrl = 'http://danas.net.hr';
		this.rootUrlRegExp = /http\:\/\/danas\.net\.hr/g;
		this.articleDir = '/page/';
		this.dailyDir   = '/servlet/redir?';
		this.archiveDir = '/servlet/archredir?';

		this.referer = '';
		this.ref = 'o';
		this.pos = '0';
		this.curl = '';

        this.objid = new String( objid );

		this.i = new Image();

		this.getPar = function( qs, s ) {
			var ret = '';
			if( qs.indexOf( '?' ) >= 0 ) { qs = qs.split( '?' )[ 1 ]; }
			if( qs.indexOf( '&' ) >=0 ) {
				qs = qs.split( '&' );
				for( var i=0; i<qs.length; i++ ) {
					var tmp = qs[ i ].split( '=' );
					if( tmp[ 0 ] == s ) { ret = tmp[ 1 ]; }
				}
			}
			else {
			    qs = qs.split( '=' );
			    if( qs[ 0 ] == s ) { ret = qs[ 1 ]; }
			}
			return ret;
		};

		this.parseDaily = function( qs ) {
		    var
		        ret = null,
    		    selector = this.getPar( qs, 'selector' ),
    		    date = this.getPar( qs, 'date' );
            if( (selector.length == 15) && (date.length == 8) ) { ret = { 'selector' : selector, 'date' : date }; }
            return ret;
		};

		this.go = function() { /* dummy function for backward compatibility */ };


        this.debug = function() {
            alert(
                'referer = ' + document.referrer + '\n' +
                'aid = ' + this.objid + '\n' +
                'ref = ' + this.ref + '\n' +
                'pos = ' + this.pos + '\n' +
                'curl = ' + this.curl
            );
        };



		//


		if( this.objid.length != 15 ) {
		    var arr = this.parseDaily( this.objid );
		    if( arr != null ) { this.objid = arr[ 'selector' ] + arr[ 'date' ]; }
        }

    	if( document.referrer != '' ) {

    	    this.referer = document.referrer;

    	    if( this.referer.indexOf( this.rootUrl ) == 0 ) {
    	        this.curl = this.referer.replace( this.rootUrlRegExp, '' );
    	        if( this.curl.indexOf( this.articleDir ) >= 0 ) { this.curl = this.curl.substring( 0, this.curl.indexOf( this.articleDir )+1 ); }
    	        else if( this.curl.indexOf( this.dailyDir ) >= 0 ) { this.curl = '/daily/' + this.getPar( this.curl, 'selector' ); }
    	        else if( this.curl.indexOf( this.archiveDir ) >= 0 ) { this.curl = '/arhiva/'; }
            }

    	    if( (this.referer == this.rootUrl) || (this.referer == this.rootUrl+'/') ) {
    	    	this.ref = 'n';
    	    	this.pos = this.getPar( document.location.href, 'pos' );
    	   	}
    	    else if( this.referer.indexOf( this.rootUrl ) == 0 ) { this.ref = 'c'; }

    	}
    	this.i.src = this.serviceUrl + '?pid=2&aid=' + this.objid + '&ref=' + this.ref + '&pos=' + this.pos + '&curl=' + this.curl;

	};

