
var meta_shadow_color="#eeeeee";

/* Add Event to Create Sharing Popup DIV */
if (window.addEventListener) {window.addEventListener("load",attachDIV,false);}
  else if (window.attachEvent) {window.attachEvent("onload",attachDIV);}

/* Creates the Sharing Popup DIV */
function attachDIV ()
{
	/* DIV Object */
	var b;
	var d=document;
	
	b = document.createElement("div");
	b.setAttribute("id","g-bookmarkpopup");
	b.style.display = "none";
	b.style.position = "absolute";
	b.style.backgroundColor = "#ffffff";


	d.getElementsByTagName("body")[0].appendChild(b);
}

/* Show Sharing Popup */
function metaShowPopUp(btnObj,gvTitle,gvURL,gvCategory,gvDescription)
{
	var metaPartnerId='';
	if (typeof(meta_partner_id)!='undefined')
		{metaPartnerId=meta_partner_id;}
	else
		{meta_hide_advert=1;} // hide if no partner id

	 /* Defaults */
	var metapId = metaPartnerId;
	var metaUrl= document.location.href;
	var metaTitle= document.title;
	var metaCategory = "All";
	var metaDescription = "";

	if (typeof(meta_hide_advert)=='undefined')
		{meta_hide_advert=0;}
	if (typeof(meta_hide_clip)=='undefined')
		{meta_hide_clip=0;}
	if (typeof(meta_hide_social)=='undefined')
		{meta_hide_social=0;}
		
	
	/* Customize Colors */
	var gModBoxStyle1="";
	var gModBoxStyle2="";
	if (typeof(meta_border_color)!='undefined')
	{
		gModBoxStyle1 +='border:1px solid '+ meta_border_color+';';

		
		gModBoxStyle2 +='border-left:1px solid '+ meta_border_color+';';
		gModBoxStyle2 +='border-right:1px solid '+ meta_border_color+';';		
		
	}
	gModBoxStyle3 = gModBoxStyle1;
	
	var gModBoxStyle="";
	if (typeof(meta_shadow_color)!='undefined')
		{gModBoxStyle +='border:4px solid '+ meta_shadow_color;}
		
	if (typeof(meta_banner_color)!='undefined')
		{gModBoxStyle1 +='background-color:'+ meta_banner_color+';';}
		
	
	/* From Email Address */
	if (typeof(meta_from)=='undefined')
		{meta_from="";}

	if (typeof(gvTitle)!='undefined')
		{metaTitle=gvTitle;}
	if (typeof(gvURL)!='undefined')
		{metaUrl=gvURL;}
	if (typeof(gvCategory)!='undefined')
		{metaCategory=gvCategory;}
	if (typeof(gvDescription)!='undefined')
		{metaDescription=gvDescription;}
	// Defend, defend, defend....This is all incorrect
	// should build the form and assign the value then add from to DIV	
	metaDescription = metaDescription.replace(/'/g,'`');
	metaDescription = metaDescription.replace(/&#39;/g,'`');
	metaDescription = metaDescription.replace(/"/g,'&#8221;');
	metaDescription = metaDescription.replace(/&quot;/g,'&#8221;');
	metaDescription = metaDescription.replace(/& /g,'&amp; ');
	metaTitle = metaTitle.replace(/'/g,'`');
	metaTitle = metaTitle.replace(/&#39;/g,'`');
	metaTitle = metaTitle.replace(/"/g,'&#8221;');
	metaTitle = metaTitle.replace(/&quot;/g,'&#8221;');
	metaTitle = metaTitle.replace(/& /g,'&amp; ');
		
	/* Categories is always "All" unless: meta_allow_cats=1 */
	if (typeof(meta_allow_cats)=='undefined')
		{meta_allow_cats=0;}
	if (meta_allow_cats!=1)
		{metaCategory = "All";}		
	if (document.location.href!=metaUrl)
		{meta_hide_clip=1;} // Hide Clip if multiple buttons on a page
 
 
 /* If Open then Close */
 /*
if (ismetaWindowOpen())
{
	closemetaWindow();
}
*/

/* Move Popup DIV right below the button that clicked it */
if (typeof(btnObj)!='undefined')
{
	var metax = findPosX(btnObj);
	var metay = findPosY(btnObj);
	
	/* Fixes problem with window going off the screen */
	if ((getWindowWidth()-metax)<350)
		{metax = getWindowWidth()-370;}
	
	setPosition ("g-bookmarkpopup",metax,metay+30);
} else
{
	// Check to see if popup DIV failed to be created..probably being called by favlet
	if(!document.getElementById("g-bookmarkpopup"))
		{attachDIV();}	
	var sy = getScreenTop();
	setPosition ("g-bookmarkpopup",100,sy-550);
	
}
  
  
 //alert (getCookie("WT_FPC"));
 
 
 
/* Module Start */
var HTMLstr= '';
HTMLstr   +='<div id="g-mod-div" style="float: left; z-index:2147483640; width:350px" align="left">';
HTMLstr   +='<table class="g-mod-box" cellpadding="0" cellspacing="0" width="350" style="'+gModBoxStyle+'">';
HTMLstr   +='<tr><th class="g-mod-box-th" style="'+gModBoxStyle1+'"><div class="g-mod-left">Share This!</div><ul class="g-mod-toolbar">';
HTMLstr   +='<li class="g-mod-t-ico" onclick="closemetaWindow();"><div class="g-mod-ico-close"></div></li></ul></th></tr>';
HTMLstr   +='<tr><td class="g-mod-box-td g-mod-nopadding" style="'+gModBoxStyle2+'"><ul class="g-mod-tab-bar">';

/* Tabs */
HTMLstr   +='<li class="g-mod-tab-active" onclick="gChangeTab(\'1\');" id="g-tab-1"><a>Email Article</a></li>';

if (meta_hide_clip!=1) 
	{HTMLstr   +='<li onclick=""><a>Email Clip</a></li>';}
	
if (meta_hide_social!=1) 	
	{HTMLstr   +='<li onclick="gChangeTab(\'2\');" id="g-tab-2"><a>Social Media</a></li>';}

HTMLstr   +='</ul></td></tr>';
HTMLstr   +='<tr><td class="g-mod-box-td g-mod-text" style="background-color:#ffffff;'+gModBoxStyle3+'border-top:0px">';


/* Email Article */
HTMLstr +='<div id="meta-body-1" align="left"><div class="meta-email" align="left">';
HTMLstr +='<form action="http://www.maevona.com/includes/js/mshare/email.php"  method="get" target="mailFrame" accept-charset="utf-8">';
HTMLstr +='<div class="meta-label">To Address:</div><input id="meta_to" type="text" name="to" value="" class="meta-text" />';
HTMLstr +='<div class="meta-note">Seperate multiple email addresses using a comma</div><div class="meta-space"></div>';
HTMLstr +='<div class="meta-label">Your Address:</div><input id="meta_from" type="text" name="from" value="'+meta_from+'" class="meta-text" /><div class="meta-space"></div>';
HTMLstr +='<div class="meta-label">Message:</div><textarea name="msg" class="meta-textarea">Check this out..</textarea><div class="meta-space"></div><input type="submit" class="meta-submit" name="meta_submit" value="Send It" onclick="closemetaWindow();"/>';
HTMLstr +='<input type="hidden"  name="meta_action" value="send_mail" /><input type="hidden"  name="meta_post_id" id="meta_post_id" value="" />';					
HTMLstr +='<input type="hidden"  name="pId" value="'+metapId+'" id="meta_pid"/><input type="hidden"  name="title" id="metafrm_title" value="'+metaTitle+'" />';
HTMLstr +='<input type="hidden"  name="subject" id="metafrm_subject" value="" /><input type="hidden" name="ctg" value="'+metaCategory+'" />';
HTMLstr +='<input type="hidden"  name="url" id="metafrm_url" value="'+metaUrl+'" /><input type="hidden"  name="description" value="'+metaDescription+'" />';
HTMLstr +='</form><iframe src="" id="mailFrame" name="mailFrame" style="height:1px;width:1px" width="1" height="1" frameborder=0></iframe>';
HTMLstr +='</div></div>';

/* Social Media */
HTMLstr +='<div id="meta-body-2" align="left" style="display:none">';
HTMLstr +='<div class="meta-social" align="left"><ul><li><a  href="http://twitter.com/home?status='+encodeURIComponent(metaTitle)+' '+metaUrl+'" onclick="metaCall(\'Twitter\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_twitter" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/twitter.gif"/>&nbsp;Twitter</a></li>';
HTMLstr +='<li><a  href="http://www.google.com/bookmarks/mark?op=edit&bkmk='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'GoogleBookmarks\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_google_bmarks" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/google_bmarks.gif"/>&nbsp;Google Bookmarks</a></li>';
HTMLstr +='<li><a  href="http://www.facebook.com/share.php?u='+encodeURIComponent(metaUrl)+'&t='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'FaceBook\',\''+metaUrl+'\',\''+metaTitle.replace("'", "\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_facebook" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/facebook.gif"/>&nbsp;Facebook</a></li>';
HTMLstr +='<li><a  href="https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-usurl='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'&top=1" onclick="metaCall(\'WindowsLive\',\''+metaUrl+'\',\''+metaTitle.replace("'", "\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_windows_live" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/windows_live.gif"/>&nbsp;Windows Live</a></li>';
HTMLstr +='<li><a  href="http://del.icio.us/post?url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Delicious\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_delicious" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/delicious.gif"/>&nbsp;del.icio.us</a></li>';
HTMLstr +='<li><a  href="http://digg.com/submit?phase=2&url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Digg\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_digg" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/digg.gif"/>&nbsp;Digg</a></li>';
HTMLstr +='<li><a  href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+encodeURIComponent(metaUrl)+'&t='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'YahooWeb\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_yahoo_myweb" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/yahoo_myweb.gif"/>&nbsp;Yahoo! My Web</a></li>';
HTMLstr +='<li><a  href="http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Ask\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_ask" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/ask.gif"/>&nbsp;Ask</a></li>';
HTMLstr +='<li><a  href="http://furl.net/storeIt.jsp?u='+encodeURIComponent(metaUrl)+'&t='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Furl\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_furl" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/furl.gif"/>&nbsp;Furl</a></li>';
HTMLstr +='<li><a  href="http://www.stumbleupon.com/submit?url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'StumbleUpon\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_stumbleupon" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/stumbleupon.gif"/>&nbsp;StumbleUpon</a></li>';
HTMLstr +='<li><a  href="http://reddit.com/submit?url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Reddit\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_reddit" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/reddit.gif"/>&nbsp;reddit</a></li>';
HTMLstr +='<li><a  href="http://www.technorati.com/faves?add='+encodeURIComponent(metaUrl)+'" onclick="metaCall(\'Technocrati\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_technorati" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/technorati.gif"/>&nbsp;Technorati</a></li>';
HTMLstr +='<li><a  href="http://blinklist.com/index.php?Action=Blink/addblink.php&Url='+encodeURIComponent(metaUrl)+'&Title='+encodeURIComponent(metaTitle)+'"onclick="metaCall(\'BlinkList\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_blinklist" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/blinklist.gif"/>&nbsp;BlinkList</a></li>';
HTMLstr +='<li><a  href="http://www.newsvine.com/_wine/save?u='+encodeURIComponent(metaUrl)+'&h='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'NewsVine\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_newsvine" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/newsvine.gif"/>&nbsp;Newsvine</a></li>';
HTMLstr +='<li><a  href="http://ma.gnolia.com/bookmarklet/add?url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'Magnolia\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_magnolia" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/magnolia.gif"/>&nbsp;ma.gnolia</a></li>';
HTMLstr +='<li><a  href="http://tailrank.com/share/?link_href=url='+encodeURIComponent(metaUrl)+'&title='+encodeURIComponent(metaTitle)+'" onclick="metaCall(\'TailRank\',\''+metaUrl+'\',\''+metaTitle.replace("'","\\\'")+'\',\''+metapId+'\',\''+encodeURIComponent(metaCategory)+'\');" id="meta_tailrank" target="_blank"><img align="absmiddle" src="http://www.maevona.com/includes/js/mshare/images/tailrank.gif"/>&nbsp;Tailrank</a></li>';
HTMLstr +='</ul><div class="clear"></div></div>';
HTMLstr +='</div>';


/* Statcounter Image */
//HTMLstr +='<img width="1" height="1" style="display:none" src="http://c42.statcounter.com/3580567/0/a78783c0/1/"/>';

/* Module End */
HTMLstr +='</td></tr></table>';
HTMLstr +='</div>';


/* Set Contents of Popup */
var bookmarkpopup= document.getElementById('g-bookmarkpopup');
bookmarkpopup.innerHTML =HTMLstr;
bookmarkpopup.style.display='block';

/* Display Popup DIV's Contents */
var gModDiv = document.getElementById('g-mod-div');
gModDiv.style.display='block';

}


/* -------------------- */
/* 	OTHER FUNCTIONS 	*/
/* -------------------- */


/* Close Window */
function closemetaWindow()
{
	popupwin =document.getElementById('g-bookmarkpopup');
	popupwin.style.display='none';
}

/* Checks to see if the Popup is open */
function ismetaWindowOpen ()
{
	var popupwin =document.getElementById('g-bookmarkpopup');
	var isOpen = false;
	if (popupwin.style.display=='block')
		{isOpen = true;}
	return (isOpen);
}


/* Change Tabs in the Popup */
function gChangeTab(tab)
{
	var tab1 = document.getElementById('g-tab-1');
	var tab2 = document.getElementById('g-tab-2');

	var body1 = document.getElementById('meta-body-1'); //meta-email
	var body2 = document.getElementById('meta-body-2'); //meta-social
	
	switch (tab) {
		case '1':
			tab2.className = '';
			tab1.className = 'g-mod-tab-active';
			body2.style.display = 'none';
			body1.style.display = 'block';
			break;
		case '2':
			tab1.className = '';
			tab2.className = 'g-mod-tab-active';
			body1.style.display = 'none';
			body2.style.display = 'block';
			break;
	}
}

/* Pings when a Social Bookmark is Clicked */
function metaCall(bmark,url,title,metapId,gtCat)
{
	if(metapId!='')
		{
			/*
			var gfurl = "http://www.widgetmatic.com/tracker.php?pId="+encodeURIComponent(metapId)+"&url="+encodeURIComponent(url)+"&title="+encodeURIComponent(title)+"&sName="+encodeURIComponent(unescape(bmark))+"&aCatId="+gtCat;
			var metaIFrame = document.createElement('div');
			var iframeInnerHTML='<iframe src="'+gfurl+'" height="1" width="1" style="display:none;">';
			metaIFrame.innerHTML=iframeInnerHTML;
			document.body.appendChild(metaIFrame);
			*/
		}
		
		closemetaWindow();
}

/* Returns Cookie */
function getCookie(name)
{
	var cookies = document.cookie;

	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) {endpos = cookies.length;}
		return unescape(cookies.substring(startpos,endpos));
	} else
	{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}

}

/* Find X Position of an Object */
function findPosX(obj)
{
 var curleft = 0;
 if(obj.offsetParent) {
	  while(1) 
	  {
		 curleft += obj.offsetLeft;
		 if(!obj.offsetParent)
			{break;}
		 obj = obj.offsetParent;
	  }
} else if(obj.x) {
	  curleft += obj.x; }
 return curleft;
}

/* Find Y Position of an Object */
function findPosY(obj)
{
 var curtop = 0;
 if(obj.offsetParent) {
	  while(1)
	  {
		 curtop += obj.offsetTop;
		 if(!obj.offsetParent) {
			break;}
		 obj = obj.offsetParent;
	  }
} else if(obj.y) {
	  curtop += obj.y;}
 return curtop;
}

/* Set the Position of an Object */
function setPosition (objName,x,y)
{
	var obj = document.getElementById(objName);
	obj.style.left = x + "px";
	obj.style.top = y + "px";
}

/* Get the Browser Height */
function getWindowHeight ()
{
  var winH=480;
  if (parseInt(navigator.appVersion)>3)
  {
		if (navigator.appName=="Netscape") 
		{
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winH = document.body.offsetHeight;
		}
	}
	return winH;
}

/* Get the Browser Width */
function getWindowWidth ()
{
	var winW=640;
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape") 
		{
			winW = window.innerWidth;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth;
		}
	}
	return winW;
}

function metaSetFromEmail(email)
{
	var obj = document.getElementById("meta_from");
	obj.value=email;
}



function getScreenTop()
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var pY;
	pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	return (pY);
}
