function FlashPlayer( config, newBid, newQueryParams, newAffiliateId, newVideoUrl, newPreviewBid )
{
    this.width = "100%";
    this.height = "100%";
    this.target = null;
    this.rootFile = "root.swf";
    this.autoPlay = null;

    this.queryParams = escape( newQueryParams );
    this.bid = newBid;
    this.affiliateId = newAffiliateId;
    this.videoUrl = newVideoUrl;
    this.previewBid = newPreviewBid;

    this.domainUrl = null;
    this.rootUrl = null;

    /**
     * covers the params:
     * => width
     * => height
     * => target
     * => rootFile
     */
    if ( this.isValueSet( config ) ) {
        var args = config.split( ',' );
        for ( var i = 0; i < args.length; i++ ) {
            var param = args[ i ].split( '=' );
            eval( "this." + param[ 0 ] + " = '" + param[ 1 ] + "'" );
        }
    }

    this.setWidth = function( newWidth ) {
        this.width = newWidth;
    }

    this.setHeight = function( newHeight ) {
        this.height = newHeight;
    }

    this.setTarget = function( newTarget ) {
        this.target = newTarget;
    }

    this.getFlashPlayerEmbed = function( isEmbeddedPlayer ) {
        var output = '<embed src="' + this.getRootUrl( isEmbeddedPlayer ) + '" '
            + 'quality="best" '
            + 'bgcolor="#FFFFFF" '
            + 'menu="true" '
            + 'width="' + this.width + '" '
            + 'height="' + this.height + '" '
            + 'name="root" '
            + 'id="root" '
            + 'align="middle" '
            + 'scaleMode="noScale" '
            + 'allowScriptAccess="always" '
            + 'allowFullScreen="true" '
            + 'type="application/x-shockwave-flash" '
            + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
            + '</embed>';

        return output;
    }

    this.writeBlogFlashPlayer = function() {
        var output = this.getFlashPlayerEmbed( true );
	    var div_block = document.getElementById( this.target );
        
	    div_block.value = output;
    }

    this.writeFlashPlayer = function() {
        var output = this.getFlashPlayerEmbed( false );
	    var div_block = document.getElementById( this.target );

	    div_block.innerHTML = output;
    }

    this.getRootUrl = function( isEmbeddedPlayer )
    {
        if ( !this.isValueSet( this.rootUrl ) )
        {
            this.rootUrl = this.getDomain();

            if ( this.isValueSet( this.affiliateId ) )
            {
                this.rootUrl += '/a/' + this.affiliateId + '/a';
            }

            this.rootUrl += '/f/' + this.rootFile + '?';
        
            if ( this.isValueSet( this.affiliateId ) )
            {
                this.rootUrl += 'aid=' + this.affiliateId + '&';
            }

            if ( this.isValueSet( this.queryParams ) )
            {
                this.rootUrl += 'query_params=' + this.queryParams;
            }
            else if ( this.isValueSet( this.bid ) )
            {
                this.rootUrl += 'bid=' + this.bid;
            }
            else if ( this.isValueSet( this.videoUrl ) )
            {
                this.rootUrl += 'video_url=' + this.videoUrl;
            }

            if ( this.isValueSet( this.previewBid ) )
            {
                this.rootUrl += '&preview_bid=' + this.previewBid;
            }

            if ( this.isValueSet( this.autoPlay ) )
            {
                this.rootUrl += '&autoPlay=' + this.autoPlay;
            }

            this.rootUrl += '&isEmbeddedPlayer=' + isEmbeddedPlayer;
        }
        return this.rootUrl;
    }

    this.getDomain = function() {
        if ( this.domainUrl == null ) {
            this.domainUrl = String( document.location );
            while ( this.domainUrl.lastIndexOf( '/' ) > 8 ) {
                this.domainUrl = this.domainUrl.substring( 0, this.domainUrl.lastIndexOf( '/' ) );
            }
        }
        return this.domainUrl;
    }

}

FlashPlayer.prototype.isValueSet = function( value ) {
    if ( value == null
      || value == 'null'
      || typeof( value ) == 'undefined'
      || value == '' )
    {
        return false;
    }
    return true;
}

$(document).ready(function() {
        
        $('a.porn').click(function() {
                var dest = $(this).attr("href");

                // 1. Make screen
                $('<div/>')
                        .css({
                                position: 'fixed',
                                top: 0,
                                left: 0,
                                right: 0,
                                bottom: 0,
                                height: '100%',
                                width: '100%',
                                cursor: 'pointer',
                                background: '#000000',
                                zIndex: '4999'
                        })
                        .fadeTo(10,.5)
                        .attr('title','Click to close')
                        .attr('id','screen')
                        .appendTo($('body'))
                        .click(function() {
                                $(this).remove();
                                $('#modalPop').fadeOut('fast', function() {
                                        $(this).remove();
                                });
                        });
                
                // 2. Apply warning
                $('<div/>')
                        .css({
                                position: 'fixed',
                                top: '200px',
                                left: 0,
                                right: 0,
                                width: '448px',
                                height: '230px',
                                margin: '0 auto',
                                textAlign: 'left',
                                zIndex: '5000',
                                background: 'url(/art/warning-bg.png) no-repeat top center'
                        })
                        .attr('id','modalPop')
                        .html('<p style="margin: 75px 20px 6px 32px; font-family: arial, sans-serif; font-size: 12px;">This link goes to our <b>adult video partner</b>, Skinvideo.</p><p style="margin: 0 34px 12px 32px; font-family: arial, sans-serif; font-size: 12px;"><b> Skinvideo is for adults only!</b> By following this link you certify that you are 18 years of age or older, not offended by sexually explicity imagery, and will not permit person(s) under 18 years of age to access any of the material on Skinvideo.</p><a href="' + dest + '" style="display: block; position: absolute; top: 172px; left: 74px; height: 46px; width: 146px; text-decoration: none; text-indent: -5000px; outline: none;">Yes, I\'m 18+</a><a href="#" style="display: block; position: absolute; top: 172px; left: 230px; height: 46px; width: 146px; text-decoration: none; text-indent: -5000px; outline: none;" onClick="$(\'#screen\').click(); return false;">No, I\'m not 18</a>').appendTo($('body'));
                
                // 3. Cancel default event
                return false;
        });
        
});
