window.addEvent('domready', function() {
	
	// calculate vertical slider position on site
	if (document.getElementById('share')!=null){
		var intLeftPos=document.getElementById('share').offsetLeft-8;
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //Set the image to middle position when the browser version is ie 6
		{ //test for MSIE x.x;
			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion==7){
				intLeftPos=document.getElementById('share').offsetLeft-4;
			}
			if (ieversion>7){
				intLeftPos=document.getElementById('share').offsetLeft-9;
			}
		}
	}

	// vertical slider
	if (document.getElementById('share_slide')){
		document.getElementById('share_slide').style.left=intLeftPos+"px";
	  	document.getElementById('share_slide').style.display = 'none';
	}
	if (document.getElementById('share_legal')){
		document.getElementById('share_legal').style.left=intLeftPos+"px";
		document.getElementById('share_legal').style.display = 'none';
	}
	// var myVerticalSlide = new Fx.Slide('share_slide');

	if($('share')){  
		$('share').addEvent('click', function(e){
			if(document.getElementById('share_slide').style.display == 'none') {
				document.getElementById('share_slide').style.display = 'block';
				document.getElementById('share_legal').style.display = 'none';
			} else {
				document.getElementById('share_slide').style.display = 'none';
			}

		});
	};	
});


function handleShare(onoff){
//  alert(onoff);
  if(onoff){
    document.getElementById('share_slide').style.display = 'block';
    document.getElementById('share_legal').style.display = 'none';
//    document.getElementById('divShare').className='shareActive';
  }else{
    document.getElementById('share_slide').style.display = 'none';
    document.getElementById('share_legal').style.display = 'none';
//    document.getElementById('divShare').className='share';
  }  
}

function OpenWindow (address) {
      NewWindow = window.open(address);
      NewWindow.focus();
      document.getElementById('share_legal').style.display = 'none';
}


function share_legal_layer(bookmarkservice) {

  	if(document.getElementById('share_legal').style.display == 'none') {
      document.getElementById('share_slide').style.display = 'none';
      document.getElementById('share_legal').style.display = 'block';
      // document.getElementById('share_legal_form').action = 'javascript:OpenWindow("' + Target + '")';
      switch (bookmarkservice) {
        case "fav":
          document.getElementById('share_legal_form').action = 'javascript:addBookmark();';
          break;
        case "twitter":
          document.getElementById('share_legal_form').action = 'javascript:TwitThis.pop();';
          break;
        case "facebook":
          document.getElementById('share_legal_form').action = 'javascript:Facebook.pop();';
          break;
        case "myspace":
          document.getElementById('share_legal_form').action = 'javascript:MySpace.pop();';
          break;
        case "google":
          document.getElementById('share_legal_form').action = 'javascript:Google.pop();';
          break;
        case "delicious":
          document.getElementById('share_legal_form').action = 'javascript:Delicious.pop();';
          break;
        case "digg":
          document.getElementById('share_legal_form').action = 'javascript:Digg.pop();';
          break;
        case "misterwong":
          document.getElementById('share_legal_form').action = 'javascript:MisterWong.pop();';
          break;
        case "reddit":
          document.getElementById('share_legal_form').action = 'javascript:Reddit.pop();';
          break;
        case "stumbleupon":
          document.getElementById('share_legal_form').action = 'javascript:StumbleUpon.pop();';
          break;
        case "windowslive":
          document.getElementById('share_legal_form').action = 'javascript:WindowsLive.pop();';
          break;
        case "yahoobuzz":
          document.getElementById('share_legal_form').action = 'javascript:YahooBuzz.pop();';
          break;
        case "email":
          document.getElementById('share_legal_form').action = 'javascript:handle_email();';
          break;
      }
    } else {
      document.getElementById('share_slide').style.display = 'block';
      document.getElementById('share_legal').style.display = 'none';
    }
}

