////////////////////////////
//  MOD: James Colby      //
//  Quick & Easy PNG Fix  /
////////////////////////////
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

//***********************************************************************************************************************************/
//	AFNBox
//
//	 Author: James Colby, America's Firearm Network
//  Website: http://www.1911.COM
//	   Date: May 25, 2009
//  © America's Network, Inc. ALL RIGHTS RESERVED.
//
//***********************************************************************************************************************************/

var max_height = 600;
var steps = 20;



function isMSIE() {
  return '\v' == 'v';
}

function afn_init(thesrc, max_height, max_width, steps, opacity, htitle) {  
  afn_load(thesrc, max_height, max_width, htitle);
  afn_expand(max_height, max_width, steps);
  //afn_fade(opacity);
}

var fadecount=1;
function afn_load(thesrc, max_height, max_width, htitle) {
  if(document.getElementById("afn_inner")) {
    scroll_val = document.getElementsByTagName('body')[0].scrollTop;
    window_val = document.body.clientHeight;
  
    offset = Math.round((window_val - max_height)/2);
    if (offset > 0) {
      scroll_val = scroll_val+offset;
    }
    document.getElementById('afn_inner').style.marginLeft = '-'+(Math.round(max_width/2))+'px';
    document.getElementById('afn_inner').style.width = max_width+'px';  
    document.getElementById('afn_inner').style.height = max_height+'px';
    document.getElementById('afn_inner').style.top = (scroll_val+37)+'px';
    document.getElementById('afn_outer').style.top = (scroll_val)+'px';
    document.getElementById('afn_outer').style.display = 'block';
    document.getElementById('pane_header').innerHTML = htitle.replace(" ", "&nbsp;");
    
    frame_con = "  <iframe id='afn_frame' height="+(parseInt(max_height)-5)+" width="+(parseInt(max_width)-30)+" scrolling='yes' name='afn_frame' src='"+thesrc+"'>";
  
    
    document.getElementById('afn_inner').innerHTML = frame_con;
    document.getElementById("afnbox").style.height = document.body.scrollHeight+'px';
    document.getElementById("afnbox").style.width = document.body.scrollWidth+'px';
    document.getElementById("fadebox").style.height = document.body.scrollHeight+'px';
    document.getElementById("fadebox").style.width = document.body.scrollWidth+'px';
    if (isMSIE() == true) {
      //is internet exploder, do not fade or it will slow down 50000%
    } else {
      //is not internet explorer. We can fade the background.
      var ab_f=setTimeout('afn_fade();', 500);
      fadecount = 1;
    }
    document.getElementById("fadebox").style.display = "block";
    document.getElementById('afnbox').style.display='block';

    document.getElementById('afn_loading').style.backgroundImage = "url(http://www.1911.com/images/rendering_back.png)";

  } else {
   // set timeout and try again
   setTimeout('afn_load("'+thesrc+'", "'+max_height+'", "'+max_width+'", "'+htitle+'");', 1500); 
  }
}

function afn_expand(max_height, max_width, steps) {
  clearTimeout(ab_t);
  current_height = document.getElementById('afn_outer').style.height.replace(/([px;]*)/g, "");
  current_width = document.getElementById('afn_outer').style.width.replace(/([px;]*)/g, "");
  if (isMSIE() == true) {
    //just open window, don't animate - speeds up
    the_height = max_height+'px';
    inner_height = Math.round(max_height-24)+'px';
    document.getElementById('afn_outer').style.height = the_height;
    the_width = max_width+'px';
    the_margin = Math.round(max_width/2)+'px';
    document.getElementById('afn_outer').style.width = the_width;
    document.getElementById('afn_outer').style.marginLeft = '-'+the_margin;
    document.getElementById('afn_inner').style.display = 'block';
    var ab_f2=setTimeout('afn_inner("20");', 500);
  } else {
    //animate
    if (parseInt(current_height, 10) < max_height) {
      new_height = Math.round(parseInt(current_height, 10)+steps);
      if (new_height > max_height) {
        new_height = max_height;
      }
      the_height = new_height+'px';
      inner_height = Math.round(new_height-24)+'px';
      document.getElementById('afn_outer').style.height = the_height;
      /*document.getElementById('afn_inner').style.height = the_height;*/
    }
    if (parseInt(current_width, 10) < max_width) {
      new_width = Math.round(parseInt(current_width, 10)+steps);
      if (new_width > max_width) {
        new_width = max_width;
      }
      the_width = new_width+'px';
      the_margin = Math.round(new_width/2)+'px';
      document.getElementById('afn_outer').style.width = the_width;
      document.getElementById('afn_outer').style.marginLeft = '-'+the_margin;
    }
    
    if (parseInt(new_width, 10) < max_width || parseInt(new_height, 10) < max_height) {
      //call self
      var ab_t=setTimeout('afn_expand('+max_height+', '+max_width+', '+steps+');', 1);
      //afn_expand(max_height, max_width, steps);    
    } else {
      document.getElementById('afn_inner').style.display = 'block';
      var ab_f2=setTimeout('afn_inner("20");', 500);
    }
  }
}

function afn_fade() {
  var opacity = 25*(fadecount);
  object = document.getElementById('fadebox').style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
  document.getElementById("fadebox").style.background = "#000000";
  if (opacity > 60) {
    clearTimeout(ab_f);    
  } else {
    fadecount++;
    ab_f=setTimeout('afn_fade();', 200);
  }
}

function afn_inner(opacity) {
  object = document.getElementById('afn_inner').style;
  object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
  if (opacity >= 100) {
    clearTimeout(ab_f2);
    document.getElementById('afn_back').display = 'none';
  } else {
    opacity = opacity+20;
    ab_f2=setTimeout('afn_inner('+opacity+');', 500);
  }
}

function afn_close() {
  document.getElementById('afnbox').style.display='none';
  document.getElementById('fadebox').style.display='none';
  document.getElementById("fadebox").style.background = "none";
  //document.getElementById('fadebox1').style.display='none';
  //document.getElementById('fadebox2').style.display='none';
  //document.getElementById('fadebox3').style.display='none';
  document.getElementById('afn_inner').innerHTML = '';
  document.getElementById('afn_outer').style.height='20px';
  document.getElementById('afn_outer').style.width='20px';
  document.getElementById('afn_inner').style.display = 'none';
  object = document.getElementById('afn_inner').style;
  object.opacity = 0;
	object.MozOpacity = 0;
	object.KhtmlOpacity = 0;
	object.filter = "alpha(opacity=0)";
   
}