/**
 * Title:        IBSYS JavaScript Architecture
 * Description:  EasyTag builds iframe containing IB content. It uses a config
 *               which runs ESI to capture content in query string
 * Company:      Internet Broadcasting Systems, Inc.
 * Copyright:    Copyright 2007
 */
/* 
 * Output content based on query string method parameter
 */
(function(){
	/* Browser detection copied from YUI/build/yahoo/yahoo.js */
  var o={
      ie:0,
      opera:0,
      gecko:0,
      webkit: 0,
      mobile: null,
      air: 0
  };

  var ua=navigator.userAgent, m;

  // Modern KHTML browsers should qualify as Safari X-Grade
  if ((/KHTML/).test(ua)) {
      o.webkit=1;
  }
  // Modern WebKit browsers are at least X-Grade
  m=ua.match(/AppleWebKit\/([^\s]*)/);
  if (m&&m[1]) {
      o.webkit=parseFloat(m[1]);

      // Mobile browser check
      if (/ Mobile\//.test(ua)) {
          o.mobile = "Apple"; // iPhone or iPod Touch
      } else {
          m=ua.match(/NokiaN[^\/]*/);
          if (m) {
              o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
          }
      }

      m=ua.match(/AdobeAIR\/([^\s]*)/);
      if (m) {
          o.air = m[0]; // Adobe AIR 1.0 or better
      }

  }

  if (!o.webkit) { // not webkit
      // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
      m=ua.match(/Opera[\s\/]([^\s]*)/);
      if (m&&m[1]) {
          o.opera=parseFloat(m[1]);
          m=ua.match(/Opera Mini[^;]*/);
          if (m) {
              o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
          }
      } else { // not opera or webkit
          m=ua.match(/MSIE\s([^;]*)/);
          if (m&&m[1]) {
              o.ie=parseFloat(m[1]);
          } else { // not opera, webkit, or ie
              m=ua.match(/Gecko\/([^\s]*)/);
              if (m) {
                  o.gecko=1; // Gecko detected, look for revision
                  m=ua.match(/rv:([^\s\)]*)/);
                  if (m&&m[1]) {
                      o.gecko=parseFloat(m[1]);
                  }
              }
          }
      }
  }
  /* End YUI browser detection */
	
	
/*!*/
	var subdomain= 'www' || 'www';
	var site     = 'wftv.com' || 'IBATOM.com';
	var section  = '_embeddablecontent' || 'widget';
	var pagetype = '' || 'index';
	var target   = '' || '_blank';
	var dm       = '';
	var css      = ''.split('|');
	var custid   = '0';
	var coid     = '1815457';
	var ownerDoc = ('t' == "t" ? "&owner="+window.location : "");
	var category = 'localNews';
	/* 
	 * iframe settings
	 */
	var width    = '220' || 300;
	var height   = '300' || 350;
	var scroll   = '' || "no";
	var fborder  = '' || "0";
	var trans    = '' || "true";
	var klass    = '';
/*!*/
	
	for (var i=0; i<css.length;i++) {
		if (css[i]) {
			dm += "css=" + css[i] + ";";
		}
	}
	
	custid = (custid && custid !== '0' ? escape(custid) + ',' : "");
	var site = 'http://' + subdomain + '.' + site; //use in iframe source
/*!
		
				*/
						var path = '/' + section + '/' + pagetype + '.html' ;
						var qs = '?layoutname=5header_blueSolid&coid=' + custid + escape(coid) + ownerDoc + "&category=" + category;
					/*!*/
					var source = site + path + qs;
					var cleanCoid = coid.replace(/;/g,'-');
					
					/** I hope isGecko is only needed because of bugs in FireBug 1.3.1b4.
					 *  For some reason placing the right-hand side of the equation in the
					 *  if statement below causes execution to step into the else block.
					 *  Watching the expression returns true.
					 */
					var isGecko = o.gecko > 0 && o.gecko < 1.9;
					
					if (isGecko) { /* See bugzillas below. This work-around breaks the back button in IE. */
						var uniqueVal = Math.random(new Date().getTime());
						
						var frame = '<iframe id="et' + cleanCoid + '-' + uniqueVal + '" src="' + site + '/sh/images/structures/spacer.gif" width="' + width + '" height="' + height +
						'" allowtransparency="' + trans + '" ' + 'class="' + klass + ' IBATOM-synd-ifr ' +
						custid + '-' + cleanCoid + '" scrolling="' + scroll + '" frameborder="' + fborder + '">' +
						'</iframe>';
				
						document.write(frame);
						/* suppress iframe switcharoo
						 * https://bugzilla.mozilla.org/show_bug.cgi?id=363840
						 * https://bugzilla.mozilla.org/show_bug.cgi?id=279048
						 */
						document.getElementById('et' + cleanCoid + '-' + uniqueVal).src = source;
						
					} else {
						var frame = '<iframe src="' + source + '" width="' + width + '" height="' + height +
						'" allowtransparency="' + trans + '" ' + 'class="' + klass + ' IBATOM-synd-ifr ' +
						custid + '-' + cleanCoid + '" scrolling="' + scroll + '" frameborder="' + fborder + '">' +
						'</iframe>';
				
						document.write(frame);
					}
					
			/*!
	*/
})();

