/*---------------------------------------------------------------------------
 * Social network + bookmarking tools
 * Copyright 2009 Mark. Sydney :: www.marksydney.com :: All Rights Reserved *
 	                          __             
	 /'\_/`\                 /\ \            
	/\      \    __      _ __\ \ \/'\        
	\ \ \__\ \  /'__`\  /\`'__\ \ , <       
	 \ \ \_/\ \/\ \L\.\_\ \ \/ \ \ \\`\   __ 
	  \ \_\\ \_\ \__/.\_\\ \_\  \ \_\ \_\/\_\
	   \/_/ \/_/\/__/\/_/ \/_/   \/_/\/_/\/_/

 * Author: Gilmore Davidson
 * Project: 'yes' SESSIONS
 * Written: February 2009
---------------------------------------------------------------------------*/

var social = (function(){
	var windowName = Math.random(1000).toString().slice(3);
	
	var getDetails = function() {
		var url = $("#fullLink").attr('href');
		var img = $("#slideShow img")[0];
		var l = document.location;
		return {
			src: img.src,
			url: (url == '') ? l.href : l.protocol + '//' + l.host + url,
			alt: img.alt
		}
	}
	
	var openWindow = function(url, name, width, height) {
		if (typeof url == 'string') {
			url = {
				win: url,
				loc: url
			}
		}
		name += '_'+windowName;
		var w = window.open(url.win, name, 'toolbar=0,status=0,resizable=1,location=0,width='+width+',height='+height);
		if (w) {
			try {
				var wx = screen.width / 2 - width / 2;
				var wy = screen.height / 2 - height / 2;
				w.moveTo(wx, wy);
			} catch (e) {}
		} else {
			location.href = url.loc;
		}
	}
	
	var d = document,
		l = location,
		e = encodeURIComponent;
	
	return {
		post: {
			facebook: function() {
				var i = getDetails(),
					f = 'http://www.facebook.com/share',
					p = '.php?src=bm&v=4&i=1233201315&u='+e(i.url)+'&t='+e(d.title),
					u = {
						win: f+'r'+p,
						loc: f+p
					};
				openWindow(u, 'facebook', 626, 436);
			},
			myspace: function() {
				var i = getDetails(),
					u = 'http://www.myspace.com/Modules/PostTo/Pages/?u='+e(i.url)+'&t='+e(document.title)+'&c='+e('<img src="'+i.src+'" alt="'+i.alt+'" />');
				openWindow(u, 'myspace', 800, 740);
			},
			twitter: function(filePath) {
				var i = getDetails(),
					u = filePath+'/gallery/twitter/?u='+e(i.url);
				openWindow(u, 'twitter', 500, 380);
			}
		}
	}
})();
