// social.js
// author: Hamish Wright
// created: 01/10/2007
// modified: 01/10/2007
// Create a rotating social bookmarking tool

function social_xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            social_updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}

function social_updatepage(str){
    //document.getElementById("result").innerHTML = str;
    //alert(str);
}

function createbookmark(socialid)
{
    var winH = 600 
    var winW = 800
    var toolbar = 0
    var status = 0
    var menubar = 0
    var location = 0
    var scrollbars = 1
    var title = 'New_Bookmark'
    
    if(gSocialProjGuid.length > 0) social_xmlhttpPost("/tools/ajax/socialcounter.php?projguid="+gSocialProjGuid+"&socialurl="+document.location.href+"&socialid="+socialid);
    
    switch(socialid)
    {
    case 'twitter':
      window.open('http://twitter.com/home?status='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'delicious':
      window.open('http://del.icio.us/post?url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'digg':
      window.open('http://digg.com/submit?phase=2&url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'furl':
      window.open('http://www.furl.net/store?s=f&to=0&u='+document.location.href+'&ti='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'newsvine':
      window.open('http://www.newsvine.com/_tools/seed&save?u='+document.location.href+'&T='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'netscape':
      window.open('http://www.netscape.com/submit/?U='+document.location.href+'&T='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'reddit':
      window.open('http://reddit.com/submit?url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'stumble':
      window.open('http://www.stumbleupon.com/submit?url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'technorati':
      window.open('http://technorati.com/faves?add='+document.location.href+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'squidoo':
      window.open('http://www.squidoo.com/lensmaster/bookmark?'+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'winlive':
      window.open('https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url='+document.location.href+'&title='+document.title+'&top=1',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'yahoo':
      window.open('http://myweb.yahoo.com/myresults/bookmarklet?u='+document.location.href+'&t='+document.title+'&ei=UTF',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'ask':
      window.open('http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url='+document.title.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'google':
      window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'magnolia':
      window.open('http://ma.gnolia.com/bookmarklet/snap/add?url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'rawsugar':
      window.open('http://www.rawsugar.com/pages/tagger.faces?turl='+document.location.href+'&tttl='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'spurl':
      window.open('http://www.spurl.net/spurl.php?url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'tagtooga':
      window.open('http://www.tagtooga.com/tapp/db.exe?c=jsEntryForm&b=fx&url='+document.location.href+'&title='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    case 'facebook':
      window.open('http://www.facebook.com/sharer.php?u='+document.location.href+'&t='+document.title+'',''+title+'','width='+winW+',height='+winH+',toolbar='+toolbar+',status='+status+',menubar='+menubar+',location='+location+',scrollbars='+scrollbars+'')
    break;
    
    default:
    break;
    }
}

var gSocialSecs;
var gSocialTimerID = null;
var gSocialTimerRunning = false;
var gSocialDelay = 1000;
var gSocialIndex = 0;
var gSocialsShowing = true;
var gSocialProjGuid = '';
var gSocialPageId = '';


function InitializeSocials(projguid,pageid,timerdelay)
{
    HideAllSocials();
    document.getElementById('social-expand').style.display = 'none';
    document.getElementById('social-hide').style.display = 'none';
    gSocialIndex = 0; 
    document.getElementById('social-'+gSocialIndex).style.display = 'inline';
    document.getElementById('label-'+gSocialIndex).style.display = 'none';
    document.getElementById('tickerlabel-'+gSocialIndex).style.display = 'inline';
    SocialInitializeTimer();
    gSocialProjGuid = projguid;
	gSocialPageId = pageid;
}

function HideAllSocials()
{
    for(i=0;i<numsocials;i++)
    {
        document.getElementById('social-'+i).style.display = 'none';
    }
    gSocialsShowing = false;
}

function ShowAllSocials()
{
	for(i=0;i<numsocials;i++)
    {
        document.getElementById('social-'+i).style.display = 'block';
        document.getElementById('tickerlabel-'+i).style.display = 'none';
        document.getElementById('label-'+i).style.display = 'inline';
    }
    gSocialsShowing = true;
}

function ShowNextSocial()
{
    document.getElementById('social-'+gSocialIndex).style.display = 'none';
    gSocialIndex++;
    if(gSocialIndex >= numsocials) { gSocialIndex = 0; }
    document.getElementById('social-'+gSocialIndex).style.display = 'inline';
    document.getElementById('tickerlabel-'+gSocialIndex).style.display = 'inline';
    document.getElementById('label-'+gSocialIndex).style.display = 'none';
}

function SocialInitializeTimer()
{
    // Set the length of the timer, in seconds
    gSocialSecs = 3;
    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
    if(gSocialTimerRunning)
        clearTimeout(gSocialTimerID);
    gSocialTimerRunning = false;
}

function StartTheTimer()
{
    if (gSocialSecs==0)
    {
        ShowNextSocial();
        SocialInitializeTimer();
    }
    else
    {
        self.status = gSocialSecs;
        gSocialSecs = gSocialSecs - 1;
        gSocialTimerRunning = true;
        gSocialTimerID = self.setTimeout("StartTheTimer()", gSocialDelay);
    }
}

function SocialOnClick()
{
    if(gSocialsShowing)
    {
        HideAllSocials();
        document.getElementById('social-hide').style.display = 'none';
        document.getElementById('social-expand').style.display = 'inline';
    }
    else
    {
        StopTheClock();
        document.getElementById('social-expand').style.display = 'none';
        document.getElementById('social-hide').style.display = 'inline';
        ShowAllSocials();
    }
}

function SocialOnMouseOver()
{
    if(!gSocialsShowing)
    {
        StopTheClock();
        document.getElementById('social-'+gSocialIndex).style.display = 'none';
        document.getElementById('social-expand').style.display = 'inline';  
    }
}

function SocialOnMouseOut()
{
    if(!gSocialsShowing)
    {
        document.getElementById('social-expand').style.display = 'none';
        document.getElementById('social-hide').style.display = 'none';
        document.getElementById('social-'+gSocialIndex).style.display = 'inline';
        document.getElementById('label-'+gSocialIndex).style.display = 'none';
        document.getElementById('tickerlabel-'+gSocialIndex).style.display = 'inline';

        SocialInitializeTimer();
    }
}

