/*
 * Engr Social Icons
 * engrsocial.js
 */
($(document).ready(function(){
	jQuery.fn.exists = function(){return jQuery(this).length>0;}

	if ($('#engrsocialicons').exists()) {
		(function() {
			var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		})();
		(function() {
			var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
			s.type = 'text/javascript';
			s.async = true;
			s.src = 'http://widgets.digg.com/buttons.js';
			s1.parentNode.insertBefore(s, s1);
		})();
		(function() {
			$.fn.center = function () {
				this.css("position","absolute");
				this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
				this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
				return this;
			}
		})();
		(function() { 
			$.extend($.ui.dialog.defaults, {
				overlay : { background: "#000", opacity: 0.6},
				modal: true,
				bgiframe: true
			});
		})(); 
		$("#engrsocialicons a").addClass( 'with-js' );
		//this might allow tracking the links as outlinks in piwik
		$("#engrsocialicons a").addClass( 'piwik_link' );
		$("body:first").append('<div id="dialog"><div class="messagepop" id="popcontent"></div></div>');
		$("#dialog").dialog({
			autoOpen: false,
			height: 350,
			width: 450,
			open: function() {
				$('.ui-dialog').css({padding: '0', background: '#fff', border: '4px solid #999999'});
				$('.ui-dialog-titlebar').css({backgroundColor:'#b9b9b9', height: '30px'});
				$('.ui-dialog-titlebar-close').css({ position: 'absolute', right: '15px', top:'10px', backgroundImage:'url(/javascript/jquery.ui/themes/smoothness/images/ui-icons_2e83ff_256x240.png)', backgroundRepeat:'none', backgroundPosition:'-34px -194px', width:'13px', height:'13px' });
				$('.ui-dialog .ui-dialog-titlebar-close').html('');
				$('.ui-dialog').center();
			}
		});
					
		$(".email a").click(function() {
			var path = this.href.replace('#','');
			$('#popcontent').load(path);
			$('#dialog').dialog("open");
			return false;
		});
		
		$(".stumble a").click(function() {
			var pop = window.open(this.href,'pop','width=600,height=500,resizable,scrollbars');
			pop.focus();
			return false;
		});
		
		$(".digg a").click(function() {
			var pop = window.open(this.href,'pop','width=475,height=500,resizable,scrollbars');
			pop.focus();
			return false;
		});
	
	}//end if social icons exist

}));//end document ready
