// Netflix Spotlight Widget, v20091209
// see http://developer.netflix.com/widgets for instructions
// author: Kent Brewster
// with much help from: Hans Granqvist, John Haren, JR Conlin, Lalitha Shankar, Michael Hart, Mikey Cohen, Navin Prasad, and Priya Poolavari 
// special thanks to: Dave Balmer, Doug Crockford, Dustin Diaz, Hedger Wang, Isaac Schlueter, and Scott Schiller

(function (w, d) {
   var voco = '';
   for (var i = 0; i < 16; i++) { voco += String.fromCharCode(Math.floor(Math.random() * 26) + 97); }
   w[voco] = {};
   // semi-private global variable
   var $ = w[voco];
   // window and document will come in handy later
   $.w = w;
   $.d = d;
   // our main function
   $.f = function() { 
      return {   
         init : function(hinc) {
            // get all the script nodes on the page
            var s = $.d.getElementsByTagName('SCRIPT');
            // loop through all script nodes on the page
            for (var i = 0; i < s.length; i++) { 
               if (s[i].src.match(hinc)) { 
                  var o = s[i]; 
                  var strucTag = 'DIV';
                  $.s = $.f.fiat(strucTag);
                  o.parentNode.insertBefore($.s, o);
                  $.f.cura(o);                 
                  // remove the first instance of a link to the movie we're getting, 
                  // if it's in the parent node of the SCRIPT tag.                            
                  var a = o.parentNode.getElementsByTagName('A');
                  for (var j = 0; j < a.length; j++) {
                     if (a[j].href === $.a.org) {
                        a[j].parentNode.removeChild(a[j]);
                        break;
                     }
                  }                  
                  o.parentNode.removeChild(o);
                  break; 
               } 
            }
         },
         // parse variables, 
         cura : function(o) {
            $.d.b = $.d.getElementsByTagName('BODY')[0];
            $.d.h = $.d.getElementsByTagName('HEAD')[0];
            $.k = {
               "catalog" : "http://catalog.netflix.com/catalog/titles/",
               "freeTrialUrl" : "http://widgets.netflix.com/FreeTrial",
               "canSuppress" : "ftadsplvirngh",
               "frameName" : "NFLXFRAME",
               "frameHeight":280,
               "frameWidth":480,
               "frameMargin":20,
               "widgetBuilder" : "http://developer.netflix.com/widgets/spotlight?",
               "maxWidth" : {"t":300, "w":600, "b":300 },
               "minWidth" : {"t":{"s":{"d":230,"x":86,"m":"n"},"l":{"d":230,"x":135,"m":"n"}},"w":{"s":{"d":350},"l":{"d":400}},"b":{"s":{"d":225,"x":150,"m":"f"},"l":{"d":265,"x":200,"m":"f"}}}               
            };
            $.a = {};
            var data = $.f.crib(o.getAttribute('settings'));
            for (var f in data) { 
               if (data[f].hasOwnProperty && !$.a[f]) { 
                  $.a[f] = data[f]; 
               } 
            }                        
            if ($.a.k) { $.k.freeTrialUrl += '?key=' + $.a.k; }
            $.k.standardRules = [
               '.nflx-iframe {position:absolute;top:11px;left:11px;height:230px;width:434px;}',
               '.nflx-iframe-container {position:absolute;overflow:hidden;top:0;left:0;height:253px;width:458px;z-index:8675310;}',
               '.nflx-iframe-close {cursor:pointer;position:absolute;overflow:hidden;top:10px;right:10px;height:30px;width:100px;z-index:8675311;}',
               '.nflx-iframe-shadow {position:absolute;top:0;left:0;height:253px;width:458px;background:transparent url(http://cdn.nflximg.com/us/layout/blocks/apiframe/iframeShadow_sq.png) 0 0 no-repeat;_background:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://cdn.nflximg.com/us/layout/blocks/apiframe/iframeShadow_sq.png\',sizingMethod=\'scale\');}'
            ];
            // here's the function we're going to run if all goes well
            var ave = function() { $.f.dili(); };
            // only fire if we have a movie id
       
            if ($.a.id) {
                $.a.org = $.a.id;
                $.a.id = $.a.id.split('/')[$.a.id.split('/').length - 1];
                if ($.a.r) {
                   // run immediately -- for web apps
                   ave();
                } else {
                   // wait for page load 
                   if(typeof $.w.addEventListener !== 'undefined') { 
                      try{$.w.addEventListener('load', ave, false);} catch (e1) {} 
                   } else if(typeof $.w.attachEvent !== 'undefined') { 
                      try{$.w.attachEvent('onload', ave );} catch(e2) {} 
                   }
                }
             }
         },         
         // do housekeeping, get data from API
         dili : function() {
            // x and y are pixel distance from buttons for iframe
            // f = format, default tall
            // s = size, default large
            // q = logo location, default 0 = top
            // k = developer key, for affiliate program
            // h = stuff to hide
            var defaults = { "x" : 40, "y" : 40, "f":"t", "s":"l", "q":0, "k":"", "h":"" };                        
            // load defaults if not present in query string
            for (var d in defaults) { if (defaults[d].hasOwnProperty && $.a[d] === undefined) { $.a[d] = defaults[d]; } }            
            // everything is on by default; to suppress, send values in $.a.h; valid characters are in $.k.canSuppress, loaded upstairs in $.f.cura
            $.a.supp = {};
            if ($.a.h) {
               for (var i = 0; i < $.k.canSuppress.length; i++) {
                  var t = $.k.canSuppress.substr(i, 1);
                  for (var j = 0; j < $.a.h.length; j++) {
                     var s = $.a.h.substr(j, 1);
                     if (t === s) { $.a.supp[t] = true; }
                  }
               }
            }             
            // default format = tall
            if ($.a.f !== 't' && $.a.f !== 'w' && $.a.f !== 'b') { $.a.f = 't'; }
            // default size = large
            if ($.a.s !== 'l' && $.a.s !== 's') { $.a.s = 'l'; }             
            // if the requested width is too wide, shrink it
            if ($.a.w > $.k.maxWidth[$.a.f]) { $.a.w = $.k.maxWidth[$.a.f]; }            
            // some fairly complicated dealings with various widths and options
            var defaultWidth = $.k.minWidth[$.a.f][$.a.s].d;
            var modifier = $.k.minWidth[$.a.f][$.a.s].m;
            var altWidth = $.k.minWidth[$.a.f][$.a.s].x;
            if (typeof $.a.w === 'undefined') { if ($.a.supp[modifier]) { $.a.w = altWidth; } else { $.a.w = defaultWidth; } }            
            if ($.a.w < defaultWidth) { if ($.a.supp[modifier]) { if ($.a.w < altWidth) { $.a.w = altWidth; } } else { $.a.w = defaultWidth; } }  
            var scriptId = voco + '.p';
            var request = 'http://movi.es/' + $.a.id + '?v=2.0&output=json&expand=widget&callback=' + scriptId;
            $.p = function(r) { 
               // fires after data comes back from the API
               if (r) {
                  // load data
                  $.a.data = $.f.conv(r); 
                  if ($.a.data.id) {
                     // yes! we are finally ready to build a widget!
                     $.f.aedi();
                     if ($.a.f === 'w') { $.f.wide(); }
                     if ($.a.f === 'b') { $.f.banner(); }
                     if ($.a.f === 't') { $.f.tall(); }
                  }
               } 
               $.f.abol(voco + '.p');
            };
            $.d.b.appendChild($.f.fiat({"SCRIPT":{"id":scriptId, "charset":"utf-8", "type":"text/javascript", "src":request}}));
         },
         // convert returned data to something the widget can deal with
         conv : function(k) {
            // everything that can be possibly displayed in any widget
            var data = {"avail" : {}, "box_art" : "", "id":"", "info" :"", "preview" : "", "rating" : "", "synopsis" : "", "tiny" : "", "title" : "", "web_page" : "" };
            var r = k.catalog_title;
            if (r.id) { data.id = r.id; } else { return data; }
            if (k.meta.links.previews) { 
               data.preview = $.k.catalog + k.meta.links.previews.split('/titles/')[1]; 
            }
            var releaseYear = '';
            var contentRating = ''; 
            if (r.tiny_url) { data.tiny = r.tiny_url.split('/')[3]; }
            if (r.title.regular) { data.title = r.title.regular; }
            if (r.release_year) { releaseYear = r.release_year; }
            if (r.ratings) { contentRating = r.ratings; }
            data.info = "(" + releaseYear + ") " + contentRating;
            if (r.web_page) { data.web_page = r.web_page; }           
            if (r.delivery_formats) {
               if (r.delivery_formats.DVD) { data.avail.disc = r.delivery_formats.DVD.available_from; } else { if (r.delivery_formats['Blu-ray']) { data.avail.disc = r.delivery_formats['Blu-ray'].available_from; } }               
               if (r.delivery_formats.instant) {
                  data.avail.play = r.delivery_formats.instant.available_from;
                  data.avail.later = r.delivery_formats.instant.available_from;
               }               
            }
            if (!data.avail.play && !data.avail.disc) { data.avail.save = true; }            
            var size = 'large';
            if ($.a.s === 's') { size = 'medium'; }
            data.box_art = r.box_art[size];
            data.synopsis = r.synopsis.regular;
            return data;
         },
         // heat up the buttons
         acti : function() {
            if (!$.s.play.className) {
               var hide = function() { $.s.later.style.display = 'none'; };
               if ($.a.f === 'b') {
                  var show = function() { 
                     $.s.later.style.top = ($.s.cust.offsetTop + $.s.cust.offsetHeight - 1) + 'px';
                     var t = $.s.cust.offsetLeft;
                     if ($.a.s === 's') {
                       t = t - 8;
                     }
                     $.s.later.style.left = t + 'px';
                     $.s.later.style.display = 'block';
                  };
               } else {
                  var show = function() { $.s.later.style.display = 'block'; };
               }
               $.s.play.onmouseover = show;
               $.s.play.onmouseout = hide;
               $.s.later.onmouseover = show;
               $.s.later.onmouseout = hide;
               $.s.add.onmouseover = show;
               $.s.add.onmouseout = hide;
               $.s.save.onmouseover = show;
               $.s.save.onmouseout = hide;
            }                 
            $.s.add.onclick = function() { $.f.exhi('add'); return false; };
            $.s.play.onclick = function() { $.w.open('http://www.netflix.com/CommunityAPIPlay?devKey=' + $.a.k + '&movieid=' + $.a.data.id + '&nbb=y');};
            $.s.later.onclick = function() { $.f.exhi('later'); return false; };
            $.s.save.onclick = function() { $.f.exhi('save'); return false; };
            if (!$.s.preview.className) { $.s.preview.onclick = function() { $.f.spec(); return false; }; }            
         },
         // banner widget
	banner : function() {
	    var mm = 0;
	    if (!$.a.supp.f) { mm = 80; }	
	    var atrium = '#'+voco+' #'+voco+'_sh #'+voco+'_at';
	    var atriumSmall = '#'+voco+'.s #'+voco+'_sh #'+voco+'_at';
	    var atriumSplit = '#'+voco+'.k #'+voco+'_sh #'+voco+'_at';
            var rules = [
               '#' + voco + ' {width:' + $.a.w + 'px;margin:0;padding:0;}',
               '#'  +voco + ' #' + voco + '_sh {background:#ccc; margin:0;padding:0;position:relative;font:normal normal normal 12px/16px arial;}',
               atrium + '  {margin:0; padding:1px; overflow:hidden; }',
               atrium + ' * {margin:0; padding:0; text-align:center; text-decoration:none; }',
               atrium + ' #' + voco + '_banner {position:absolute;top:0;left:0;width:64px;background:#B9090B;}',
               atrium + ' #' + voco + '_logo{display:block;background:transparent url(http://jsapi.netflix.com/us/api/images/buttons/n_small.png) no-repeat 50% 50%;height:30px;width:64px;text-indent:-8675309px;}',               
               atrium + ' #' + voco + '_trial {position:absolute;top:1px;right:1px;width:80px;background-color:#fff;border-left:1px solid #ccc;}', 
               atrium + ' #' + voco + '_trialLink {display:block;color:#000;font-weight:bold;}', 
               atrium + ' #' + voco + '_trialLink span{white-space:pre;display:inline-block;padding:0 5px;background:#0271C0 url(http://jsapi.netflix.com/us/api/w/s/i/t.jpg) repeat-x scroll 0 0;color:#fff;font-size:11px;height:18px;line-height:18px;border:1px solid #fff;}',
               atrium + ' #' + voco + '_merch {padding:5px 0;margin:0px ' + mm + 'px 0px 64px; background-color:#eee;}',               
               atrium + ' #' + voco + '_merch #'+voco+'_titl{display:block;padding:0 5px 5px;font-weight:bold;color:#00458A;}',
               atrium + ' #' + voco + '_merch #'+voco+'_info{font-size:11px;padding-top:5px;}',
               atrium + ' #'+voco+'_cust{position:relative}',
               atrium + ' #' + voco + '_buttons{width:120px;margin:0 auto;}',
               atrium + ' #' + voco + '_buttons a#'+voco+'_preview{background-color:#333;background-position:0 -200px;margin-top:2px;}',
               atrium + ' #' + voco + '_buttons a#'+voco+'_preview:hover{background-color:#777;background-position:0 -234px;}',
               atriumSmall + ' #' + voco + '_buttons{width:64px;}',
               '#'+voco+'_sh a#' + voco + '_later, '+atrium + ' #' + voco + '_cust a,' + atrium + ' #' + voco + '_merch a#' + voco + '_preview{display:inline-block;text-align:center;height:20px;line-height:20px;font-size:13px;font-weight:bold;color:#fff;width:100%;background-image:url(http://jsapi.netflix.com/us/api/w/s/i/b.gif);background-image-repeat:repeat-x;text-decoration:none;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add{background-color:#900;background-position:0 -8px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add:hover{background-color:#b71e1e;background-position:0 -40px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save{background-color:#688507;background-position:0 -136px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save:hover{background-color:#8bb109;background-position:0 -168px;}',
               '#'+voco+' a#'+voco+'_later, #'+voco+' #'+voco+'_cust a#'+voco+'_play {background-color:#004073;background-position:0 -72px;}',
               '#'+voco + '_sh a#'+voco+'_later:hover, #'+voco+' #'+voco+'_cust a#'+voco+'_play:hover{background-color:#1d5d90;background-position:0 -112px;}',
               '#'+voco + '_sh a#'+voco+'_later{display:none;border:1px solid #666;left:0;position:absolute;top:0;height:20px;width:110px;}',
               atrium + ' #'+voco+'_cust,' + atrium + ' #'+voco+'_merch a#'+voco+'_preview{width:110px;display:inline-block;border:1px solid #666;}',
               atriumSmall + ' #'+voco+'_cust,' + atriumSmall + ' #'+voco+'_merch a#'+voco+'_preview{width:64px;}',
               atriumSmall + ' a#'+voco+'_later, ' + atriumSmall + ' #'+voco+'_cust a, ' + atriumSmall + ' #'+voco+'_merch a#'+voco+'_preview{font-size:11px;height:17px;line-height:17px;}',
               '#'+voco+'.s #'+voco+'_sh a#'+voco+'_later{width:84px;font-size:11px;height:17px;line-height:17px;}',
               atriumSplit + ' #' + voco + '_cust a#'+voco+'_add, ' + atriumSplit + ' #' + voco + '_cust a#'+voco+'_play, ' + atriumSplit + ' #' + voco + '_cust a#'+voco+'_save{width:50%;}',

               '#'+voco+' .x{display:none!important;}'
            ];
            var r = rules.join("\n") + $.k.standardRules.join("\n");
            var css = document.createElement('STYLE');
            css.className = 'netflix-generated-style';
            css.type = 'text/css';
            if (css.styleSheet) { css.styleSheet.cssText = r;} else { css.appendChild(document.createTextNode(r));}
            document.getElementsByTagName('HEAD')[0].appendChild(css);              
            var struc = $.f.fiat({"DIV":{"id":voco + "_sh"}}); 
            var atrium = $.f.fiat({"DIV":{"id":voco + "_at"}}); 
               var banner = $.f.fiat({"DIV":{"id":voco + "_banner"}});
                  logo = $.f.fiat({"A":{"id":voco + "_logo", "innerHTML":"Netflix", "href":"http://www.netflix.com"}});
                  banner.appendChild(logo);
               atrium.appendChild(banner);
               var merch = $.f.fiat({"DIV":{"id":voco + "_merch"}});
	          if (!$.a.supp.f) {
	             var trial = "FREE TRIAL <span>Click Here</span>"; 
	             if ($.a.supp.t && $.a.supp.i && ($.a.supp.v || !$.a.data.preview)) {
	                trial = "<span>FREE TRIAL</span>"; 
	             }
	             $.s.trial = $.f.fiat({"DIV":{"id":voco + "_trial"}});
	             $.s.trialLink = $.f.fiat({"A":{"id":voco + "_trialLink", "href":$.k.freeTrialUrl, "innerHTML": trial}});
	             $.s.trial.appendChild($.s.trialLink);
	             merch.appendChild($.s.trial);
	          }
                  $.s.titl = $.f.fiat({"A":{"id":voco + "_titl", "innerHTML":$.a.data.title, "href":$.a.data.web_page}});
                  if ($.a.supp.t) { $.s.titl.className = 'x'; }
                  merch.appendChild($.s.titl);
                  
                  var buttons = $.f.fiat({"DIV":{"id":voco + "_buttons"}});
                     $.s.cust = $.f.fiat({"DIV":{"id":voco + "_cust"}});
                        $.s.save = $.f.fiat({"A":{"id":voco + "_save", "innerHTML":"Save", "href":"#"}});
                        if (!$.a.data.avail.save || $.a.supp.s) { $.s.save.className = 'x'; } 
                        $.s.cust.appendChild($.s.save);
                        $.s.add = $.f.fiat({"A":{"id":voco + "_add", "innerHTML":"Add"}});
                        $.s.cust.appendChild($.s.add);
                        if (!$.a.data.avail.disc || $.a.supp.d) { $.s.add.className = 'x'; } else { if ($.s.save.className !== 'x') { $.s.className = 'k'; } }
                        $.s.play = $.f.fiat({"A":{"id":voco + "_play", "innerHTML":"Play", "href":"#"}});
                        $.s.cust.appendChild($.s.play);
                        buttons.appendChild($.s.cust);
                     $.s.preview = $.f.fiat({"A":{"id":voco + "_preview", "innerHTML":"Preview", "href":"#"}});
                     if (!$.a.data.preview || $.a.supp.v ) { $.s.preview.className = 'x'; }
                     buttons.appendChild($.s.preview);
                     if ($.a.data.avail.later && !$.a.supp.p && !$.a.supp.l) {
                        if (!$.a.data.avail.preview || $.a.supp.v) {
                           buttons.className = 'p';
                        }
                     }
                  merch.appendChild(buttons);
                  
                  $.s.info = $.f.fiat({"DIV":{"id":voco + "_info", "innerHTML":$.a.data.info }});
                  if ($.a.supp.i) { $.s.info.className = 'x'; }
                  merch.appendChild($.s.info);
               atrium.appendChild(merch);
            struc.appendChild(atrium);
            $.s.id = voco;
            $.s.appendChild(struc);
            if (!$.a.data.avail.play || $.a.supp.p) { $.s.play.className = 'x'; } else { if ($.s.save.className !== 'x' || $.s.add.className !== 'x') { $.s.className = 'k'; } }
               $.s.later = $.f.fiat({"A":{"id":voco + "_later", "innerHTML":"Add to Instant", "href":"#"}});
               struc.appendChild($.s.later);
            if (!$.a.data.avail.later || $.a.supp.l) { $.s.later.className = 'x'; }
            if ($.a.s === 's') { $.s.className += ' s'; }

            // re-draw logo and trial upper offsets after the fact
            var t = struc.offsetHeight;

            if ($.s.trial) {
               $.s.trial.style.height = t - 2 + 'px';
               $.s.trialLink.style.marginTop = t / 2 - $.s.trialLink.offsetHeight / 2 - 1 + 'px';
            }
            banner.style.height = t + 'px';
            logo.style.marginTop = t / 2 - logo.offsetHeight / 2 + 'px';

            $.f.acti();
         },         
         // tall widget
         tall : function() {
            var rules = [
               '#'+voco+' a{cursor:pointer;text-decoration:none;border:none;font-weight:normal;background-color:transparent;}',
               '#'+voco+' #'+voco+'_sh div {margin:0;padding:0;}',
               
               '#'+voco+' #'+voco+'_sh {width:' + $.a.w + 'px;background-color:#ccc;font:normal normal normal 12px/16px arial;position:relative;text-align:center;}',

               '#'+voco+' #'+voco+'_sh #'+voco+'_main{width:' + ($.a.w -2)+ 'px;position:relative;background-color:#eee;margin:0 auto;}',

               '#'+voco+' #'+voco+'_sh #'+voco+'_merch{background-color:#eee;text-align:center;padding-bottom:10px;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_about{background-color:#ddd;}',
               '#'+voco+' #'+voco+'_share{font-size:11px;right:1px;text-align:right;background-color:#ddd;}',
               '#'+voco+' #'+voco+'_text a, #'+voco+' #'+voco+'_share a, #'+voco+' #'+voco+'_merch a{color:#00458A;}',

               '#'+voco+' #'+voco+'_cust {z-index:2;margin:0;padding:0;}',
               
               
               '#'+voco+' #'+voco+'_sh #'+voco+'_buttons{z-index:2;padding:0;width:110px;margin:4px auto 2px;}',
               '#'+voco+' #'+voco+'_cust a,#'+voco+' #'+voco+'_merch a#'+voco+'_preview{color:#fff;display:inline-block;height:20px;line-height:20px;font-size:13px;font-weight:bold;color:#fff;width:100%;background-image:url(http://jsapi.netflix.com/us/api/w/s/i/b.gif);background-image-repeat:repeat-x;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add{background-color:#900;background-position:0 -8px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add:hover{background-color:#b71e1e;background-position:0 -40px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save{background-color:#688507;background-position:0 -136px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save:hover{background-color:#8bb109;background-position:0 -168px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_play,#'+voco+' #'+voco+'_cust a#'+voco+'_later{background-color:#004073;background-position:0 -72px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_play:hover,#'+voco+' #'+voco+'_cust a#'+voco+'_later:hover{background-color:#1d5d90;background-position:0 -112px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_later{display:none;left:-1px;position:absolute;top:20px;height:20px;width:112px;z-index:3;}',
               '#'+voco+' #'+voco+'_cust,#'+voco+' #'+voco+'_merch a#'+voco+'_preview{position:relative;width:110px;display:inline-block;border:1px solid #666;}',

               '#'+voco+' #'+voco+'_merch a#'+voco+'_preview{background-color:#333;background-position:0 -200px;margin-top:2px;}',
               '#'+voco+' #'+voco+'_merch a#'+voco+'_preview:hover{background-color:#777;background-position:0 -234px;}',
               '#'+voco+'.s #'+voco+'_sh #'+voco+'_buttons{width:84px;}',
               '#'+voco+'.s #'+voco+'_merch a#'+voco+'_later{top:17px;height:17px;left:-10px;width:84px;}',
               '#'+voco+'.s #'+voco+'_cust,#'+voco+'.s #'+voco+'_merch a#'+voco+'_preview{width:64px;}',
                
               '#'+voco+'.s #'+voco+'_sh #'+voco+'_cust a,#'+voco+'.s #'+voco+'_sh #'+voco+'_merch a#'+voco+'_preview{font-size:11px;height:17px;line-height:17px;}',
               '#'+voco+'.k #'+voco+'_cust a#'+voco+'_add,#'+voco+'.k #'+voco+'_cust a#'+voco+'_play,#'+voco+'.k #'+voco+'_cust a#'+voco+'_save{width:50%;}',

               '#'+voco+' #'+voco+'_box {display:block;height:150px;width:110px;padding:10px 0 0 0;margin:0 auto;}',
               '#'+voco+' #'+voco+'_box img#'+voco+'_art{margin:0;padding:0;border:1px solid #666;}',
               '#'+voco+'.s #'+voco+'_box {height:90px;width:66px;}',

               '#'+voco+' #'+voco+'_sh #'+voco+'_text{ margin-top:1px;}',

               '#'+voco+' #'+voco+'_sh #'+voco+'_synopsis{ padding:10px; }',
         
               '#'+voco+'.t #'+voco+'_merch{padding-top:45px;margin-left:1px; margin-right:1px;}',
               '#'+voco+'.b #'+voco+'_merch{padding-top:29px;margin-left:1px; margin-right:1px;}',

               '#'+voco+'.t #'+voco+'_about{padding-bottom:19px;}',
               '#'+voco+'.b #'+voco+'_about{padding-bottom:31px;}',

               '#'+voco+'.t.z #'+voco+'_sh {border-bottom:1px solid #ccc;}',
               '#'+voco+'.b.z #'+voco+'_sh {border-top:1px solid #ccc;}',
               
               '#'+voco+'.b.z #'+voco+'_sh #'+voco+'_merch{padding-top:5px;padding-bottom:37px;}',

               '#'+voco+'.t.z #'+voco+'_sh #'+voco+'_merch{padding-bottom:5px;padding-top:36px;}',

               '#'+voco+' #'+voco+'_sh #'+voco+'_about{text-align:left;}',

               '#'+voco+' #' + voco + '_merch #'+voco+'_titl{display:block;font-weight:bold;padding:0 5px 5px;}',
               '#'+voco+' #'+voco+'_synopsis,#'+voco+' #'+voco+'_info{font-size:11px;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_info{padding-top:5px;}',

               '#'+voco+' #'+voco+'_share a#'+voco+'_get{float:left;margin-left:10px;}',
               '#'+voco+' #'+voco+'_share span{color:#666;float:right;margin-left:10px;padding:0 3px;font-size:11px;height:18px;line-height:18px;background-color:#fff;}',
               '#'+voco+' #'+voco+'_share a#'+voco+'_fb,#'+voco+' #'+voco+'_share a#'+voco+'_tw{float:right;width:18px;height:18px;background:#fff url(http://l.yimg.com/a/i/us/mbl/services/ifacebook.png) 1px 1px no-repeat;margin-left:1px;}',
               '#'+voco+' #'+voco+'_share a#'+voco+'_tw{float:right;background-image:url(http://l.yimg.com/a/i/us/mbl/services/itwitter.png);}',

               '#'+voco+' #'+voco+'_share {position:absolute;left:1px;height:18px;}',
               '#'+voco+'.b #'+voco+'_share{top:0;border-bottom:1px solid #ccc;border-top:1px solid #ccc;}',
               '#'+voco+'.t #'+voco+'_share{bottom:0;border-bottom:1px solid #ccc;}',

               '#'+voco+' #'+voco+'_banner{width:' + $.a.w + 'px;position:absolute;left:0;height:31px;background:#B9090B url(http://jsapi.netflix.com/us/api/images/buttons/n_small.png) no-repeat 5px 50%;color:#fff;}',
               '#'+voco+'.t #'+voco+'_banner{top:0;}',
               '#'+voco+'.b #'+voco+'_banner{bottom:0;}',
               '#'+voco+' #'+voco+'_banner #'+voco+'_logo{display:block;height:30px;width:60px;text-indent:-8675309px;}',

               '#'+voco+' #'+voco+'_trial{position:absolute;top:5px;right:5px;color:#fff;font-weight:bold;}',
               '#'+voco+' #'+voco+'_trial span{white-space:pre;display:inline-block;padding:0 5px;background:#0271C0 url(http://jsapi.netflix.com/us/api/w/s/i/t.jpg) repeat-x scroll 0 0;color:#fff;font-size:11px;height:18px;line-height:18px;border:1px solid #fff;}',

               '#'+voco+' .x{display:none!important;}'
            ];
            var r = rules.join("\n") + $.k.standardRules.join("\n");
            var css = document.createElement('STYLE');
            css.type = 'text/css';
            css.className = 'netflix-generated-style';
            if (css.styleSheet) { css.styleSheet.cssText = r;} else { css.appendChild(document.createTextNode(r));}
            document.getElementsByTagName('HEAD')[0].appendChild(css);              
            var trial = "FREE TRIAL <span>Click Here</span>"; 
            var get = "get this widget";
            if ($.a.w < 200) {
               get = "get this";
            }
            var struc = $.f.fiat({"DIV":{"id":voco + "_sh"}}); 
            var main = $.f.fiat({"DIV":{"id":voco + "_main"}});
               var merch = $.f.fiat({"DIV":{"id":voco + "_merch"}});
               
                  $.s.titl = $.f.fiat({"A":{"id":voco + "_titl", "innerHTML":$.a.data.title, "href":$.a.data.web_page}});
                  if ($.a.supp.t) { $.s.titl.className = 'x'; }
                  merch.appendChild($.s.titl);

                  var box = $.f.fiat({"A":{"id":voco + "_box", "href":$.a.data.web_page}});
                     var art = $.f.fiat({"IMG":{"id":voco + "_art", "src": $.a.data.box_art }});
                     box.appendChild(art);
                     if (!$.a.data.box_art || $.a.supp.a) {
                        box.className = 'x';
                     }
                  merch.appendChild(box);
                  var buttons = $.f.fiat({"DIV":{"id":voco + "_buttons"}});
                     var cust = $.f.fiat({"DIV":{"id":voco + "_cust"}});
                        $.s.save = $.f.fiat({"A":{"id":voco + "_save", "innerHTML":"Save", "href":"#"}});
                        if (!$.a.data.avail.save || $.a.supp.s) { $.s.save.className = 'x'; } 
                        cust.appendChild($.s.save);
                        $.s.add = $.f.fiat({"A":{"id":voco + "_add", "innerHTML":"Add"}});
                        cust.appendChild($.s.add);
                        if (!$.a.data.avail.disc || $.a.supp.d) { $.s.add.className = 'x'; } else { if ($.s.save.className !== 'x') { $.s.className = 'k'; } }
                        $.s.play = $.f.fiat({"A":{"id":voco + "_play", "innerHTML":"Play", "href":"#"}});
                        cust.appendChild($.s.play);
                        if (!$.a.data.avail.play || $.a.supp.p) { $.s.play.className = 'x'; } else { if ($.s.save.className !== 'x' || $.s.add.className !== 'x') { $.s.className = 'k'; } }
                        $.s.later = $.f.fiat({"A":{"id":voco + "_later", "innerHTML":"Add to Instant", "href":"#"}});
                        cust.appendChild($.s.later);
                        if (!$.a.data.avail.later || $.a.supp.l) { $.s.later.className = 'x'; }
                        buttons.appendChild(cust);
                     $.s.preview = $.f.fiat({"A":{"id":voco + "_preview", "innerHTML":"Preview", "href":"#"}});
                     if (!$.a.data.preview || $.a.supp.v ) { $.s.preview.className = 'x'; }
                     buttons.appendChild($.s.preview);
                     // if we are going to show the "later" button AND have no preview button, we need 5px more margin-bottom
                     if ($.a.data.avail.later && !$.a.supp.p && !$.a.supp.l) {
                        if (!$.a.data.avail.preview || $.a.supp.v) {
                           buttons.className = 'p';
                        }
                     }
                  merch.appendChild(buttons);

                  $.s.info = $.f.fiat({"DIV":{"id":voco + "_info", "innerHTML":$.a.data.info }});
                  if ($.a.supp.i) { $.s.info.className = 'x'; }
                  merch.appendChild($.s.info);

               main.appendChild(merch);
               var about = $.f.fiat({"DIV":{"id":voco + "_about"}});
                  var text = $.f.fiat({"DIV":{"id":voco + "_text"}});
                     $.s.synopsis = $.f.fiat({"DIV":{"id":voco + "_synopsis", "innerHTML":$.a.data.synopsis }});
                     text.appendChild($.s.synopsis);
                     if ($.a.supp.n) {
                        text.className = 'x';
                     }
                  about.appendChild(text);
                  if ($.a.supp.n) {
                     about.className = 'x';
                  }
               main.appendChild(about);
            struc.appendChild(main);
            var banner = $.f.fiat({"DIV":{"id":voco + "_banner"}});
               $.s.trial = $.f.fiat({"A":{"id":voco + "_trial", "href":$.k.freeTrialUrl, "innerHTML": trial}});
               if ($.a.supp.f) { $.s.trial.className = 'x'; }
               banner.appendChild($.s.trial);
               var logo = $.f.fiat({"A":{"id":voco + "_logo", "innerHTML":"Netflix", "href":"http://www.netflix.com"}});
            banner.appendChild(logo);
            struc.appendChild(banner);
            $.s.share = $.f.fiat({"DIV":{"id":voco + "_share"}});
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_tw", "href":"http://twitter.com/home?status=" + encodeURIComponent($.a.data.title) + "%20on%20Netflix%3a%20http%3a%2f%2fmovi.es%2f" + $.a.id }}));
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_fb", "href":"http://www.facebook.com/share.php?u=" + encodeURIComponent($.a.data.web_page) }}));
               $.s.share.appendChild($.f.fiat({"SPAN":{"innerHTML":"share"}}));
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_get", "innerHTML": get, "href":$.k.widgetBuilder + $.a.id}}));
               if ($.a.supp.n) {
                  $.s.share.className = 'x';
                  $.s.className += ' z';
               }
            struc.appendChild($.s.share);   

            $.s.id = voco;
            $.s.appendChild(struc);
            if ($.a.s === 's') { $.s.className += ' s'; }
            if ($.a.q) { $.s.className += ' b'; } else { $.s.className += ' t'; }
            $.f.acti();
         },         
         // wide widget
         wide : function() {
            var merchBig = 130;
            var merchSmall = 85;
            var aboutBig = $.a.w - merchBig;
            var aboutSmall = $.a.w - merchSmall;            
            var rules = [
               '#'+voco+' a{cursor:pointer;text-decoration:none;border:none;font-weight:normal;background-color:transparent;}',
               '#'+voco+' #'+voco+'_sh div{margin:0;padding:0;}',
               '#'+voco+' #'+voco+'_sh {text-align:left; width:' + $.a.w + 'px;background-color:#ccc;font:normal normal normal 12px/16px arial;padding: 1px;position:relative;}',
               '#'+voco+'.b #'+voco+'_sh{ padding-bottom:31px;}',
               '#'+voco+'.t #'+voco+'_merch,#'+voco+'.t #'+voco+'_about{margin-top:31px;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_main{width:' + $.a.w + 'px;overflow:hidden;position:relative;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_merch{width:' + merchBig + 'px;float:left;background-color:#eee;padding-top:10px;padding-bottom:2000px;margin-bottom:-2000px;text-align:center;}',
               '#'+voco+'.s #'+voco+'_sh #'+voco+'_merch{width:' + merchSmall + 'px;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_about{width:' + aboutBig + 'px;position:relative;float:left;background-color:#ddd;padding-bottom:2000px;margin-bottom:-2000px;}',
               '#'+voco+'.s #'+voco+'_sh #'+voco+'_about{width:' + aboutSmall + 'px;}',
               '#'+voco+' #'+voco+'_share{width:' + aboutBig + 'px;position:absolute;font-size:11px;right:1px;text-align:right;background-color:#ddd;}',
               '#'+voco+'.s #'+voco+'_share{width:' + aboutSmall + 'px;}',
               '#'+voco+' #'+voco+'_about a,#'+voco+' #'+voco+'_share a{color:#00458A;}',
               '#'+voco+' div#'+voco+'_buttons{z-index:2;margin-bottom:10px;padding:4px 0 0 0;}',
               '#'+voco+' div#'+voco+'_buttons.p{margin-bottom:18px;}',
               '#'+voco+' #'+voco+'_cust a,#'+voco+' #'+voco+'_merch a#'+voco+'_preview{color:#fff;display:inline-block;height:20px;line-height:20px;font-size:13px;font-weight:bold;color:#fff;width:100%;background-image:url(http://jsapi.netflix.com/us/api/w/s/i/b.gif);background-image-repeat:repeat-x;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add{background-color:#900;background-position:0 -8px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_add:hover{background-color:#b71e1e;background-position:0 -40px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save{background-color:#688507;background-position:0 -136px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_save:hover{background-color:#8bb109;background-position:0 -168px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_play,#'+voco+' #'+voco+'_cust a#'+voco+'_later{background-color:#004073;background-position:0 -72px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_play:hover,#'+voco+' #'+voco+'_cust a#'+voco+'_later:hover{background-color:#1d5d90;background-position:0 -112px;}',
               '#'+voco+' #'+voco+'_cust a#'+voco+'_later{display:none;left:-1px;position:absolute;top:20px;height:20px;width:112px;z-index:3;}',
               '#'+voco+' #'+voco+'_cust,#'+voco+' #'+voco+'_merch a#'+voco+'_preview{position:relative;width:110px;display:inline-block;border:1px solid #666;}',
               '#'+voco+' #'+voco+'_cust{z-index:2;}',
               '#'+voco+' #'+voco+'_merch a#'+voco+'_preview{background-color:#333;background-position:0 -200px;margin-top:2px;}',
               '#'+voco+' #'+voco+'_merch a#'+voco+'_preview:hover{background-color:#777;background-position:0 -234px;}',
               '#'+voco+'.s #'+voco+'_merch a#'+voco+'_later{top:17px;height:17px;left:-10px;width:84px;}',
               '#'+voco+'.s #'+voco+'_cust,#'+voco+'.s #'+voco+'_merch a#'+voco+'_preview{width:64px;}',
               '#'+voco+'.s #'+voco+'_sh #'+voco+'_cust a,#'+voco+'.s #'+voco+'_sh #'+voco+'_merch a#'+voco+'_preview{font-size:11px;height:17px;line-height:17px;}',
               '#'+voco+'.k #'+voco+'_cust a#'+voco+'_add,#'+voco+'.k #'+voco+'_cust a#'+voco+'_play,#'+voco+'.k #'+voco+'_cust a#'+voco+'_save{width:50%;}',
               '#'+voco+' #'+voco+'_box{display:block;height:150px;width:112px;padding:0;margin:0 auto;}',
               '#'+voco+' #'+voco+'_box img#'+voco+'_art{margin:0;padding:0;border:1px solid #666;}',
               '#'+voco+'.s #'+voco+'_box{height:90px;width:66px;}',
               '#'+voco+' #'+voco+'_sh #'+voco+'_text{margin:5px 10px;}',
               '#'+voco+' #'+voco+'_share {margin:5px 10px;}',
               '#'+voco+' #'+voco+'_about #'+voco+'_titl{font-weight:bold;}',
               '#'+voco+' #'+voco+'_about #'+voco+'_synopsis,#'+voco+' #'+voco+'_about #'+voco+'_info{font-size:11px;}',
               '#'+voco+'.t #'+voco+'_sh #'+voco+'_text{margin-bottom:20px;}',
               '#'+voco+'.b #'+voco+'_sh #'+voco+'_text{margin-top:20px }',
               '#'+voco+' #'+voco+'_share a#'+voco+'_get{display:block;text-align:left;margin-left:10px;}',
               '#'+voco+'.b #'+voco+'_share a#'+voco+'_get{text-align:right;}',
               '#'+voco+' #'+voco+'_share span{color:#666;float:right;margin-left:10px;padding:0 3px;font-size:11px;height:18px;line-height:18px;background-color:#fff;}',
               '#'+voco+' #'+voco+'_share a#'+voco+'_fb,#'+voco+' #'+voco+'_share a#'+voco+'_tw{float:right;width:18px;height:18px;background:#fff url(http://l.yimg.com/a/i/us/mbl/services/ifacebook.png) 1px 1px no-repeat;margin-left:1px;}',
               '#'+voco+' #'+voco+'_share a#'+voco+'_tw{float:right;background-image:url(http://l.yimg.com/a/i/us/mbl/services/itwitter.png);}',
               '#'+voco+'.b #'+voco+'_share{top:1px;}',
               '#'+voco+'.t #'+voco+'_share{bottom:1px;}',
               '#'+voco+' #'+voco+'_banner{width:' + $.a.w + 'px;position:absolute;left:1px;height:30px;background:#B9090B url(http://jsapi.netflix.com/us/api/images/buttons/n_small.png) no-repeat 5px 50%;color:#fff;}',
               '#'+voco+'.t #'+voco+'_banner{top:1px;}',
               '#'+voco+'.b #'+voco+'_banner{bottom:1px;}',
               '#'+voco+' #'+voco+'_banner #'+voco+'_logo{display:block;height:30px;width:60px;text-indent:-8675309px;}',
               '#'+voco+' #'+voco+'_trial{position:absolute;top:5px;right:5px;color:#fff;font-weight:bold;}',
               '#'+voco+' #'+voco+'_trial span{white-space:pre;display:inline-block;padding:0 5px;background:#0271C0 url(http://jsapi.netflix.com/us/api/w/s/i/t.jpg) repeat-x scroll 0 0;color:#fff;font-size:11px;height:18px;line-height:18px;border:1px solid #fff;}',
               '#'+voco+' .x{display:none!important;}'
            ];
            var r = rules.join("\n") + $.k.standardRules.join("\n");
            var css = document.createElement('STYLE');
            css.className = 'netflix-generated-style';
            css.type = 'text/css';
            if (css.styleSheet) { css.styleSheet.cssText = r;} else { css.appendChild(document.createTextNode(r));}
            document.getElementsByTagName('HEAD')[0].appendChild(css);              
            var trial = "FREE TRIAL <span>Click Here</span>"; 
            var struc = $.f.fiat({"DIV":{"id":voco + "_sh"}}); 
            var main = $.f.fiat({"DIV":{"id":voco + "_main"}});
               var merch = $.f.fiat({"DIV":{"id":voco + "_merch"}});
                  var box = $.f.fiat({"A":{"id":voco + "_box", "href":$.a.data.web_page}});
                     var art = $.f.fiat({"IMG":{"id":voco + "_art", "src": $.a.data.box_art }});
                     box.appendChild(art);
                  merch.appendChild(box);
                  var buttons = $.f.fiat({"DIV":{"id":voco + "_buttons"}});
                     var cust = $.f.fiat({"DIV":{"id":voco + "_cust"}});
                        $.s.save = $.f.fiat({"A":{"id":voco + "_save", "innerHTML":"Save", "href":"#"}});
                        if (!$.a.data.avail.save || $.a.supp.s) { $.s.save.className = 'x'; } 
                        cust.appendChild($.s.save);
                        $.s.add = $.f.fiat({"A":{"id":voco + "_add", "innerHTML":"Add"}});
                        cust.appendChild($.s.add);
                        if (!$.a.data.avail.disc || $.a.supp.d) { $.s.add.className = 'x'; } else { if ($.s.save.className !== 'x') { $.s.className = 'k'; } }
                        $.s.play = $.f.fiat({"A":{"id":voco + "_play", "innerHTML":"Play", "href":"#"}});
                        cust.appendChild($.s.play);
                        if (!$.a.data.avail.play || $.a.supp.p) { $.s.play.className = 'x'; } else { if ($.s.save.className !== 'x' || $.s.add.className !== 'x') { $.s.className = 'k'; } }
                        $.s.later = $.f.fiat({"A":{"id":voco + "_later", "innerHTML":"Add to Instant", "href":"#"}});
                        cust.appendChild($.s.later);
                        if (!$.a.data.avail.later || $.a.supp.l) { $.s.later.className = 'x'; }
                        buttons.appendChild(cust);
                     $.s.preview = $.f.fiat({"A":{"id":voco + "_preview", "innerHTML":"Preview", "href":"#"}});
                     if (!$.a.data.preview || $.a.supp.v ) { $.s.preview.className = 'x'; }
                     buttons.appendChild($.s.preview);
                     // if we are going to show the "later" button AND have no preview button, we need 5px more margin-bottom
                     if ($.a.data.avail.later && !$.a.supp.p && !$.a.supp.l) {
                        if (!$.a.data.avail.preview || $.a.supp.v) {
                           buttons.className = 'p';
                        }
                     }
                  merch.appendChild(buttons);
               main.appendChild(merch);
               var about = $.f.fiat({"DIV":{"id":voco + "_about"}});
                  var text = $.f.fiat({"DIV":{"id":voco + "_text"}});
                     $.s.titl = $.f.fiat({"A":{"id":voco + "_titl", "innerHTML":$.a.data.title, "href":$.a.data.web_page}});
                     text.appendChild($.s.titl);
                     $.s.info = $.f.fiat({"DIV":{"id":voco + "_info", "innerHTML":$.a.data.info }});
                     if ($.a.supp.i) { $.s.info.className = 'x'; }
                     text.appendChild($.s.info);
                     $.s.synopsis = $.f.fiat({"DIV":{"id":voco + "_synopsis", "innerHTML":$.a.data.synopsis }});
                     text.appendChild($.s.synopsis);
                  about.appendChild(text);
               main.appendChild(about);
            struc.appendChild(main);
            var banner = $.f.fiat({"DIV":{"id":voco + "_banner"}});
               $.s.trial = $.f.fiat({"A":{"id":voco + "_trial", "href":$.k.freeTrialUrl, "innerHTML": trial}});
               if ($.a.supp.f) { $.s.trial.className = 'x'; }
               banner.appendChild($.s.trial);
               var logo = $.f.fiat({"A":{"id":voco + "_logo", "innerHTML":"Netflix", "href":"http://www.netflix.com"}});
            banner.appendChild(logo);
            struc.appendChild(banner);
            $.s.share = $.f.fiat({"DIV":{"id":voco + "_share"}});
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_tw", "href":"http://twitter.com/home?status=" + encodeURIComponent($.a.data.title) + "%20on%20Netflix%3a%20http%3a%2f%2fmovi.es%2f" + $.a.id }}));
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_fb", "href":"http://www.facebook.com/share.php?u=" + encodeURIComponent($.a.data.web_page) }}));
               $.s.share.appendChild($.f.fiat({"SPAN":{"innerHTML":"share"}}));
               $.s.share.appendChild($.f.fiat({"A":{"id":voco + "_get", "innerHTML": "get this widget", "href":$.k.widgetBuilder + $.a.id}}));
            struc.appendChild($.s.share);   
            $.s.id = voco;
            $.s.appendChild(struc);
            if ($.a.s === 's') { $.s.className += ' s'; }
            if ($.a.q) { $.s.className += ' b'; } else { $.s.className += ' t'; }
            $.f.acti();
         },
         // create the iframe
         aedi: function() {
            // CRITICAL: don't do this if it's already here!
            if ($.d.getElementById('NFLXFRAME')) {
               // found it in existing structure; set a pointer so we can get to it from here
               $.i = $.d.getElementById('NFLXFRAME').parentNode;
            } else {
               // build it
               $.i = $.f.fiat({"DIV":{"className":"nflx-iframe-container","style":{"display":"none"}}});
               $.d.b.appendChild($.i);             
               $.i.shadow = $.f.fiat({"DIV":{"className":"nflx-iframe-shadow"}});
               $.i.appendChild($.i.shadow);
               $.i.iframe = $.f.fiat({"IFRAME":{"className":"nflx-iframe"}});
               $.i.iframe.setAttribute('frameBorder', '0');
               $.i.iframe.scrolling = 'no';
               $.i.iframe.name = $.i.iframe.id = $.k.frameName;
               $.i.appendChild($.i.iframe);
               $.i.x = $.f.fiat({"A":{"className":"nflx-iframe-close","onclick":function() { $.f.occu(); } }});
               $.i.appendChild($.i.x);
            }
         },
         // show the iframe
         exhi : function(action) {
            // where shall we put that iframe?
            var ww = 0;
            var wh = 0;
            var wx = 0;
            var wy = 0;
            if (!$.w.innerWidth) {
               ww = $.d.b.clientWidth;
               wh = $.d.b.clientHeight;
               wx = $.d.b.scrollLeft;
               var scrollTop = $.d.documentElement.scrollTop ? $.d.documentElement.scrollTop : $.d.b.scrollTop;
               wy = scrollTop;
            } else {
               ww = $.w.innerWidth;
               wh = $.w.innerHeight;
               wx = $.w.pageXOffset;
               wy = $.w.pageYOffset;
            }
            var f = $.s;
            var x = 0;       
            var y = 0;
            do {
               y += f.offsetTop;
               x += f.offsetLeft;
               f = f.offsetParent;
            } while (f.offsetParent);
            var tx = x + $.a.x;
            var ty = y + $.a.y;
            if (tx < wx) { tx = wx + $.k.frameMargin; } else { if (tx + $.k.frameWidth > (ww + wx)) { tx = (wx + ww) - $.k.frameWidth; } }
            if (ty < wy) { ty = wy + $.k.frameMargin; } else { if (ty + $.k.frameHeight > (wh + wy)) { ty = (wh + wy) - $.k.frameHeight; } }
            $.i.style.top = ty + 'px';
            $.i.style.left = tx + 'px';
            // default: add a disc
            var queue_type = 'disc';
            // or maybe add to instant
            if (action === 'later') { queue_type = 'instant'; }
            // $.a.k = developer key, for affiliate referrals
            $.i.iframe.src = 'http://widgets.netflix.com/addToQueue.jsp?output=json&devKey=' + $.a.k + '&queue_type=disc&movie_id=' + $.a.data.id;
            // show the frame
            $.i.style.display = 'block';
            // start checking for frame close
            $.a.frameChecker = $.w.setInterval($.f.cave, 200);
         },     
         // guard the iframe
         cave : function() {
            // there's no school like the old school....
            var f = ( $.d.frames || $.w.frames );
            if (f && f[$.k.frameName] && f[$.k.frameName].frames.length) {
               $.w.clearInterval($.a.frameChecker);
               $.f.occu();
            }
         },
         // hide the iframe -- also called when someone clicks the X button
         occu : function() {
            $.i.style.display = 'none';
            $.i.iframe.src = null;
         },
         // show previews
         spec : function() {
            var ave = voco + '.f.prop';
            var req = $.a.data.preview + '?output=json&callback=' + ave;
            $.f.prop = function(r) { 
               if (r && r.previews && r.previews.preview && r.previews.preview.stream) {
               var s = r.previews.preview.stream;
                  var url = '';
                  var height = 0;
                  var width = 0;
                  for (var i = 0; i < s.length; i++) {
                     if (s[i].category[0].term === 'flv') {
                        url = s[i].link.href;
                        height = s[i].height - 0;
                        width = s[i].width - 0;
                        break;
                     }
                  }            
                  if (!url || !height || !width) { return; }
                  var mt = 0 - (height / 2);
                  var ml  = 0 - (width / 2);
                  var sm = { "407":133, "303":185, "331":166, "311":178, "247":235, "271":210 };
                  var pn = 133;
                  var t = sm[height + ''];
                  if (t) { pn = t; }
                  if ($.w.innerWidth) {
                     // DOM
                     $.i.pglass = $.f.fiat({"DIV":{"style":{"position":"fixed", "top":"0", "left":"0", "height":"100%","width":"100%","opacity":"0.95", "backgroundColor":"#000","zIndex":"8675312"}}});
                     $.i.ui = $.f.fiat({"DIV":{"style":{"position":"fixed","top":"50%","left":"50%","marginLeft":(ml - 2) + 'px',"marginTop":(mt - 32) + 'px', "zIndex":"8675313", "height":height + 32 + 'px',"width":width + 2 + 'px', "backgroundColor":"#ddd", "textAlign":"center" }}});
                  } else {
                     // IE
                     var scrollTop = $.d.documentElement.scrollTop ? $.d.documentElement.scrollTop : $.d.b.scrollTop;
                     $.i.pglass = $.f.fiat({"DIV":{"style":{"position":"absolute", "top":0, "left":0, "height":$.d.b.scrollHeight + 'px',"width":$.d.b.scrollWidth + 'px',"filter":"alpha(opacity=95)","backgroundColor":"#000","zIndex":"8675312"}}});
                     $.i.ui = $.f.fiat({"DIV":{"style":{ "position":"absolute","top":scrollTop  + (($.d.b.clientHeight / 2) - (t/2)) + "px", "left":$.d.b.scrollLeft  + ($.d.b.clientWidth / 2),"marginLeft":(ml - 2) + 'px',"marginTop":(mt - 32) + 'px', "zIndex":"8675313", "height":height + 32 + 'px', "width":width + 2 + 'px', "backgroundColor":"#ddd", "textAlign":"center" }}});                  
                  }
                  $.d.b.appendChild($.i.pglass);
                  $.i.uix = $.f.fiat({"A":{"innerHTML":"close", "onclick": function() { $.f.abol($.i.ui); $.f.abol($.i.pglass); }, "style":{ "display":"block","font":"normal 12px/30px arial, helvetica, sans-serif","height":"30px", "paddingRight":"5px", "margin":"1px 1px 0","background":"#b9090b url(http://jsapi.netflix.com/us/api/images/buttons/n_small.png) 5px 5px no-repeat", "textAlign":"right", "textDecoration":"none", "color":"#fff", "cursor":"pointer" }}});
                  $.i.ui.appendChild($.i.uix);               
                  $.i.player = $.d.createElement('EMBED');
                  $.i.player.src = 'http://screeningcdn.nflximg.com/us/flash/v3Player/' + pn + '.swf?bl=' + encodeURIComponent(url);
                  $.i.player.height = height;
                  $.i.player.width = width;
                  $.i.player.flashvars = 'ptCell=-1';
                  $.i.player.wmode = 'transparent';
                  $.i.player.quality = 'high';
                  $.i.player.bgcolor = '#a00';
                  $.i.player.name = 'flashpcontentObj';
                  $.i.player.id = 'flashpcontentObj';
                  $.i.player.type = 'application/x-shockwave-flash';
                  $.i.ui.appendChild($.i.player);
                  $.d.b.appendChild($.i.ui);
               }
               $.f.abol(voco + '.f.prop');
            };        
            $.d.b.appendChild($.f.fiat({"SCRIPT":{"id":ave, "charset":"utf-8", "type":"text/javascript", "src":req}}));
         },
         // create an element
         fiat: function(o) {
            var el = null;
            if (typeof o === 'object') {
               for (var t in o) {
                  if (o[t].hasOwnProperty) {
                     try {
                        el = $.d.createElement(t);
                        for (var a in o[t]) { if (typeof o[t][a] === 'string' || typeof o[t][a] === 'function') { try{ el[a] = o[t][a]; } catch (err1) { } } else { if (typeof o[t][a] === 'object') { for (var v in o[t][a]) { if (o[t][a][v].hasOwnProperty) { try { el[a][v] = o[t][a][v]; } catch (err2) { } } } } } }
                     } catch (err3) {}
                     break;
                  }
               }
            } else { if (typeof o === 'string') { el = $.d.createElement(o); } }
            if (typeof el === 'object' && el.tagName) { return el; } else { return false; }
         },
         // destroy an element
         abol: function(o) {
            var e = o;
            if (typeof o === 'string') { e = $.d.getElementById(o); }
            if (e && e.parentNode) { e.parentNode.removeChild(e); } 
         },
         // sieve input from a single string into key/value pairs and return an object
         crib : function (input) {
            var args, pairs, i, query, key, value, temp, text;
            args = {};
            // require input to be string, not object
            if (typeof input === 'string') {               
               text = $.w.unescape(input);
               pairs = text.split('&');
               for (i = 0; i < pairs.length; i = i + 1) {
                  query = pairs[i].split('=');
                  key = query[0];
                  value = query[1];
                  // we see a second value for k, so turn it into an array
                  if (typeof args[key] === 'string') {
                     temp = args[key];
                     args[key] = [];
                     args[key][0] = temp;
                  }
                  if (typeof args[key] === 'object' && args[key].length) {
                     // is args[key] an array? add value
                     args[key][args[key].length] = value;
                  } else {
                     // args[key] takes value as a string
                     args[key] = value;
                  }
               }
            }
            return args;
         }
      };
   }();
   var hinc = /^http:\/\/jsapi.netflix.com\/us\/api\/w\/s\/sp100.js/;
   var hinc = /sp100.js/;
   $.f.init(hinc);
})(window, document);