﻿var fade_started=0; 
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function blendIn(id, millisec)
{
    opacity(id, 0, 85, millisec);
}

function blendOut(id, millisec)
{
    opacity(id, 85, 0, millisec);
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if( fade_started == 0 )
    {
        fade_started = 1;
        if(document.getElementById(id).style.opacity == 0)
        {
            opacity(id, 0, 100, millisec);
        }
        else
        {
            opacity(id, 100, 0, millisec);
        }
        setTimeout("fadeFinished()",millisec);
    }
} 

function fadeFinished()
{
    fade_started=0;
}

    /******* Social Bookmarking functions ******/
/**
* toggles SocialBookmark-Box on and off
* @param spDisplay - ture=on, false=off
*/
function spSocialBookmarkSetDisplay(spDisplay) {
spSocialBookmarkElement = document.getElementById("spSocialBookmark");
//if(document.all){
//spSocialBookmarkElement.filters[0].Apply();
//if(spDisplay) {
//spSocialBookmarkElement.filters[0].Direction  = "down";
//spSocialBookmarkElement.style.visibility = "visible";
//}
//else {
//spSocialBookmarkElement.filters[0].Direction  = "up";
//spSocialBookmarkElement.style.visibility = "hidden";
//}
//spSocialBookmarkElement.filters[0].Play(duration=.5);
//}
//else {
if( spDisplay )
{
spSocialBookmarkElement.style.visibility = "visible";
blendIn("spSocialBookmark", 600);
}
else
{
blendOut("spSocialBookmark", 600);
setTimeout( "spSocialBookmarkOff()", 600 );
}
//}
spSocialBookmarkState=spDisplay;
}

function spSocialBookmarkOff()
{
    var elm = document.getElementById("spSocialBookmark");
    elm.style.visibility = "hidden";
}
/**
* toggle function called form Bookmark Link
* served spSocialBookmarkSetDisplay() and starts EventHandler
*/
function spSocialBookmarkToggle() {
if (!spSocialBookmarkState) {
spSocialBookmarkSetDisplay(true);
spStartMouseEvent();
}
else 
spSocialBookmarkSetDisplay(false);
}
/**
* Event handler function tests where the user clicked
* and acts	according to this (switch SocialBookmark-Box off 
* stops EventHandler)
*/
function spSocialBookmarkToggleDisplay(e) {
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
if (targ.id == "spSocialBookmarkLink") {
spStopMouseEvent();
return false;
}
var isInDiv = false;
while(targ != null) {
if (targ.id == "spSocialBookmark") {
isInDiv=true;
break;
}
if (targ.id == "spSocialBookmarkClose")
break;
targ = targ.parentNode;
}
if (!isInDiv) {
spSocialBookmarkSetDisplay(false);
spStopMouseEvent();
}
return false;
}
/**
* starts EventHandling
*/
function spStartMouseEvent(){
if (document.addEventListener) { // DOM Level 2 Event Model
document.addEventListener("mouseup", spSocialBookmarkToggleDisplay, true);
}
else if (document.attachEvent) { // IE 5+ Event Model
document.attachEvent("onmouseup", spSocialBookmarkToggleDisplay);
}
else { // IE 4 Event Model
document.onmouseup=spSocialBookmarkToggleDisplay;
}
}
/**
* stops EventHandling
* spOldHandler is a hack for EI4 Event Model
*/
var spOldHandler = document.onmouseup;	// Eventhandler for EI 4 StopEvent
function spStopMouseEvent() {
// Unregister the capturing event handlers.
if (document.removeEventListener) { // DOM Event Model
document.removeEventListener("mouseup", spSocialBookmarkToggleDisplay, true);
}
else if (document.detachEvent) { // IE 5+ Event Model
document.detachEvent("onmouseup", spSocialBookmarkToggleDisplay);
}
else { // IE 4 Event Model
document.onmouseup = spOldHandler;
}
}


function bookmark( target )
    {
        var sbUrl = '';
        switch(target)
        {
            case 'technorati':
                sbUrl = 'http://technorati.com/faves?add='+encodeURIComponent(location.href)+'&tag=';
                break;
            case 'blinklist':
                sbUrl = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Tag=&Url='+encodeURIComponent(location.href)+'&Title='+encodeURIComponent(document.title);
                break;
            case 'google':
                sbUrl = 'http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+encodeURIComponent(location.href)+'&annotation=&labels=&title='+encodeURIComponent(document.title);
                break;
            case 'yahoo':
                sbUrl = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(document.title)+'&d=&tag=&u='+encodeURIComponent(location.href);
                break;
            case 'furl':
                sbUrl = 'http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&keywords=&t='+encodeURIComponent(document.title);
                break;
            case 'reddit':
                sbUrl = 'http://reddit.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title);
                break;
            case 'delicious':
                sbUrl = 'http://del.icio.us/post?v=2&url='+encodeURIComponent(location.href)+'&notes=&tags=&title='+encodeURIComponent(document.title);
                break;
            case 'linkarena':
                sbUrl = 'http://linkarena.com/bookmarks/addlink/?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'desc=&tags=';
                break;
            case 'wong':
            default:
                sbUrl = 'http://www.mister-wong.de/index.php?action=addurl&bm_url='+encodeURIComponent(location.href)+'&bm_notice=&bm_description='+encodeURIComponent(document.title)+'&bm_tags=';
                break;  
        }
        
        window.open(sbUrl);
    }