function handle_email(){
	document.getElementById("transMask").onclick = function()
    {
      close_email();
    };      
    document.getElementById('tipframe').src = document.getElementById('hiddentiplink').value;
    document.getElementById('share_tipfriend').style.display = 'block';
    

    
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //Set the image to middle position when the browser version is ie 6
	{ //test for MSIE x.x;
		screen_height = document.body.clientHeight;
		screen_width = document.body.clientWidth;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
//		if (ieversion==6)
//		{	
//		      //document.getElementById('share_tipfriend').style.top =  (document.getElementById("content-overlay").scrollHeight -600) + "px";
//		      document.getElementById('share_tipfriend').style.left = "0px";
//           document.getElementById('share_tipfriend').style.zIndex = '1070';
//			var intLeftPos=parseInt( (document.body.clientWidth - 366)/2 );
//			alert(intLeftPos);
//			document.getElementById('share_tipfriend').style.left="-"+intLeftPos+"px";
//		}
	}else{
		screen_height=window.innerHeight;
		screen_width=window.innerWidth;
	}
    var intTopPos=document.getElementById("content-overlay").scrollTop+parseInt((screen_height-541)/2);
    var intLeftPos=document.getElementById("content-overlay").scrollLeft+parseInt((screen_width-366)/2);
    
    document.getElementById('share_tipfriend').style.top=intTopPos+"px";
    document.getElementById('share_tipfriend').style.left=intLeftPos+"px";

	MenuMatic.aSubMenu.displayTransMask(true,true);
}



function close_email(){
	  document.getElementById("transMask").onclick = null;
      document.getElementById('share_tipfriend').style.display = 'none';
      MenuMatic.aSubMenu.displayTransMask(false,true);
      share_legal_layer();
}

function onClickFavoriten(){
  var elem = document.getElementById('booklink');
  if(elem){
    if(elem.onclick)
      elem.onclick();
  }
}

/* Functions for each bookmark service */

/* addBookmark in the browser */

function addBookmark() {
  var url = encodeURIComponent(location.href);
  var title = ((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : "");
  if(window.sidebar){
    window.sidebar.addPanel(title,url,"");
  }
  else if(window.opera && window.print){
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
  } else if(document.all){
    if(window.external){
    alert('IE-Part: '+title+': '+url);
      window.external.AddFavorite(url,title);
    }  
  }
  document.getElementById('share_slide').style.display = 'none';
  document.getElementById('share').style.backgroundColor = '';
}

/*
	(C) 2007 Chuug. All rights reserved.
	twitthis.com
*/
var TwitThis = {
	pop : function () {
		window.open("http://twitthis.com/twit?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "TwitThisPop", "width=600, height=600, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Facebook */
var Facebook = {
	pop : function () {
		window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(location.href)+"&t="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "Facebook", "width=600, height=600, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for MySpace */
var MySpace = {
	pop : function () {
		window.open("http://www.myspace.com/Modules/PostTo/Pages/?u="+encodeURIComponent(location.href), "ptm", "width=440, height=450, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Google */
var Google = {
	pop : function () {
		window.open("http://www.google.com/bookmarks/mark?op=add&bkmk="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "Google", "width=750, height=700, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for del.icio.us */
var Delicious = {
	pop : function () {
		window.open("http://del.icio.us/post?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "Delicious", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Digg */
var Digg = {
	pop : function () {
		window.open("http://digg.com/submit?phase=2&url="+encodeURIComponent(location.href), "Digg", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Mister Wong */
var MisterWong = {
	pop : function () {
		window.open("http://mister-wong.de/index.php?action=addurl&bm_url="+encodeURIComponent(location.href)+"&bm_description="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "MisterWong", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Reddit */
var Reddit = {
	pop : function () {
		window.open("http://reddit.com/submit?url="+encodeURIComponent(location.href), "Reddit", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Stumble Upon */
var StumbleUpon = {
	pop : function () {
		window.open("http://www.stumbleupon.com/submit?url="+encodeURIComponent(location.href), "Stumble", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Windows Live */
var WindowsLive = {
	pop : function () {
		window.open("http://favorites.live.com/quickadd.aspx?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "MisterWong", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

/* JavaScript for Yahoo Buzz */
var YahooBuzz = {
	pop : function () {
	window.open("http://buzz.yahoo.com/buzz?publisherurn=Autostadt.de&targetUrl="+encodeURIComponent(location.href)+"&headline="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "MisterWong", "width=880, height=740, location, status, scrollbars, resizable");
    document.getElementById('share_legal').style.display = 'none';
    document.getElementById('share').style.backgroundColor = '';
	}
}

function clickCommandButton(linkId)
{
  document.getElementById('share_slide').style.display = 'block';
  document.getElementById('share_legal').style.display = 'none';
} 

