function newImage(arg) {
	if (document.images) {
		sts = new Image();
		sts.src = arg;
		return sts;
	}
}



function enlarger(image){
	var theImg = new Image();
       	theImg.src = image;
	var defaultWidth = theImg.width;
   	var defaultHeight = theImg.height;	
	var PositionTop = 100;
	var PositionLeft = Math.round((screen.width - defaultWidth) / 2);
	var isIE = true;
	var optIE='scrollbars=no,width=300,height=300,left='+PositionLeft+',top='+PositionTop;

	var imageTitle = "Photo Rescuer - Enlarged Photograph";
	imgWin=window.open('about:blank','',optIE);
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
		writeln('width=300-(document.body.clientWidth-document.images[0].width);');
		writeln('height=300-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		writeln('</head><body bgcolor=c0c0c0 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+image+' style="display:block"></body></html>');
		close();		
	}
}

 function enlarge(jpg1){
   var theImg = new Image();
       theImg.src = jpg1;
   var imgw = theImg.width;
   var imgh = theImg.height;
    imgw = imgw + 10;
    imgh = imgh + 5;
    var l = Math.round((screen.width - imgw) / 2);
    t = 0;
    var options= ' menubar=0, status=0, location=0, resizable=0, titlebar=0, toolbar=0';
    var str = "width=" + imgw + " height=" + imgh;

     var ImgWin = window.open('','imgwin',config='height='+imgh+',width='+imgw+',top='+t+',left='+l + options)
       with(ImgWin.document){
        writeln('<html><head><title>Photo Rescuer - Enlargement</title></head>');
	  	writeln ("<!--[if lt IE 7.]>");
	  	writeln ("<script defer='' src='pngfix.js' type='text/javascript'></script>");
	  	writeln ("<![endif]-->");
       	write   ('<body onload="self.focus()" onblur="self.close()" style="margin: 0; padding: 0;"');
	  	writeln (" background='images/gray_shift.png'>");
        writeln('<div style="text-align:center">');
        writeln('<img src='+jpg1+' ></div>');
        writeln('<div style="text-align:center;">');
        writeln('</div></body></html>');
        close();
       }
  }
  
  function swapImages() {
	if (document.images && (LoadedFlag == true)) {
		for (var i=0; i<swapImages.arguments.length; i+=2) {
			document[swapImages.arguments[i]].src = swapImages.arguments[i+1];
		}
	}
}

function beforeafter (jpg1, jpg2) {
	var options;
	
   	var img1 = new Image();
      img1.src = jpg1;
   	var imgw1 = img1.width;
   	var imgh1 = img1.height;

   	var img2 = new Image();
      img2.src =  jpg2;
   	var imgw2 = img2.width;
   	var imgh2 = img2.height;
   	
	var iheight = img1.height;
	/* 
	if (img2.height > img1.height) 
		{
		iheight = iheight + (img2.height - img1.height);
      	}
	*/
	var widthboth = img1.width + img2.width + 40;
	iheight = img2.height;
	if (iheight < img1.height) 
		iheight = img1.height;
	
	iheight = iheight + 25;

	var Xcor = ((screen.width-(widthboth))/2); 
	if (Xcor < 0) Xcor = 0;
  	Ycor = 0;

	options = 'height=' + iheight + ' , width=' + widthboth + ' , ';
	options += 'top=' + Ycor + '  , ';
	options += 'left=' + Xcor + '  , ';
	options +=  ' menubar=0, status=0, location=0, resizable=0, titlebar=0, toolbar=0';
	newwin = window.open('',"", options);
	newwin.document.write ("<title>Photo Rescuer - Before and After Restoration</title>");
	newwin.document.write ("<body background='images/gray_shift.png'>");
	newwin.document.write ("<!--[if lt IE 7.]>");
	newwin.document.write ("<script defer='' src='pngfix.js' type='text/javascript'></script>");
	newwin.document.write ("<![endif]-->");
	newwin.document.write ("<div width=100%>");
	newwin.document.write ('<img src=' + jpg1 + ' style="padding-right:10px; margin-right:10px;">'); 
	newwin.document.write ('<img src=' + jpg2 + '>'); 
	newwin.document.write ("</div>"); 	
	newwin.document.close();
}


