﻿var arti2SNSjq = {

    surl : '',
    longurl : '',
    title : '',
    type : '',
    ispop : false,
    
    getShortUrl : function (longurl) {

		var durlurl = "/makeshorturl.asp";
		var sendmsg = "longurl="+longurl;
		//alert(sendmsg);
		new Ajax.Request(durlurl, {
		  method:'get', parameters : sendmsg,
		  onSuccess: function(transport){
			 var json = transport.responseText.evalJSON();
             arti2SNSjq.surl = json.shortUrl;
			 arti2SNSjq.linkPage();
		   }
		});		
            
    },
    
    showPage : function(type,title,longurl,ispop) {

        this.type = type;
        this.title = title;
        this.ispop = ispop;
        this.longurl = longurl;

        this.getShortUrl(longurl);
    },

    linkPage : function() {

        var surl = this.surl;
        var longurl = this.longurl;
        var type = this.type;
        var title = this.title;
        var ispop = this.ispop;

        if( (typeof surl != "undefined") && surl != "") {

            switch(type) {


                case 'facebook': 
                        var link = 'http://www.facebook.com/sharer.php?u=' + longurl + "&t=" + title ;
                        if (ispop) {
                            popwin = window.open(link,'popwin', 'width=800, height=500,resizable=yes,scrollbars=yes');
                            if(popwin)
                                popwin.focus();
                        } else {
                            document.location = link;
                        }
                break;

                case 'twitter': 
                        var link = 'http://twitter.com/home?status=' + title + ':' + surl ;
                        if (ispop) {
                            popwin = window.open(link,'popwin', 'width=800, height=500,resizable=yes,scrollbars=yes');
                            if(popwin)
                                popwin.focus();
                        } else {
                            document.location = link;
                        }
                break;

                default:
                break;
            }
            return;
        }
/*        else    {
            alert('');
        } */

    }
}
