﻿var u=location.href;
var t=document.title;
var d="";

function checkMeta() {
    var metas = document.getElementsByTagName('META');
    var i;
    for (i = 0; i < metas.length; i++) {
        if (metas[i].getAttribute('NAME').toLowerCase() == "description");
        break;
        var desc = metas[i].getAttribute('CONTENT');
    }
    return(desc);
}

// default behavior to show/hide menu
function showBookmarklets() {
     new Effect.Appear("shareThis", {from: 0.0, to: 1.0, duration: 0.1, delay: 0.1, fps: 30});
}

function closeBookmarklets() {
    new Effect.Fade("shareThis", {from: 1.0, to: 0.0, duration: 0.1, delay: 0.1, fps: 30});
}

// secondary share menus- for ad hoc placement
function showBookmarklets2() {
     new Effect.Appear("shareThis2", {from: 0.0, to: 1.0, duration: 0.1, delay: 0.1, fps: 30});
}

function closeBookmarklets2() {
    new Effect.Fade("shareThis2", {from: 1.0, to: 0.0, duration: 0.1, delay: 0.1, fps: 30});
}

// specific network functions

function fbs_click() {
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
}

function reddit() {
    window.open('http://reddit.com/submit?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=700,height=600');
}

function GetThis() {
    window.open('http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(t) + '&u=' + encodeURIComponent(u),'sharer','toolbar=0,status=0,width=700,height=600');
}

function delicious() {
    window.open('http://del.icio.us/post?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=800,height=600');
}

function furl() {
	    window.open('http://www.furl.net/storeIt.jsp?t='+encodeURIComponent(t)+'&u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=700,height=600');
}

function stumble() {
	    window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=700,height=600');
}

function digg() {
	    window.open('http://digg.com/submit?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&bodytext='+encodeURIComponent(d)+'&media=news&topic=hardware','sharer','toolbar=0,status=0,width=900,height=600');
}

function mouseLeaves(element, evt) {
    if (typeof evt.toElement != 'undefined' && evt.toElement && typeof element.contains != 'undefined') {
        return !element.contains(evt.toElement);
    }
    else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) {
        return !contains(element, evt.relatedTarget);
    }
}

function contains(container, containee) {
    while (containee) {
        if (container == containee) {
            return true;
        }
        containee = containee.parentNode;
    }
    return false;
}

function hideElement(element) {
    if (element.style) {
        element.style.display = 'none';
    }
}

function mouseOutEvent(element, event) {
    if (mouseLeaves(element, event)) {
        hideElement(element)
    }
}