var LoadedFlag = false;
function preloadImages() {
	if (document.images) {
		len_b = newImage("http://www.photorescuer.com/llevin_o_hp.jpg");
		lev_a = newImage("http://www.photorescuer.com/llevin_r_hp.jpg");
		santa_a = newImage("http://www.photorescuer.com/WithSanta62_rs.jpg");
		santa_b = newImage("http://www.photorescuer.com/WithSanta62_os.jpg");
		levs_a = newImage("http://www.photorescuer.com/llevin_r_s.jpg");
		levs_b = newImage("http://www.photorescuer.com/llevin_r_sss.jpg");
		mgc_a = newImage("http://www.photorescuer.com/mgc_r_s.jpg");
		mgc_b = newImage("http://www.photorescuer.com/mgc_o_s.jpg");
		mlandfriend_a = newImage("http://www.photorescuer.com/mlandfriend_r_s.jpg");
		mlandfriend_b = newImage("http://www.photorescuer.com/mlandfriend_o_s.jpg");
		don_a = newImage("http://www.photorescuer.com/don_r_ss.jpg");
		don_b = newImage("http://www.photorescuer.com/don_o_ss.jpg");
		eyesopened_a = newImage("http://www.photorescuer.com/eyesopen_s.jpg")
		eyesopened_b = newImage("http://www.photorescuer.com/eyesopen_o.jpg")
		LoadedFlag = true;
	}
}

var ctr = 1;

function start () {
   	var theImg = new Image();
      theImg.src = "images/pr_logo_gray_trans3.png";

	preloadImages();
	checkIEVersion();
	/* swaplinksheets(); */
	/* fixIEQuotes(); */
	/* fixPNGALL (); */
}

function fixPNGALL () {
/*
 Correctly handle PNG transparency in Win IE 5.5 & 6.
*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
}

function swaplinksheets ()
{
  if (screen.width < 1024) 
	{
    		link1 = document.getElementsByTagName( "link" )[ 0 ];
    		link1.href = "styles/core-big.css";
    		link2 = document.getElementsByTagName( "link" )[ 1 ];
    		link2.href = "styles/pages-big.css";
	}
}

/*
 Correctly handle PNG transparency in Win IE 5.5 & 6.
*/
function fixPNG(myImage) 
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			var imgAttribs = img.attributes;
			for (var j=0; j<imgAttribs.length; j++)
			{
				var imgAttrib = imgAttribs[j];
				if (imgAttrib.nodeName == "align")
				{
					if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
					if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
					break
				}
			}
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + 
			imgStyle + ";"
			strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}

function checkIEVersion()
{
   var ver = getInternetExplorerVersion();
   if ( ver > -1 )
   {
      if ( ver == 6.0 ) 
    	  fixIEQuotes();
   }
}


function getInternetExplorerVersion()
{
   var rv = -1; 
   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;
}


/* Fix Quotes in IE6 */
function fixIEQuotes()
{
  var objQuotes = document.getElementsByTagName('q');
  var strOpen, strClose;

  for (var i=0; i<objQuotes.length; i++)
  {
    if (isNested(objQuotes[i]))
    {
      // Double-quotes
      strOpen = document.createTextNode('\u2018');
      strClose = document.createTextNode('\u2019');
    }
    else
    {
      // Single-quotes
      strOpen = document.createTextNode('\u201c');
      strClose = document.createTextNode('\u201d');
    }
    // Insert quotation marks around quote
    objQuotes[i].parentNode.insertBefore(strOpen, objQuotes[i]);
    objQuotes[i].appendChild(strClose);
  }

  objQuotes = null;
}

function isNested(objElement)
{
  var objParent = objElement;
  do // Check if nested quote
  {
    objParent = objParent.parentNode;
    if (objParent.tagName && objParent.tagName.toLowerCase() == 'q')
      return true;
  } while (objParent.parentNode);

  return false;
}
