
function appEmbed(instanceid)
{
    this.instanceid = instanceid;
    this.stagewidth = 341;
    this.stageheight = 256;

    this.defwidth = 341;
    this.defheight = 256;

    this.link_logo = 'http://www.rockyou.com?type=slideshow&refid='+this.instanceid;
    this.link_create = 'http://www.rockyou.com/slideshow_create.php?source=cyo&refid='+this.instanceid;
    this.link_view = 'http://www.rockyou.com/show_my_gallery.php?instanceid='+this.instanceid;
    this.img_logo = 'http://apps.rockyou.com/images/tail_logo.gif';
    
    this.noSound = false;    
    this.noShare = false;

    this.playlist_link = "";
    this.type = "sl1";
    this.xmlpathprefix = "";

    this.ctid = "";
    
    this.approottail = "";

    this.islocal = false;
    this.sizelocked = false;
    this.isScale = true;
    
    this.frengo_id = 0;
    
    this.publish_type = 'default';
    
    this.overridesize = function()
    {
        if (this.sizelocked && !this.isTvRatio())
        {
            if (this.stagewidth == this.defwidth)
                return false;
            else
                return true;
        }
        else
        return false;
    }

    this.appurlroot = function () {
        switch (this.type)
        {
            case "sl2": case "sl1": default:
                var frengo_param = '';
                if (this.frengo_id > 0) frengo_param = '&username='+this.frengo_id;
                return 'http://apps.rockyou.com/rockyou.swf?instanceid='+this.instanceid+frengo_param+'&ver=102906';
                break;
            case "sc1":
                return 'http://apps.rockyou.com/scratch.swf?instanceid='+this.instanceid+'&ver=102906';
                break;
            case "fx1":
                return 'http://apps.rockyou.com/text-viewer.swf?instanceid='+this.instanceid+'&'+this.approottail+'&ver=102906';
                break;
            case "ct1":
                return 'http://apps.rockyou.com/countdown.swf?ID='+this.instanceid+'&ver=102906';
                break;
        }


    }
    this.appurlpreview = function () {return this.appurlroot()+((this.islocal)? '&xmlpath='+this.xmlpathprefix+'xmllocal':'')+'&nopanel=true'+((this.noSound)? '&nosound=true&noclick=yes':'')+((this.noShare)? '&noshare=true':'&noshare=false');}
    this.appurlpublic = function () {return this.appurlroot();}
    this.urltail = function () {
            switch (this.type)
            {
                case "sl2": case "sl1": default:
                    return '</td></tr><tr><td style="font-size:0px;background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="left">'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px;" src="'+this.img_logo+'"></a></td><td style="background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="right"><a style="padding-right:0px;" target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_create.gif"></a><a style="padding-right:0px;" target="_BLANK" href="'+this.link_view+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_view.gif"></a>'+this.playlist_link;
                    break;
                    case "sc1":
                    return '</td></tr><tr><td style="font-size:0px;background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="left">'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_logo.gif"></a></td><td style="background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="right"><a style="padding-right:0px;" target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_create.gif"></a>';
                    break;
                    case "fx1":
                    return '<br>'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'"><img alt="RockYou Scratcher" src="http://apps.rockyou.com/images/logo-mini.gif" border="0"></a> | <a target="_BLANK" href="'+this.link_create+'">Create Your Own</a>';
                    break;
                    case "ct1":
                    return '</td></tr><tr><td style="font-size:0px;background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="left">'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_logo.gif"></a></td><td style="background-color:#fff; padding:1px;font-size:0px;  filter:alpha(opacity=60);-moz-opacity:.60;opacity:.60;" align="right"><a style="padding-right:0px;" target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_create.gif"></a>';
                    break;
            }
        }
    

    this.urltail_mini = function () {
            switch (this.type)                   
            {
                case "sl2": case "sl1": default:
                    return '<br>'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px;" src="'+this.img_logo+'"></a> <a target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_create.gif"></a>';
                    break;
                    case "sc1":
                    return '<br>'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px" src="http://apps.rockyou.com/images/tail_logo.gif"></a><a target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px" src="http://apps.rockyou.com/images/tail_create.gif"></a>';
                    break;
                    case "fx1":
                    return '<br>'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'"><img alt="RockYou Scratcher" src="http://apps.rockyou.com/images/logo-mini.gif" border="0"></a> | <a target="_BLANK" href="'+this.link_create+'">Create Your Own</a>';
                    break;
                    case "ct1":
                    return '<br>'+this.ctid+'<a target="_BLANK" href="'+this.link_logo+'">'+'<img style="border:0px" src="http://apps.rockyou.com/images/tail_logo.gif"></a><a target="_BLANK" href="'+this.link_create+'">'+'<img style="border:0px" src="http://apps.rockyou.com/images/tail_create.gif"></a>';
                    break;
            }
        }
    
    

    this.flashvars = function () {
        return (!this.isTvRatio()?' scale="noscale" ':'')+' salign="lt" '+(this.overridesize()?' flashvars="&appWidth='+this.stagewidth+'&appHeight='+this.stageheight+'" ':"");
    }

    this.set_playlist_link = function(url, bool)
    {
        if(bool) {
            this.playlist_link = '<a style="padding-right:0px;" target="_BLANK" href="'+url+'">'+'<img style="border:0px;" src="http://apps.rockyou.com/images/tail_playlist.gif"></a>';
        }
    }

    this.setType = function(type)
    {
        switch (type)
        {
            case "slideshow":
                this.link_logo = 'http://www.rockyou.com?type=slideshow&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/slideshow_create.php?source=cyo&refid='+this.instanceid;
                this.link_view = 'http://www.rockyou.com/show_my_gallery.php?instanceid='+this.instanceid;
                this.img_logo = 'http://apps.rockyou.com/images/tail_logo.gif';
                this.type = "sl1";
                break;
            case "slider":
                this.link_logo = 'http://www.rockyou.com?type=slideshow&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/slideshow_create.php?source=cyo&refid='+this.instanceid;
                this.type = "sl2";
                break;
            case "scratcher":
                this.link_logo = 'http://www.rockyou.com?type=scratcher&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/scratch-create.php?refid='+this.instanceid;
                this.type = "sc1";
                break;
            case "fxtext":
                this.link_logo = 'http://www.rockyou.com?type=fxtext&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/fxtext/fxtext-create.php?refid='+this.instanceid;
                this.type = "fx1";
                break;
            case "ctimer":
                this.link_logo = 'http://www.rockyou.com?type=ctimer&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/ctimer/create.php?refid='+this.instanceid;
                this.type = "ct1";
                break;
            default:
                this.link_logo = 'http://www.rockyou.com?type=slideshow&refid='+this.instanceid;;
                this.link_create = 'http://www.rockyou.com/slideshow_create.php?source=cyo&refid='+this.instanceid;
                this.type = "sl1";
                break;
        }
    }

    this.setLocal = function (local)
    {
        this.islocal = local;
    }

    this.getRatio = function ()
    {
        return this.stagewidth / this.stageheight;
    }

    this.isTvRatio = function()
    {
        val = this.getRatio();
        if (val > 1.2 && val < 1.4)
        {
            return true;
        }
        return false;
    }

    this.setPixelSize = function(wd,ht)
    {
        this.stagewidth = wd;
        this.stageheight = ht;
    }

    this.setBasePixelSize  = function(wd,ht)
    {
        this.defwidth = wd;
        this.defheight = ht;
        this.setPixelSize(wd,ht);
        this.isScale = true;
    }

    this.scale = function (scale)
    {
        this.stagewidth = Math.round(this.defwidth*scale);
        this.stageheight = Math.round(this.defheight*scale);
        this.isScale = true;
    }

    
    

    this.embedURL = function ()
    {
        return ( '<table style="border-collapse:collapse;"><tr><td colspan="2"><embed src="'+this.appurlpublic() +'" quality="high" '+ this.flashvars() + 'width="'+this.stagewidth+'" height="'+this.stageheight+'" wmode="transparent" name="rockyou" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>'+this.urltail()+'</td></tr></table>');
    }

    this.embedWordPressCode = function ()
    {
        return ( '[rockyou id=' + this.instanceid + '&w='+this.stagewidth+'&h='+this.stageheight+']' );
    }
    
    this.embedWordPressOrgCode = function ()
    {
        return ( '[rockyou ' + this.instanceid + ']' );
    }

    
    /* getUBBEmbed will generate this particular type of embedding code for the slideshow. */
    this.getUBBEmbed = function () {
        return '[flash]'+this.appurlpublic()+'[/flash]';
    }
    
    this.getShortEmbed = function () {
        return ('<embed src="'+this.appurlpublic() +'" quality="high" '+ this.flashvars() + 'width="'+this.stagewidth+'" height="'+this.stageheight+'" wmode="transparent" name="rockyou" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></embed>');
    }

    
    this.onSiteEmbedURL = function ()
    {

        return ( '<embed src="'+this.appurlpreview() +'" quality="high" '+ this.flashvars() + ' width="'+this.stagewidth+'" height="'+this.stageheight+'" wmode="transparent" name="rockyou" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>');
    }

    this.insertEmbed = function (id)
    {
        val = this.onSiteEmbedURL();
        //alert(val);
        document.getElementById(id).innerHTML = val;
    }

    this.insertCode = function (id)
    {
         switch(this.publish_type) {
            case "default":
                val = this.embedURL();
                document.getElementById(id).value = val;
                break;
            case "mini":
                this.insertMiniCode(id);
                break;
            default:
                val = this.embedURL();
                document.getElementById(id).value = val;
                break;
        }
    }

    this.insertWordPressCode = function (id)
    {
        val = this.embedWordPressCode();
        document.getElementById(id).value = val;
    }
    
    this.insertWordPressOrgCode = function (id)
    {
        val = this.embedWordPressOrgCode();
        document.getElementById(id).value = val;
    }
    
    
    /* insertUBBCode will put the particular type of embedding code in the specific object in the page */
    this.insertUBBCode = function (id)
    {
        val = this.getUBBEmbed();
        document.getElementById(id).value = val;
    }
    
    this.insertShortCode = function (id) {
        val = this.embedURL();
        document.getElementById(id).value = val;
    }
    
     this.insertMiniCode = function (id) {                                            
        val = this.getShortEmbed()+this.urltail_mini();
        document.getElementById(id).value = val;
    }

    this.getCode = function ()
    {
         switch(this.publish_type) {
            case "default":
                return  this.embedURL();
                break;
            case "mini":
                return this.getShortEmbed()+this.urltail_mini();
                break;
            case "old":
                return  this.embedURL();
                break;
            default:
                return this.embedURL();
                break;
        }
    }
    
    this.insertClosedCode = function (id) {                                            
        val = this.getClosedEmbed();
        document.getElementById(id).value = val;
    }
    
    this.getClosedEmbed = function () {
        return ( '<table style="border-collapse:collapse;"><tr><td colspan="2"><embed src="'+this.appurlpublic() +'" quality="high" '+ this.flashvars() + 'width="'+this.stagewidth+'" height="'+this.stageheight+'" wmode="transparent" name="rockyou" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'+this.urltail()+'</td></tr></table>');   
    }
    
    this.setXmlPathPrefix = function (prefix) {
        this.xmlpathprefix = prefix;
    }
    
}
