  ///////////////////////
 // Overlay Functions //
///////////////////////

function showOverlay() {
	$('#overlay').css({ display: 'block', left: ($(window).width() - $('#overlay').width())/2, top: '121px' , position: 'absolute' });	
	$('#overlaybg').css({width: $(document).width(),height:$(document).height()});	
	$('#overlaybg').fadeIn('fast');	
	return false;
}

function showOverlayInternal() {
	if(document.getElementById('navigation')) {
		document.getElementById('navigation').disableNavigation();
	}
	$('#overlay').css({ display: 'block', left: ($(window).width() - $('#overlay').width())/2, top: $(window).scrollTop() + 150 + 'px', position: 'absolute' });			
	$('#overlaybg').css({width: $(window).width(),height: $(window).scrollTop() + $(document).height()});	
	$('#overlaybg').fadeIn('fast');	
	return false;
}

function overlayClose() {
	if(document.getElementById('navigation')) {
		document.getElementById('navigation').enableNavigation();
	}
	$('#overlay').css({display:'none'});		
	$('#overlaybg').fadeOut('fast');	
	return false;
}

function externalOverlay() {
	$('a[rel=externaloverlay]').click(function() {
		baseURL = 'http://www.sonywonder.com/parents/external.php?' + encodeURIComponent(this.href);
		window.open(baseURL);
		return false;
	});		
}

  /////////////////////////////////
 // Social Network Share object //
/////////////////////////////////

var share = {
	// required
	url: null,
	title: null,
	
	// optional
	description: null,
	
	// specific
	tweet: null,
	
	// custom settings
	delicious: {},
	digg: {},
	facebook: {},
	myspace: {},
	reddit: {},
	stumbleupon: {},
	twitter: {},

	
	send: function (site)
	{
		var url = null;
		switch (site) {
			case 'delicious':
				// check for custom settings
				var url = typeof this.delicious.url != 'undefined' ? this.delicious.url : this.url;
				var title = typeof this.delicious.title != 'undefined' ? this.delicious.title : this.title;
				var description = typeof this.delicious.description != 'undefined' ? this.delicious.description : this.description;
				
				if (url && title) {
					var link = 'http://delicious.com/save?url=' + escape(url) + '&title=' + escape(title) + '&notes=' + escape(description);
				}
				break;
			case 'digg':
				// check for custom settings
				var url = typeof this.digg.url != 'undefined' ? this.digg.url : this.url;
				var title = typeof this.digg.title != 'undefined' ? this.digg.title : this.title;

				if (url && title) {
					var link = 'http://digg.com/submit?phase=2&partner=[partner]&url=' + escape(url) + '&title=' + escape(title);
				}
				break;
			case 'facebook':
				// check for custom settings
				var url = typeof this.facebook.url != 'undefined' ? this.facebook.url : this.url;
				var title = typeof this.facebook.title != 'undefined' ? this.facebook.title : this.title;
				
				if (url) {
					var link = 'http://www.facebook.com/sharer.php?u=' + escape(url) + '&t=' + escape(title);
				}
				break;
			case 'myspace':
				// check for custom settings
				var url = typeof this.myspace.url != 'undefined' ? this.myspace.url : this.url;
				var title = typeof this.myspace.title != 'undefined' ? this.myspace.title : this.title;
				var description = typeof this.myspace.description != 'undefined' ? this.myspace.description : this.description;
				
				if (url && title) {
					var link = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + escape(url) + '&t=' + escape(title) + '&c=' + escape(description);
				}
				break;
			case 'reddit':
				// check for custom settings
				var url = typeof this.reddit.url != 'undefined' ? this.reddit.url : this.url;
				var title = typeof this.reddit.title != 'undefined' ? this.reddit.title : this.title;
				
				if (url && title) {
					var link = 'http://www.reddit.com/r/reddit.com/submit?url=' + escape(url) + '&title=' + escape(title);
				}
				break;
			case 'stumbleupon':
				// check for custom settings
				var url = typeof this.stumbleupon.url != 'undefined' ? this.stumbleupon.url : this.url;
				var title = typeof this.stumbleupon.title != 'undefined' ? this.stumbleupon.title : this.title;
				
				if (url && title) {
					var link = 'http://www.stumbleupon.com/submit?url=' + escape(url) + '&title=' + escape(title);
				}
				break;
			case 'twitter':
				var tweet = this.tweet;
				
				if (tweet) {
					var link = 'http://twitter.com/home?status=' + escape(tweet);
				}
				break;
		}

		if (typeof s == "object") {
			var property = s.prop4.substring(s.prop4.lastIndexOf(':') + 1);
			sCode.trackOutboundClick(link, property + '_' + site + '_button');
		}
		
		if (link) window.open(link);
	}
	
};

share.url = "http://www.sonywonder.com";
share.title = "SonyWonder.com - Family Entertainment from Sony Pictures";
share.description = "Sony Wonder is your Sony Pictures Family Entertainment Destination for Games, Activities and Sweepstakes starring your favorite Movie Characters.";
share.tweet = "I just visited http://SonyWonder.com - tons of fun for the whole family!";
share.delicious.description = "Sony Wonder is your Sony Pictures Family Entertainment Destination for Games, Activities and Sweepstakes starring your favorite Movie Characters.";

// Social bookmarking function

function shareThis() {
	var links = document.getElementById('share').getElementsByTagName('a');
	for (i=0; i<links.length; i++) {
		var link = links[i];
		if( (link.getAttribute('rel') == 'facebook') || (link.getAttribute('rel') == 'myspace') || (link.getAttribute('rel') == 'twitter') || (link.getAttribute('rel') == 'delicious') || (link.getAttribute('rel') == 'digg') || (link.getAttribute('rel') == 'stumbleupon'))
		{
			link.onclick= function() {
				share.send(this.getAttribute('rel'));		
				return false;
			}
		}
	}
}

// Popup function
function popup(url,windowtype) {
	var newwindow = window.open(url,windowtype);
	if (!newwindow) {		
			document.getElementById('navigation').flashPopup(url,windowtype);
	}
}

$(document).ready(function() {
	shareThis();
	externalOverlay();
});