var flashversion = "9.0.0";
var flashplayerdivid = 'main';

if(typeof(swfobject)=='object' && swfobject.hasFlashPlayerVersion(flashversion)){
	//console.log(swfobject.getFlashPlayerVersion());
	
	var head = document.getElementsByTagName('head')[0];
	if(head){
		var flashstyle = document.createElement('style');
		var css = '#'+flashplayerdivid+' p {display: none}';

		flashstyle.setAttribute('type','text/css');
		
		if(head){
			if(flashstyle.styleSheet){//cause you can't put text in the webstandards way in ie
				flashstyle.styleSheet.cssText = css;
			}else{
				flashstyle.appendChild(document.createTextNode(css));
			}
			head.appendChild(flashstyle);
		}
	}
}


function openWindow ( url, windowname, options ) {
	if ( window.open ( url, windowname, options ) ) {
		return true;
	}
	return false;
}

function getUrlVars(){
	var varis = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
	hash = hashes[i].split('=');
	varis.push(hash[0]);
	varis[hash[0]] = hash[1];
	}
	return varis;
}
var vars = getUrlVars();
//alert("section="+vars['section']+"\n"+"gallery="+vars['gallery']+"\n"+"video="+vars['video']+"\n");


var flashvars = {
//	section: getQueryParamValue("section"),
	absoluteUrl: "http://www.d-9.com/communitywatch"
	};

if( vars['division'] ){flashvars.division=vars['division'];}
if( vars['call'] ){flashvars.call=vars['call'];}


var params = {
	allowFullScreen:'true',
	allowScriptAccess:'always',
	base:'media/',
	bgcolor:'#000000'
	};
var attributes = {id:flashplayerdivid};

swfobject.embedSWF("media/index.swf", flashplayerdivid, "965", "637", flashversion, "", flashvars, params, attributes);

/*
share.url = "http://www.District9Movie.com";
share.title = "District 9 | Official Movie Site and Trailer";
share.description = "Thirty years ago, aliens made first contact with Earth. Humans waited for the hostile attack, or the giant advances in technology. Neither came. Instead, the aliens were refugees, the last survivors of their home world. The creatures were set up in a makeshift home in South Africa's District 9 as the world's nations argued over what to do with them.<br />Now, patience over the alien situation has run out. Control over the aliens has been contracted out to Multi-National United (MNU), a private company uninterested in the aliens' welfare - they will receive tremendous profits if they can make the aliens' awesome weaponry work. So far, they have failed; activation of the weaponry requires alien DNA.<br />The tension between the aliens and the humans comes to a head when an MNU field operative, Wikus van der Merwe (Sharlto Copley), contracts a mysterious virus that begins changing his DNA. Wikus quickly becomes the most hunted man in the world, as well as the most valuable - he is the key to unlocking the secrets of alien technology. Ostracized and friendless, there is only one place left for him to hide: District 9.  Coming August 14!";
share.tweet = "Check out the official District 9 movie site and trailer!  http://www.District9Movie.com.";
share.delicious.description = "Check out the District 9 official site and trailer at http://www.district9movie.com.  District 9 is in theaters August 14.";

*/

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;
				
				if (url && title) {
					var link = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + escape(url) + '&t=' + escape(title);
				}
				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 configuration
share.url = "http://www.d-9.com/communitywatch";
share.title = "Multi-National United: Community Watch";
share.description = "Welcome to the Multi-National United Community Watch home page.  Click on hotspots on the map to hear non-human sightings in North America.  Report your own non-human sightings by calling 1-866-666-6001.  MNU - Keeping Humans Safe By Keeping Non-Humans Separate&trade;.";
share.tweet = "Check out the map for non-human sightings in North America and report your own non-human sightings.  http://D-9.com/CommunityWatch";
//share.delicious.description = "Check out the map for non-human sightings in North America and report your own non-human sightings.  http://D-9.com/CommunityWatch";

// Social bookmarking function
function sharethis() {
	var links = document.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;
			}
		}

		if( (link.getAttribute('rel') == 'external') ){
			link.setAttribute('target','_blank');
			/*
			link.onclick = function() {
				var parent = this.parentNode;
				if (typeof s == "object" && parent.parentNode.getAttribute('id')=='share') {
					var property = s.prop4.substring(s.prop4.lastIndexOf(':') + 1);
					if(console)
						console.log(parent.getAttribute('id'));
					sCode.trackOutboundClick(this.getAttribute('href'), property + '_' + parent.getAttribute('id') + '_link');
				}
			}
			*/
		}
	}
}

// Initializing functions on load
swfobject.addDomLoadEvent(sharethis);