

if(typeof Wishpot == "undefined") {

var Wishpot = { BM : {

Style : "",
ContentRoot : "https://www.wishpot.com",
LibWaitCode : null,
LibWaitCount : 0,
LibLoadIssued : 0,
Dialog : null,
DomainEuropeRegex : new RegExp(/\.[a-z]{2,3}\.[a-z]{2}$/i), //.co.uk, etc
DomainUSRegex: new RegExp(/\.[a-z]{2,4}$/i), //.com, .net, etc
_DomainNoPrefix : "",
_LeadImage : null,
_PostFormWaitCode : null,
_PostFormWaitCount : 0,
_JqueryVersion : "1.3.2",
_JqueryUIVersion : "1.7.0",
_DebugEnabled: false,
_StyleSheetPath : null,

Root : function()
{
    return this.CurrentProtocol()+"www.wishpot.com";
},

CurrentProtocol : function()
{
    return (("https:" == document.location.protocol) ? "https://" : "http://");
},

StyleSheetPath : function()
{
  if(null != this._StyleSheetPath) return this._StyleSheetPath;
  this._StyleSheetPath = this.Root()+"/js/jquery/ui.theme.css";
  return this._StyleSheetPath;
},

OnButtonPressed : function()
{
	if(this.IsFrameContainer())
	{
		this.ShowFailure("Frames detected, and not yet supported.");
		//this.RestartInFrame();
		return;
	}

	this.LoadLibs();

	if(this.CheckLibsLoaded() === true)
	{        
		this.ClearWait();
		this.Run();    
	}    
	else
	{
		this.ClearWait();
		this.LibWaitCode = window.setInterval(this.RunWhenReady, 500);
	}
},

Debug : function(msg, consoleOnly)
{
  if(this._DebugEnabled)
  {
    if(typeof(window) != "undefined" && window.opera) { window.opera.postError(msg); }
    else if(typeof(console) != "undefined" && console.log) { console.log(msg); }
    else if(!consoleOnly){ window.alert(msg); }
  }
},

StripDomainPrefix : function(domainName){
     var domainNoPrefix = domainName;
     var domainPartsArr = domainNoPrefix.split(".");

     if(  (domainNoPrefix.match(this.DomainEuropeRegex) && (domainPartsArr.length  == 4))
       || (domainNoPrefix.match(this.DomainUSRegex) && (domainPartsArr.length == 3))   ){
        domainPartsArr.shift(); //knocks off the first element
	   domainNoPrefix = domainPartsArr.join(".");
	}
    return domainNoPrefix;
},

DomainNoPrefix : function(){
    if (this._DomainNoPrefix != ""){ return this._DomainNoPrefix; }
    this._DomainNoPrefix = this.StripDomainPrefix(this.GetLargestWindow().document.domain);
    return this._DomainNoPrefix;
},

//Forces the loading of the lead image so we can grab it's dimensions
SetLeadImageDimensions : function(imageUrl)
{
  this._LeadImage = new Image();
  this._LeadImage.onload = Wishpot.BM.UpdateLeadImageDimensions;
  this._LeadImage.src = imageUrl;
},

LeadImageLoaded : function()
{
  return (null != this._LeadImage && null != this._LeadImage.height && this._LeadImage.height > 0);
},

UpdateLeadImageDimensions : function ()
{
  //no need to do anything
  Wishpot.BM.Debug("Lead Image onload callback fired.");
},

RestartInFrame : function()
{
	var w = this.GetLargestFrame();
	if(w == null){ return; }

	var doc = w.document;
	this.AddToHead(this.Root()+"/scripts/bm.js", "script", "text/javascript", doc);
},

IsFrameContainer : function()
{
	var w = window;	
	var bodies = w.document.getElementsByTagName('body');	
	return (w.frames.length > 0 && bodies.length <= 0);
},

GetLargestWindow : function()
{
  var targetWin = window;
  if (this.IsFrameContainer()) { targetWin = this.GetLargestFrame();}
  return targetWin;
}, 

GetLargestFrame : function()
{    
	var maxArea = 0;	   
	var maxFrame = null;	   
	for(var i=0; i < window.frames.length; i++)
	{	       
		try
		{
			var doc = this.GetFrameDoc(window.frames[i]);
			var ar = this.GetWindowArea(window.frames[i]);	       
			if(ar >= maxArea)
			{	           
				maxArea = ar;	           
				maxFrame = window.frames[i];	       
			}	   
		}
		catch(e)
		{}
	}	   
	return maxFrame;
},

GetFrameDoc : function(f)
{
	var doc = (f.contentWindow || f.contentDocument);
  	if(f.document) 
  		doc = doc.document;
  	return doc;
},

LoadLibs : function()
{	
    var jsSuffix = (this._DebugEnabled) ? "" : ".min";
	if(this.LibLoadIssued == 0)
	{
		this.LibLoadIssued = 1;
		var root = this.Root();
		//Add CSS first so styling is right
        this.AddToHead(this.StyleSheetPath(), "link", "text/css");
		this.AddToHead(this.CurrentProtocol()+"ajax.googleapis.com/ajax/libs/jquery/"+Wishpot.BM._JqueryVersion+"/jquery"+jsSuffix+".js", "script", "text/javascript");
	}
	if(this.CheckJqueryVersion() && this.LibLoadIssued < 2)
     {
        Wishpot.BM.Debug("Adding jquery ui to head...");
        this.AddToHead(this.CurrentProtocol()+"ajax.googleapis.com/ajax/libs/jqueryui/"+Wishpot.BM._JqueryUIVersion+"/jquery-ui"+jsSuffix+".js", "script", "text/javascript");
        this.LibLoadIssued = 2;
     }

	return true;	
},

AddToHead : function(objSrc, objType, objMimeType, doc)
{	
	if(doc == null) { doc = document; }
	if(doc.getElementById(objSrc) != null){ return; }
	
	var s;	
	try{ s = doc.standardCreateElement(objType); }
	catch(e) { }	

	try
	{	    
		if(typeof(s)!="object"){ s=doc.createElement(objType); }
		    
		if(objType == "link")
		{			
			s.href=objSrc;			
			s.rel="stylesheet";		
		}
		else if(objType == "script")
		{			
			s.src=objSrc;		
		}		

		s.setAttribute('id', objSrc);
		if(objMimeType)
			s.type=objMimeType;		

		doc.getElementsByTagName('head')[0].appendChild(s);	

	}	
	catch(e)
	{	   
	    Wishpot.BM.Debug("Problem adding object to head: "+e); 
		return false;	
	}
},

GetWindowArea : function(aWindow)
{  
	var myWidth = 0, myHeight = 0;  
	if(typeof( aWindow.innerWidth ) == 'number') 
	{    
		//Non-IE    
		myWidth = aWindow.innerWidth;    
		myHeight = aWindow.innerHeight;  
	} 
	else if(aWindow.document.documentElement && 
		(aWindow.document.documentElement.clientWidth || aWindow.document.documentElement.clientHeight)) 
	{    
		//IE 6+ in 'standards compliant mode'    
		myWidth = aWindow.document.documentElement.clientWidth;    
		myHeight = aWindow.document.documentElement.clientHeight;  
	} 
	else if(aWindow.document.body && 
		(aWindow.document.body.clientWidth || aWindow.document.body.clientHeight)) 
	{    
		//IE 4 compatible    
		myWidth = aWindow.document.body.clientWidth;    
		myHeight = aWindow.document.body.clientHeight;  
	}  
	return myWidth*myHeight;
},

RunWhenReady : function()
{    
	Wishpot.BM.RunWhenReadyInt();
},

RunWhenReadyInt : function()
{    
	if(this.CheckLibsLoaded() == true)
	{        
		this.ClearWait();
		this.Run();    
	}    
	else
	{
	    this.LoadLibs();  //keep calling this and let it manage it's progression
		this.LibWaitCount++;        
		var maxCount = 40;
		if(this.LibWaitCount >= maxCount)
		{   
			var showAlert = (this.LibWaitCount == maxCount);
			this.ClearWait();
			if(showAlert)
			{
				this.ShowFailure("Libraries didn't load in a timely fashion.  Is ajax.googleapis.com accessible?");
			}
		}
	}
},

ClearWait : function()
{    
	if(this.LibWaitCode != 0)
	{        
		window.clearInterval(this.LibWaitCode);        
		this.LibWaitCode = 0; 
		this.LibWaitCount = 0;
	}    
},

ShowFailure : function(moreinfo)
{
    var details = "";
    if(typeof(moreinfo) != 'undefined' && moreinfo != null)
        details = "\n[ "+moreinfo+" ]";
        
	alert("The Add to Wishpot window couldn't be loaded on this page. We apologize for the inconvenience."+details);
},

CheckLibsLoaded : function()
{    
	return (this.CheckJqueryVersion() && typeof(jQuery.ui) != "undefined");
},

CheckJqueryVersion: function()
{
  if (typeof(jQuery) == "undefined") return false;
  try { return (this.WPJQ != null || $().jquery == Wishpot.BM._JqueryVersion); }
  catch(ex){ Wishpot.BM.Debug("Error checking jQuery version: "+ex); return false;}
},

CheckStyleSheetPresent: function()
{
    for(i=0;i<document.styleSheets.length;i++)
    {
      if (document.styleSheets[i].href == this.StyleSheetPath()) return true;
    }
    Wishpot.BM.Debug("Stylesheet not present: "+this.StyleSheetPath());
    return false;
},

//Namespacing jQuery
WPJQ : null,

//
// Anything below this point assumes the libs have been loaded
//

Run : function()
{
    this.WPJQ = jQuery.noConflict();
    //if the stylesheet wasn't loaded, this hack will force it in.  Workaround for IE on sites with lots of styles
    if(!this.CheckStyleSheetPresent()){ document.styleSheets[0].addImport(this.StyleSheetPath()); }
	this.OnDocReady();
},

OnDocReady : function()
{
    var d = this.CreateDialog();

    //show the dialog even before we parse the page, so users get some immediate feedback.
    //try/catch is because some sites (ex. anthropologie) throw errors here in prototype.js
    try{ d.dialog("open"); }
    catch(e){ Wishpot.BM.Debug("Could not open dialog: "+e);}

    var info = this.ScrapePage();	
    this.OnPageScraped(info);
},

OnPageScraped : function(info)
{
    Wishpot.BM.Debug("page scraped");
    
    //make sure the lead image has finished loading if it needs to.  
    if(this._LeadImage != null && !this.LeadImageLoaded() && this._PostFormWaitCount < 4)
    {
		Wishpot.BM.Debug("Waiting for lead image to load.  Count "+this._PostFormWaitCount);
        if(null != this._PostFormWaitCode){ this._PostFormWaitCount++; }
        else {this._PostFormWaitCode = window.setInterval(function() {Wishpot.BM.OnPageScraped(info)}, 500); }
        return;
    }
    if(this._PostFormWaitCode != null){ window.clearInterval(this._PostFormWaitCode); }
    
    //if we had a lead image that we were waiting to load, add it
    if(this._LeadImage != null)
	{
		if(this.LeadImageLoaded())
		{
			Wishpot.BM.Debug("Lead image loaded: "+this._LeadImage.src);
			var img = {};
			img.Src = this._LeadImage.src;
			img.X = null;
			img.Y = null;
			img.Height = this._LeadImage.height;
			img.Width = this._LeadImage.width;
			img.Alt = "WISHPOT";
			info.Images.push(img);
		}
		else
		{
			Wishpot.BM.Debug("Lead image failed to load: "+this._LeadImage.src);
		}
	}

    //do the submit
	this.Form = document.getElementById("Wishpot.BM.Form");
    this.PrepareForm(info);
    this.Form.submit();	
},

CreateDialog : function()
{
	if(this.Dialog != null)
	{
	  Wishpot.BM.Debug("Destroying existing dialog.");
		try
		{
            if(this.Dialog.dialog("isOpen")) this.Dialog.dialog("close");
			this.Dialog.dialog("destroy");
			this.Dialog.remove();
		}
		catch(e)
		{  Wishpot.BM.Debug("Exception destroying dialog: "+e); }
		this.Dialog = null;
	}
	var f_id = "Wishpot.BM.Form";
	var d_id = "WishpotDialog";
	
	var cdiv = document.createElement('div');
	cdiv.setAttribute("id", d_id);
	cdiv.setAttribute("style", "padding: 0;");
	
	//the content of the dialog box - post to "default.aspx" to workaround integrated mode iis bug.
	var s = "";
    s = s + "<iframe style=\"width:100%; height:100%; margin:0px; padding:0px; border: 0px;\" src=\"about:blank\" id=\"Wishpot.BM.Frame\" name=\"Wishpot.BM.Frame\"></iframe>";
    s = s + "<div style=\"display:none; position:absolute; visibility:hidden;\"><form id=\""+f_id+"\" name=\""+f_id+"\" target=\"Wishpot.BM.Frame\"";
    s = s + " method=\"post\" action=\"";
    s = s + this.ContentRoot + "/bm/default.aspx";
    s = s + "\"></form></div>";
    cdiv.innerHTML = s;
    
    var bod = this.GetLargestWindow().document.body;
    Wishpot.BM.Debug("Appending body text to: "+bod);
    bod.appendChild(cdiv); //no jquery just in case

    Wishpot.BM.Debug("Creating dialog with element: "+this.WPJQ("#"+d_id)+" whose type is "+(typeof(this.WPJQ("#"+d_id))));

    var addText = "Add to Wishpot";
    var button_elems = this.GetButtonFormElements();
    if(button_elems!= null && typeof(button_elems["DialogTitle"]) != "undefined"){addText = button_elems["DialogTitle"].value;}
    
    try{
        this.WPJQ("#"+d_id).dialog({
			    title: addText,
			    width:655,
          height:520,
			    modal: true,
			    zIndex: 10000000, //goes up to 2147483647, but opera/safari don't like it
			    overlay: {
				    backgroundColor: '#000',
				    opacity: 0.5
			    }
		    });
        Wishpot.BM.Debug("Dialog created...");
        //make sure the elements we expect exist, based on behavior at ballarddesigns.com
        var dialogTitle = document.getElementById("ui-dialog-title-"+d_id);
        if(null == dialogTitle || (typeof(dialogTitle) == "undefined"))
        {
          //hide the div we did create
          this.WPJQ("#"+d_id).css("display", "none");
          throw("No dialog created.  Titlebar not found.");
        }
    }catch(e){
        Wishpot.BM.Debug("Error creating dialog, will post to new window instead: "+e);
        document.getElementById(f_id).setAttribute("target", "_blank");
    }
       
    this.Dialog = this.WPJQ("#"+d_id);

	return this.Dialog;
},


PrepareForm : function(info)
{
	this.AddInput("Source", "b100");
	this.AddInput("pkey", info.pkey);
	this.AddInput("pchannel", info.pchannel);
    this.AddInput("sku", info.sku);
	this.AddInput("uid", info.uid);
	this.AddInput("wid", info.wid);
	this.AddInput("rc", info.rc);
	this.AddInput("SourceUrl", info.Url);
	this.AddInput("WishTitle", info.Title);
	this.AddInput("Notes", info.Notes);
	this.AddInput("charset", document.characterSet);
	this.AddInputNN("Currency", info.Currency);
	this.AddInputNN("Price", info.Price);
	this.AddInputNN("Upc", info.Upc);
	this.AddInputNN("Isbn", info.Isbn);
	var imgs = info.Images;
	this.AddInput("ImgCount", imgs.length);
	for(var i=0; i<imgs.length; i++)
	{
		var pre = "Img" + i;
		this.AddInput(pre+"Src", imgs[i].Src);
		this.AddInputNN(pre+"X", imgs[i].X);
		this.AddInputNN(pre+"Y", imgs[i].Y);
		this.AddInputNN(pre+"W", imgs[i].Width);
		this.AddInputNN(pre+"H", imgs[i].Height);
		this.AddInputNN(pre+"Alt", imgs[i].Alt);
	}
},


AddInput : function(iid, val)
{
	var s = (typeof(val) == "undefined") ? "" : val.toString();
	var iel = document.createElement('input');
	iel.setAttribute("type", "hidden");
	iel.setAttribute("id", iid);
	iel.setAttribute("name", iid);
	iel.setAttribute("value", s);
	this.Form.appendChild(iel); 
},

AddInputNN : function(iid, val)
{
	if(val != null){ this.AddInput(iid, val); }
},

TrimX : function(s)
{
	s = s.replace(/^[\s,:\-||\x2e\x2f]+/g, "").replace(/[\s,:\-||\x2e\x2f]+$/g, "");
	return s;
},

FirstMatch : function(regExps, s, idx)
{
	if(!idx){ idx = [1]; }
	
	var res = null;
	for(var i=0; i < regExps.length; i++) 
	{
		var m = s.match(regExps[i]);
		if(m != null)
		{
			res = "";
			for(var j = 0; j < idx.length; j++)
				res = res + m[idx[j]];
			break;
		}
	}
	return res;
},

GetButtonFormElements : function()
{
  var wpform = ( (typeof(window.WISHPOT_FORM) != "undefined") ? window.WISHPOT_FORM : null);
  if(wpform == null) return null;
  var button_elems = wpform.elements;
  //check if we were given a form or a node (div) and parse values out of either
	if(typeof(button_elems) == "undefined"){button_elems = wpform.getElementsByTagName('input');}
	return button_elems;
},

ScrapePage : function()
{
	var body = document.getElementsByTagName("body")[0];	
	var bs = body.innerHTML;
	
	var res = {};
	//if the user provided this information in a form
	//we don't need to scrape the page for data 
	var button_elems = this.GetButtonFormElements();
	if(button_elems != null){
	    if(typeof(button_elems["pkey"]) != "undefined"){res.pkey = button_elems["pkey"].value;}
	    if(typeof(button_elems["pchannel"]) != "undefined"){res.pchannel = button_elems["pchannel"].value;}
	    if(typeof(button_elems["Sku"]) != "undefined"){res.sku = button_elems["Sku"].value;}
	    if(typeof(button_elems["uid"]) != "undefined"){res.uid = button_elems["uid"].value;}
	    if(typeof(button_elems["wid"]) != "undefined"){res.wid = button_elems["wid"].value;}
	    if(typeof(button_elems["WishTitle"]) != "undefined"){res.Title = button_elems["WishTitle"].value;}
	    if(typeof(button_elems["WishUrl"]) != "undefined"){res.Url = button_elems["WishUrl"].value;}
	    if(typeof(button_elems["Price"]) != "undefined"){res.Price = button_elems["Price"].value;}
	    if(typeof(button_elems["Isbn"]) != "undefined"){res.Isbn = button_elems["Isbn"].value;}
	    if(typeof(button_elems["Upc"]) != "undefined"){res.Upc = button_elems["Upc"].value;}
	    if(typeof(button_elems["Notes"]) != "undefined"){res.Notes = button_elems["Notes"].value;}
	    if(typeof(button_elems["Currency"]) != "undefined"){res.Currency = button_elems["Currency"].value;}
	    //only support a single image for now
	    if( typeof(button_elems["ImgSrc"]) != "undefined" ){
            var img_full_src = button_elems["ImgSrc"].value;
            //support relative paths to images as well
	        if(img_full_src.indexOf("http") != 0)
            { 
              var path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
              img_full_src = window.location.protocol+"//"+window.location.host+path+img_full_src;
            }
            Wishpot.BM.Debug("Adding lead image: "+img_full_src);
            Wishpot.BM.SetLeadImageDimensions(img_full_src);
	    }
	    //consider the referral a button user
	    res.rc = "button";
	}
	
	if(typeof(res.Title) == "undefined") res.Title = this.ScrapeTitle(bs);
	if(typeof(res.Url) == "undefined") res.Url = window.location.href;
	if(typeof(res.Images) == "undefined") res.Images = this.ScrapeImages(bs);
	if(typeof(res.Price) == "undefined") res.Price = this.ScrapePrice(bs);
	if(typeof(res.Upc) == "undefined") res.Upc = this.ScrapeUpc(bs);
	if(typeof(res.Isbn) == "undefined") res.Isbn = this.ScrapeIsbn(bs);
	if(typeof(res.Currency) == "undefined") res.Currency = this.ScrapeCurrency();
	
	return res;
},

ScrapeTitle : function(bs)
{
	if(Wishpot.Spec && Wishpot.Spec.ScrapeTitle)
		return Wishpot.Spec.ScrapeTitle(bs);
	else
		return this.ScrapeTitleDef(bs);
},

ScrapeImages : function(bs)
{
	if(Wishpot.Spec && Wishpot.Spec.ScrapeImages)
		return Wishpot.Spec.ScrapeImages(bs);
	else
		return this.ScrapeImagesDef(bs);
},

ScrapePrice : function(bs)
{
	if(Wishpot.Spec && Wishpot.Spec.ScrapePrice)
		return Wishpot.Spec.ScrapePrice(bs);
	else
		return this.ScrapePriceDef(bs);
},

ScrapeCurrency : function()
{
    if(/\.co\.uk$/.test(this.DomainNoPrefix()))
        return "GBP";
    if(/\.(it|fr)$/.test(this.DomainNoPrefix()))
        return "EUR";
    if(/\.ca$/.test(this.DomainNoPrefix()))
        return "CAD";
    return null;
},

ScrapeUpc : function(bs)
{
	if(Wishpot.Spec && Wishpot.Spec.ScrapeUpc)
		return Wishpot.Spec.ScrapeUpc(bs);
	else
		return this.ScrapeUpcDef(bs);
},

ScrapeIsbn : function(bs)
{
	if(Wishpot.Spec && Wishpot.Spec.ScrapeIsbn)
		return Wishpot.Spec.ScrapeIsbn(bs);
	else
		return this.ScrapeIsbnDef(bs);
},

ScrapeUpcDef : function(bs)
{
	var regex = new RegExp(/upc.*?(\d{10,14})/i);
	var m = bs.match(regex);
	if(m != null){ return m[1]; }
	else { return null; }
},

ScrapeIsbnDef : function(bs)
{
	var regExps =  [
			new RegExp(/isbn.*?(\w{9}[X\d]{1})/i),
			new RegExp(/isbn.*?([\w\-]{13})/i)];

	return this.FirstMatch(regExps, bs);
},

ScrapePriceDef : function(bs)
{
	var priceDef = "([\\$\\u00A3\\u20AC])(([1-9]\\d*(,\\d\\d\\d)*\\d*(\\.\\d{0,3})?)|(0?\\.0*[1-9]\\d*))";
	var regExps =  [
			new RegExp("you pay(?:\\s|\\&nbsp;)*:[\\s\\S]+?" + priceDef, "i"),
			new RegExp("sale(?:\\s|\\&nbsp;)+price[\\s\\S]+?" + priceDef, "i"),
			new RegExp("our(?:\\s|\\&nbsp;)+price[\\s\\S]+?" + priceDef, "i"),
			new RegExp("sale(?:\\s|\\&nbsp;)*:[\\s\\S]+?" + priceDef, "i"),
			new RegExp("price(?:\\s|\\&nbsp;)*:[\\s\\S]+?" + priceDef, "i"),
			new RegExp("now(?:\\s|\\&nbsp;)*:[\\s\\S]+?" + priceDef, "i"),
			new RegExp(priceDef, "i")];

	return this.FirstMatch(regExps, bs, [1,2]);
},

ScrapeTitleDef : function(bs)
{
	var t = document.title;
	var dd = this.DomainNoPrefix();

	t = this.TrimX(t.replace(/\240/g, " "));
	if(dd != null)
	{	
		t = this.TrimX(t.replace(new RegExp("www."+dd, "i"), ""));
		t = this.TrimX(t.replace(new RegExp(dd, "i"), ""));
	}
	if(t.length == 0)
		t = document.title;
	
	return t;
},

ScrapeImagesDef : function(bs)
{		
	var res = [];
	var count = 0;
    var imgs = document.getElementsByTagName("img");

    Wishpot.BM.Debug("Looping through "+imgs.length+" images.");
		
    for (var i=0; i < imgs.length; i++) 		
	{	
	
	  var el = imgs[i];
      if(el.src == "" || el.id == "WishpotLogo")
        continue;

      //special case for flash sites
      if(el.src){
          if ("macys.com" == Wishpot.BM.DomainNoPrefix()) { if (el.name == "PDPimage") Wishpot.BM.SetLeadImageDimensions(el.src); }
          if ("anthropologie.com" == Wishpot.BM.DomainNoPrefix()) { if ((el.src).match(/\$appprodmain\$/)) Wishpot.BM.SetLeadImageDimensions(el.src); }
          if ("crateandbarrel.com" == Wishpot.BM.DomainNoPrefix()) { if (el.id == "ctl00_CrateMainContent_imgFamilyPrint") Wishpot.BM.SetLeadImageDimensions(el.src);}
      }
      
      var w = el.width;
      var h = el.height;
      //Wishpot.BM.Debug("Image ("+w+", "+h+"): "+el.src, true);
      
      //skip tiny images
      if(w < 30 || h < 30)
        continue;
        
      var x = 0;
      var y = 0;
      
      try{
        var o = Wishpot.BM.WPJQ(el);
        var offset = o.offset();
        x = offset.left;
        y = offset.top;
      }catch(e){ /*no jquery*/}
      
      var img = {};
      img.Src = el.src;
      img.X = (isNaN(x) ? null : x);
      img.Y = (isNaN(y) ? null : y);
      img.Width = (isNaN(w) ? null : w);
      img.Height = (isNaN(h) ? null : h);
      img.Alt = el.alt;
      if(img.Alt == "")
        img.Alt = null;
        
      res[count++] = img;
    }
	Wishpot.BM.Debug("returning from images.  Added "+count);

	return res;
}

}}

}
Wishpot.BM.OnButtonPressed();
