﻿
function TSButton(icn, txt) {
    this.Icon = icn
    this.Text = txt
    this.OnClick
}
Drupal.shareTitletext="<b>Share this page:</b>";
function TravelShare() {
    this.TSMenu = null
    this.TSEL = null
    this.TSUser = ''
 
    this.TitleEL = null
    this.mposx = 0;
    this.mposy = 0;
    

    this.Initialize = function(el) {
        if (!TravelShare.BaseUrl) {
            TravelShare.BaseUrl = Drupal.settings.basePath+'travelwig/'
        }

        try {
            var ss = document.createElement('link')
            ss.rel = 'stylesheet'
            ss.type = 'text/css'
            ss.href = TravelShare.BaseUrl + 'travelshare.css'
            ss.media = 'all'
            document.getElementsByTagName('head')[0].appendChild(ss)
        }
        catch (Error) { }

        this.TSEL = el
        this.SetClass(this.TSEL, 'tsdiv')
        this.TSMenu = document.createElement('div')
        this.TSUser = this.TSEL.getAttribute('username')
        if (!this.TSUser) this.TSUser = ''

        this.SetClass(this.TSMenu, 'tsmenu')
        
        
        this.TSEL.me = this
        this.TSEL.appendChild(this.TSMenu)
        this.TSEL.href=''
       

        this.CreateContainer(this.TSMenu)
    }
   
    this.CreateContainer = function(el) {
        this.TitleEL = document.createElement('div')

        var midel = document.createElement('div')

        this.TitleEL.id = 'tstitle'
        this.TitleEL.style.padding = '2px 2px 2px 10px'
        this.TitleEL.innerHTML = Drupal.shareTitletext

        midel.style.padding = '0px 0px 5px 0px'
        midel.style.margin = '0px'
        midel.style.textAlign = 'left'

        this.CreateButtons(midel)

        el.appendChild(this.TitleEL)
        el.appendChild(midel)        
    }
    
    this.CreateButtons = function(el) {
        var TheButtons = new Array()
        
        var ThePrintBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_prnt.gif', 'Print')
        var TheFacebookBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_fcbk.gif', 'Facebook')
        var TheTwitterBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_twttr.gif', 'Twitter')
        var TheFavoritesBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_fvrts.gif', 'Favorites')
        var TheMySpaceBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_myspc.gif', 'MySpace')
        var TheGoogleBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_ggl.gif', 'Google')
        var TheStumbleUponBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_stmblpn.gif', 'StumbleUpon')
        var TheDiggBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_dgg.gif', 'Digg')
        var TheLiveBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_lv.gif', 'Live')
        var TheYahooBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_yhbzz.gif', 'Yahoo! Buzz')
        var TheDeliciousBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_dlcs.gif', 'Del.icio.us')
        var TheTripAdvisorBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_tripadvisor.gif', 'TripAdvisor')
        var TheTripItBTN = new TSButton(TravelShare.BaseUrl + 'images/sh_tripit.gif', 'TripIt')
        var TheRedditBTN = new TSButton(TravelShare.BaseUrl + 'images/reddit.gif', 'Reddit');
        var TheNewsvineBTN=new TSButton(TravelShare.BaseUrl + 'images/newsvinecom.gif', 'Newsvine');
        var TheMixxBTN=new TSButton(TravelShare.BaseUrl + 'images/mixxcom.gif', 'Mixx');
        var TheDiigoBTN=new TSButton(TravelShare.BaseUrl + 'images/diigo.gif', 'Diigo');
        var TheSlashdotBTN=new TSButton(TravelShare.BaseUrl + 'images/slashdot.gif', 'Slashdot');
        var ThePropellerBTN=new TSButton(TravelShare.BaseUrl + 'images/propeller.gif', 'Propeller');
        var TheWongBTN=new TSButton(TravelShare.BaseUrl + 'images/wong.gif', 'Mister-wong');
        var TheSquidooBTN=new TSButton(TravelShare.BaseUrl + 'images/squidoocom.gif', 'Squidoo');
        var TheBloggerBTN=new TSButton(TravelShare.BaseUrl + 'images/blogger.gif', 'Blogger');
        TheBloggerBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.blogger.com/blog-this.g?u=' + escape(document.URL)+ '&n=' + escape(document.title)+'&pli=1';
            return true;
        }
        TheSquidooBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.squidoo.com/lensmaster/bookmark?' + escape(document.URL);
            return true;
        }
        TheWongBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.mister-wong.com/index.php?action=addurl&bm_url=' + escape(document.URL)+ '&bm_description=' + escape(document.title);
            return true;
        }
        ThePropellerBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.propeller.com/submit?url=' + escape(document.URL);
            return true;
        }
        TheSlashdotBTN.OnClick = function(el) {
            el.btn.link.href = 'http://slashdot.org/submission?url=' + escape(document.URL)+ '&title=' + escape(document.title)+'&new=1';
            return true;
        }
        TheDiigoBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.diigo.com/post?b_mode=0&c_mode=0&url=' + escape(document.URL)+ '&title=' + escape(document.title);
            return true;
        }
        TheMixxBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.mixx.com/submit?page_url=' + escape(document.URL);
            return true;
        }
        TheNewsvineBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.newsvine.com/_tools/seed&save?u=' + escape(document.URL) + '&h=' + escape(document.title);
            return true;
        }
        TheRedditBTN.OnClick = function(el) {
            el.btn.link.href = 'http://reddit.com/submit?url=' + escape(document.URL);
            return true;
        }
        ThePrintBTN.OnClick = function(el) {
            
            if (window.print) window.print();
        }
        TheFacebookBTN.OnClick = function(el) {           
            el.btn.link.href = 'http://www.facebook.com/sharer.php?u=' + escape(document.URL) + '&t=' + escape(document.title)
            return true
        }
        TheTwitterBTN.OnClick = function(el) {
            el.btn.link.href = 'http://twitter.com/home?status=' + escape(document.URL + ' via @travelmanana')
            return true
        }
        TheFavoritesBTN.OnClick = function(el) {
            if (navigator && navigator.userAgent) {
                if (navigator.userAgent.toLowerCase().indexOf('chrome') != -1) {
                    alert('Press <Control>+D to bookmark in Chrome')
                    return
                }
            }

            var title = document.title
            var url = document.URL
            if (window.sidebar) window.sidebar.addPanel(title, url, "");
            else if (window.external) window.external.AddFavorite(url, title);
        }
        TheMySpaceBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + escape(document.URL) + '&t=' + escape(document.title)
            return true
        }
        TheGoogleBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.google.com/bookmarks/mark?op=add&bkmk=' + escape(document.URL) + '&title=' + escape(document.title)
            return true
        }
        TheStumbleUponBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.stumbleupon.com/submit?url=' + escape(document.URL) + '&title=' + escape(document.title)
            return true
        }
        TheDiggBTN.OnClick = function(el) {
            el.btn.link.href = 'http://digg.com/submit/?phase=2&url=' + decodeURIComponent(document.URL) + '&title=' + decodeURIComponent(document.title)
            return true
        }
        TheLiveBTN.OnClick = function(el) {
            el.btn.link.href = 'https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=10&ct=' + new Date().valueOf() + '&rver=4.0.1534.0&wp=MBI&wreply=https:%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D0%26mkt%3Den-us%26url%3D' + escape(document.URL + '&title=' + document.title) + '%26top%3D1&lc=1033&id=66867'
            return true
        }
        TheYahooBTN.OnClick = function(el) {
            el.btn.link.href = 'http://buzz.yahoo.com/buzz?targetUrl=' + encodeURIComponent(document.URL) + '&submitHeadline=' + encodeURIComponent(document.title)
            return true
        }
        TheDeliciousBTN.OnClick = function(el) {
            el.btn.link.href = 'https://secure.delicious.com/login?noui=yes&v=4&jump=http%3A%2F%2Fdelicious.com%2Fsave%3Furl%3D' + escape(document.URL) + '%26title%3D' + escape(document.title) + '%26notes%3D%26tags%3D%26v%3D4%26noui%3D%26share%3Dyes%26jump%3Dclose%26time%3D1235403055'
            return true
        }
        TheTripAdvisorBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.tripadvisor.com/UserReview'
            return true
        }
        TheTripItBTN.OnClick = function(el) {
            el.btn.link.href = 'http://www.tripit.com/trip_item/createBookmark?url=' + encodeURIComponent(document.URL) + '&display_name=' + encodeURIComponent(document.title);
            return true
        }
        TheButtons.push(TheFavoritesBTN)
        TheButtons.push(ThePrintBTN)
        TheButtons.push(TheFacebookBTN)
        TheButtons.push(TheTwitterBTN)
        TheButtons.push(TheMySpaceBTN)
        TheButtons.push(TheGoogleBTN)
        TheButtons.push(TheStumbleUponBTN)
        TheButtons.push(TheDiggBTN)
        //TheButtons.push(TheLiveBTN)
        TheButtons.push(TheYahooBTN)
        TheButtons.push(TheDeliciousBTN)
        //TheButtons.push(TheTripAdvisorBTN)
        //TheButtons.push(TheTripItBTN)
        //TheButtons.push(TheRedditBTN);
        //TheButtons.push(TheNewsvineBTN);
        //TheButtons.push(TheMixxBTN);
        //TheButtons.push(TheDiigoBTN);
        //TheButtons.push(TheSlashdotBTN);
        //TheButtons.push(ThePropellerBTN);
        //TheButtons.push(TheWongBTN);
        //TheButtons.push(TheSquidooBTN);
        //TheButtons.push(TheBloggerBTN);
        for (var i = 0; i < TheButtons.length; i++) {
            var conel = document.createElement('a')
            var iconel = document.createElement('img')
            var textel = document.createElement('div')
            var clrel = document.createElement('div')

            clrel.style.clear = 'both'

            conel.setAttribute('class', 'tsbtn')
            conel.setAttribute('className', 'tsbtn')
            conel.style.display = 'inline'
            conel.style.margin = '5px 0px 0px 5px'
            conel.style.styleFloat = 'left'
            conel.style.cssFloat = 'left'
            conel.style.width = '116px'
            conel.style.padding = '0px'
            conel.style.font = '11px arial'
            conel.style.cursor = 'pointer'
            conel.target = '_blank'
            conel.btn = TheButtons[i]

            conel.onmouseover = function() { this.style.backgroundColor = '#EEEEEE'; }
            conel.onmouseout = function() { this.style.backgroundColor = '#F9F9F9'; }

            this.SetFloat(iconel, 'left')
            iconel.style.display = 'inline'
            iconel.style.border = 'none'
            iconel.style.width = '16px'
            iconel.style.height = '16px'
            iconel.style.padding = '2px 2px 2px 2px'
            iconel.src = TheButtons[i].Icon

            this.SetFloat(textel, 'left')
            textel.style.padding = '3px 0px 0px 3px'
            textel.style.textTransform = 'none';
            textel.innerHTML = TheButtons[i].Text

            TheButtons[i].link = conel

            conel.appendChild(iconel)
            conel.appendChild(textel)
            conel.appendChild(clrel)
            conel.me = this

            conel.onclick = function() { this.btn.OnClick(this); }

            el.appendChild(conel)
        }

        var clel = document.createElement('div')
        clel.style.clear = 'both'
        el.appendChild(clel)
    }

    this.UrlEncode = function(str) {
        var histogram = [], histogramv = [], tmp_arr = [];
        var ret = str.toString();

        var replacer = function(search, replace, str) {
            var tmp_arr = [];
            tmp_arr = str.split(search);
            return tmp_arr.join(replace);
        };

        histogram.push("'"); histogramv.push('%27');
        histogram.push("("); histogramv.push('%28');
        histogram.push(")"); histogramv.push('%29');
        histogram.push("*"); histogramv.push('%2A');
        histogram.push("~"); histogramv.push('%7E');
        histogram.push("!"); histogramv.push('%21');
        histogram.push("%20"); histogramv.push('+');

        ret = encodeURIComponent(ret);

        for (var i = 0; i < histogram.length; i++) 
        {
            ret = replacer(histogram[i], histogramv[i], ret)
        }

        return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) 
        {
            return "%" + m2.toUpperCase();
        });

        return ret;
    }
    this.aim = function(el, mask) {
        el.Mask = mask
        el.value = mask
        el.style.color = "#AAAAAA";
        el.me = this
        el.onfocus = function() { this.me.OnItemFocus(this); }
        el.onblur = function() { this.me.OnItemBlur(this); }
    }
    this.OnItemFocus = function(el) {
        if (el.value == el.Mask) {
            el.value = "";
            el.style.color = "#000000";
        }
    }
    this.OnItemBlur = function(el) {
        if ((el.value == "") || (el.value == el.Mask)) {
            el.value = el.Mask;
            el.style.color = "#AAAAAA";
        }
    }
    this.SetFloat = function(el, afloat) {
        el.style.styleFloat = afloat
        el.style.cssFloat = afloat
    }

    this.SetClass = function(el, name) {
        el.className = name
        el.setAttribute('class', name)
    }
}

if (!window.TravelShareLoaded) {
    window.TravelShareLoaded = true;

    TravelShare.prototype.BaseUrl =Drupal.settings.basePath+'travelwig/'
    var TheTravelShares = new Array()

    var TheTSOldLoad = window.onload
    var TheTSOldMove = document.onmousemove

    window.onload = function() {
        if (TheTSOldLoad) TheTSOldLoad()

        
        var TheTravelShareElement = document.getElementById('tsdiv')
      
        if (TheTravelShareElement) {
            var TheTravelShare = new TravelShare()
            TheTravelShare.Initialize(TheTravelShareElement)
            TheTravelShares.push(TheTravelShare)
        }
    }
}



