// Snaphire Script Utilities

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function addIEResources() {
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        switch (ver) {
			case 9.0:
				try {
					$("#internal").addClass("ie9");
				}
                catch (e) { }
                break;
            case 8.0:
				try {
					$("#internal").addClass("ie8 ie9");
				}
                catch (e) { }
                break;
            case 7.0:
                try {
					$("#internal").addClass("ie7 ie8 ie9");
                }
                catch (e) { }
                break;
            case 6.0:
            case 5.0:
            case 4.0:
                try {
                	$("#internal").addClass("ie6 ie7 ie8 ie9");
                }
                catch (e) { }
				try {
					document.execCommand("BackgroundImageCache", false, true);
				} catch(e) {}
				break;
            default:
                break;
        }
    }
}

function addPNGfixer() {
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        switch (ver) {
			case 6.0:
            case 5.0:
            case 4.0:
                try {
                    document.write('<script type="text/javascript" src="/js/DD_belatedPNG.js"><\/script>');
                }
                catch (e) { }
                break;
            default:
                break;
        }
    }
}


function loadPNGfixes() {
	DD_belatedPNG.fix('img, #snaphire input, #snaphire select, #snaphire textarea, .wicket-modal .w_sh .w_left, .wicket-modal .w_sh .w_right, .wicket-modal .w_sh .w_top, .wicket-modal .w_sh .w_bottom, .wicket-modal .w_sh .w_topLeft, .wicket-modal .w_sh .w_topRight, .wicket-modal .w_sh .w_bottomRight, .wicket-modal .w_sh .w_bottomLeft, .wicket-modal .w_sh a.w_close, .wicket-modal .wicket-tree-content .line, .wicket-modal .wicket-tree-content .half-line, .wicket-modal .wicket-tree-content .junction-open, .wicket-modal .wicket-tree-content .junction-closed, .wicket-modal .wicket-tree-content .junction-corner, #snaphire .sh_SearchPanel .modalLink, #snaphire .drafts table tr td, #snaphire .submission table tr td, #snaphire table tbody tr td.data, .wicket-modal table tbody tr td.data, #snaphire table tbody tr.even .data, .wicket-modal table tbody tr.even .data, #snaphire table tbody tr.odd .data, .wicket-modal table tbody tr.odd .data, .modalLink, .icon, .textbox');
}

function addFlashTransparencyFix() {
	
	// Automatically 'detects' an embed tag and adds the 'wmode: transparent' attribute to it.
	// FIXES: Modal not appearing correctly over a flash element.
	
	for (var ems = document.embeds, i = 0, em; em = ems[i]; i++) {
		em.setAttribute('wmode', 'transparent');
		var nx = em.nextSibling, pn = em.parentNode;
		pn.removeChild(em);
		pn.insertBefore(em, nx);
	}
}

// USE: Call addFlashTransparencyFix(); in base template or on the page needed.
