/*
<html>
<h1>dan's photo viewer : script tag gallery loader</h1>

<h2>makes a gallery in an exsiting page via a simple script tag.</h2>



<script type='text/javascript'>


*/
	
/*
	two formats: 
	1. a simple list of urls
	2. JSON: gallery settings in object named settings, images in array named "imgs"



script strategy:


-figure out if it's a list or JSON.
-if list, assume a 600X400 px iframe embed.
*/




function K(a){return a;}
function el(tid) {return document.getElementById(tid);}
function tags(elm) {return obValsl(document.getElementsByTagName(elm));}
function obValsl(ob) {var r = [], i = 0, mx = ob.length;for (var z = 0; z < mx; z++) {r[z] = ob[z] || undefined;} return r;};

if (!Array.prototype.map) {// from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:map
Array.prototype.map = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array(len);var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {res[i] = fun.call(thisp, this[i], i, this);}}return res;};}
if (!Array.prototype.filter) { //from  http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter
Array.prototype.filter = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array;var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {var val = this[i];if (fun.call(thisp, val, i, this)) {res.push(val);}}}return res;};}

function doPhotoParse(){
	var scriptTag = tags("script");
	scriptTag  = scriptTag[ scriptTag.length -1];
	var txt = scriptTag.text || scriptTag.textContent || scriptTag.innerText;
	if(!txt){return;}
	var listMode = ! txt.match(/imgs\s*\=\s*\[/);
	var addy = "";
	var base = "http://danml.com/pub/photos.htm?";
	function gs(s){ return scriptTag.getAttribute(s) || undefined }
	var settings = "";


if(listMode){
	var r = txt.split(/\r?\n/).filter(K);
	addy = settings + base + "imgs=['"+ r.join("','") +"']"

}else { //json mode
	alert("feature not implemented.")
}

var I= document.createElement("iframe");
	I.width = gs("width") || 600;
	I.height = gs("height") ||  400;
	I.src = addy;
	I.setAttribute("frameborder", 0);
  scriptTag.parentNode.insertBefore(I, scriptTag);





}//end doPhotoParse
doPhotoParse();



/*  </script>	


*/

//</html>	