
/*
 *
 */

var Functions;

/*
 *
 */

Functions = {};

/*
 *
 */

Functions.SetXY = function (obj, offsettype) {
    var totaloffset = (offsettype == 'left') ? obj.offsetLeft : obj.offsetTop;
    var parentEl = obj.offsetParent;
    while(parentEl != null) {
        totaloffset = (offsettype == 'left') ? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}

/*
 *
 */

Functions.GoogleSE = {};

Functions.GoogleSE.Show = function (subhref) {
    if(document.getElementById('functionsGoogleSE')) {
        var subobj  = document.getElementById('functionsGoogleSE');
        var opt_position = 'bottom';
        var xpos = Functions.GoogleSE.SetXY(subhref, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-subhref.offsetWidth) : 0)
        var ypos = Functions.GoogleSE.SetXY(subhref, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? subhref.offsetHeight : 0)
        ypos = ypos - 128;
        xpos = xpos + 0;
        subobj.style.left = xpos + "px";
        subobj.style.top  = ypos + "px";
        Spry.Effect.AppearFade('functionsGoogleSE', {duration:400,from:0,to:100,toggle:true});
        return false;
    } else {
        return true;
    }
}

Functions.GoogleSE.SetXY = function (obj, offsettype) {
    var totaloffset = (offsettype == 'left') ? obj.offsetLeft : obj.offsetTop;
    var parentEl = obj.offsetParent;
    while(parentEl != null) {
        totaloffset = (offsettype == 'left') ? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}

/*
 *
 */

Functions.Bookmark = {};

Functions.Bookmark.Highlight = function(href, service) {
    if(service != '') {
        href.src = href.src.replace('_g.gif', '.gif');
    } else {
        href.src = href.src.replace('.gif', '_g.gif');
    }
    return false;
}

Functions.Bookmark.Service = function(service) {
	var thisUri   = location.href.split('?');
	var thisUrl   = encodeURIComponent(thisUri[0]);
    var thisTitle = encodeURIComponent(document.title);
	switch(service) {
		case 'blinkList':
			window.open('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&_20x20='+thisUrl+'&Title='+thisTitle);
			break;
		case 'delicious':
			window.open('http://del.icio.us/post?_20x20='+thisUrl+'&title='+thisTitle);
			break;
		case 'folkd':
			window.open('http://www.folkd.com/submit/page/'+thisUrl);
			break;
		case 'f_20x20':
			window.open('http://www.f_20x20.net/storeIt.jsp?u='+thisUrl+'&t='+thisTitle);
			break;
		case 'google': 		
			window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+thisUrl+'&title='+thisTitle);
			break;
		case 'linkarena':	
			window.open('http://linkarena.com/bookmarks/addlink/?_20x20='+thisUrl+'&title='+thisTitle+'&desc=&tags=');
			break;
		case 'oneview':
			window.open('http://beta.oneview.de/quickadd/neu/addBookmark.jsf?_20x20='+thisUrl+'&title='+thisTitle);			
			break;
		case 'webnews': 		
			window.open('http://www.webnews.de/einstellen?_20x20='+thisUrl+'&title='+thisTitle);
			break;
		case 'wong':
			window.open('http://www.mister-wong.de/index.php?action=add_20x20&bm__20x20='+thisUrl+'&bm_description='+thisTitle);
			break;
		case 'yahoo':
			window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+thisUrl+'&t='+thisTitle);
			break;
		case 'yigg':
			window.open('http://yigg.de/neu?ext_20x20='+thisUrl+'&exttitle='+thisTitle);
			break;	
	}
    return false;
}

/*
 * 
 */

Functions.Sitemap = {};

Functions.Sitemap.Anchor = function(href) {
    var sitemap = document.getElementById('functionsSitemap');
    
    var opt_position = 'bottom';
    var xpos = Functions.GoogleSE.SetXY(href, 'left') + ((typeof opt_position != 'undefined' && opt_position.indexOf('right')  != -1) ? -(sitemap.offsetWidth-href.offsetWidth) : 0)
    var ypos = Functions.GoogleSE.SetXY(href, 'top')  + ((typeof opt_position != 'undefined' && opt_position.indexOf('bottom') != -1) ? href.offsetHeight : 0)
    ypos = ypos - 0;
    xpos = xpos + 0;
    sitemap.style.left = xpos + 'px';
    sitemap.style.top  = ypos + 'px';
    Spry.Effect.AppearFade('functionsSitemap', {duration:400,from:0,to:100,toggle:true});
    return false;

}

/*
 * 
 */

Functions.Tooltip = {};

Functions.Tooltip.Anchor = function(href, cid) {
    var sitemap = document.getElementById('contentDetails');
    sitemap.innerHTML = '<div>'+document.getElementById('contentDetails'+cid).innerHTML+'</div>';
    
    var opt_position = 'bottom';
    var xpos = Functions.GoogleSE.SetXY(href, 'left') + ((typeof opt_position != 'undefined' && opt_position.indexOf('right')  != -1) ? -(sitemap.offsetWidth-href.offsetWidth) : 0)
    var ypos = Functions.GoogleSE.SetXY(href, 'top')  + ((typeof opt_position != 'undefined' && opt_position.indexOf('bottom') != -1) ? href.offsetHeight : 0)
    ypos = ypos - 0;
    xpos = xpos + 0;
    sitemap.style.left = xpos + 'px';
    sitemap.style.top  = ypos + 'px';
    Spry.Effect.AppearFade('contentDetails', {duration:400,from:0,to:100,toggle:false});
    return false;

}

Functions.Tooltip.AnchorOut = function(href, cid) {
    var sitemap = document.getElementById('contentDetails');
    sitemap.innerHTML = '<div>'+document.getElementById('contentDetails'+cid).innerHTML+'</div>';
    
    var opt_position = 'bottom';
    var xpos = Functions.GoogleSE.SetXY(href, 'left') + ((typeof opt_position != 'undefined' && opt_position.indexOf('right')  != -1) ? -(sitemap.offsetWidth-href.offsetWidth) : 0)
    var ypos = Functions.GoogleSE.SetXY(href, 'top')  + ((typeof opt_position != 'undefined' && opt_position.indexOf('bottom') != -1) ? href.offsetHeight : 0)
    ypos = ypos - 0;
    xpos = xpos + 0;
    sitemap.style.left = xpos + 'px';
    sitemap.style.top  = ypos + 'px';
    Spry.Effect.AppearFade('contentDetails', {duration:200,from:100,to:0,toggle:false});
    //sitemap.style.display = 'none';
    return false;

}
