// -----------------------------------------------------------------------------
// http://gallery.worldsware.com/gallery.js
//

var about = null, page, photo, caption;

// -----------------------------------------------------------------------------
//

function removed()
{
	// thick box is removing a popup image
	//
	$("#swfobject").css( { visibility: "visible" } );
}

function showPhoto()
{
	// thickbox a photo's image
	//
	$("#swfobject").css( { visibility: "hidden" } );
	tb_show(caption, photo, false);
}

function showURL(caption, url, w, h)
{
	$("#swfobject").css( { visibility: "hidden" } );
	w = w || pageSize().width - 150;
	h = h || pageSize().height - 150;
	tb_show(caption, url + "?TB_iframe=true&height=" + h + "&width=" + w, false);
}

function showPage()
{
	// thickbox a photo's page
	//
	showURL(caption, page);
}

function showAbout()
{
	showURL("About Flickr Gallery", "about.html", 560, 520);
}

function showControls()
{
	showURL("Navigation Controls", "controls.html", 220, 320);
}

function showStores()
{
	showURL("Our Stores", "/stores.html", 510, 440);
}

function goto(store, shop)
{
	tb_remove();
	var url = "/" + store;
	if (shop) url += "?s=" + shop;
	window.location = url;
}


// -----------------------------------------------------------------------------
// Functions called by SWF
//
function trace(args)
{
	// called by SWF to show activity
	//
	$('#trace').append(">>> " + args + "<br />");
}

function track(name)
{
	$("#music").attr("title", "now playing: Dreams for the sleepless - " + name);
}

function progress(msg)
{
	if (!about) $('#caption').html(msg + ", please wait...");
}

function ready()
{
	// the gallery is ready (loaded)
	//
	about = "<a href='javascript:showAbout()'>About Flickr Gallery</a> | <a href='javascript:showStores()'>Visit our Stores</a> | <a href='javascript:showControls()'>Controls</a>";
			"" + 

	$('#caption').html("Welcome to Flickr Gallery");
	$('#extra').html("Click <a href='javascript:showControls()'>Controls</a> to learn how to get around...");
	$('#links').html(about);
}

function info(args)
{
	// user's focus changed; deal with that
	//
	// args.title, args.author, args.date - caption stuff
	// args.photo - photo url
	// args.page - photo page url
	// args.info - array of more info - fields are: ... id | secret | server | farm | owner | title | name | date | lat | lng
	//
	
	// about is set after the gallery is fully loaded, don't do the following before that
	//
	if (!about) return;

	var info = args.info;
	if (!info)
	{
		ready();
		return;
	}

	// get these into globals
	caption = args.title + " by " + args.author;	// caption for any thickboxes
	page = args.page;
	photo = args.photo;
	var geo = args.geo;

	// urls
	var link = " | <a href='javascript:showPage()'>Show photo page</a>";
	var popup = " | <a href='javascript:showPhoto()'>Show photo</a>";
	if (geo != "") geo = " | <a target='new' href='" + geo + "'>Show on map</a>";

	// title, author from args (not using date)
	$('#caption').html(args.title);
	$('#extra').html("by " + args.author);
	$('#links').html(about + link + popup + geo);

	//if (args.dblclick) showPhoto();
}

// -----------------------------------------------------------------------------
// Other stuff
//
function gup(name, def)
{
	// Get url parameter from querystring
	//
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	return results ? results[1] : "";
}

function pageSize()
{
	var size = { width: 0, height: 0 };
	if (typeof ( window.innerWidth ) == 'number') {
		//Non-IE
		size.width = window.innerWidth;
		size.height = window.innerHeight;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		size.width = document.documentElement.clientWidth;
		size.height = document.documentElement.clientHeight;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		size.width = document.body.clientWidth;
		size.height = document.body.clientHeight;
	}
	return size;
}

//------ ADD THIS stuff

var addthis_url = '';
var addthis_title = '';
var addthis_pub = 'dr3d';

function addthis_click(obj, str)
{
	var aturl  = 'http://www.addthis.com/bookmark.php';
	aturl += '?v=10';
	aturl += '&pub=' + addthis_pub;
	aturl += '&url=' + encodeURIComponent(addthis_url);
	aturl += '&title=' + encodeURIComponent(addthis_title);
	window.open(aturl,'addthis','scrollbars=yes,menubar=no,width=620,height=540,resizable=yes,toolbar=yes,location=yes,status=no,screenX=200,screenY=100,left=200,top=100');
	return false;
}
