//JavaScript for DecorPlastics propriatary API
//
// written by AlexNa

var MORE_PHOTOS_ID = "product_photo_zoom_url";
var MORE_PHOTOS_ID2 = "product_photo_zoom_url2";
var ALTERNATIVE_PHOTO_VIEW = "/v/vspfiles/templates/PlanetOwn/more_photos.html";


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function changePhotoView( product_code, product_name )
{
	var a = document.getElementById( MORE_PHOTOS_ID );
	a.href = 
		"javascript:" + 
		"OpenNewWindow('" + ALTERNATIVE_PHOTO_VIEW + "?" + 
		escape(product_code) + '&' + escape( product_name ) + "'" + 
		", 798, 644);";
		
	var a2 = document.getElementById( MORE_PHOTOS_ID2 );
	a2.href = a.href;
}

function initImageViewer()
{
      document.write( "<div id=image_viewer_frame><a href=\"javascript:closeImageViewer();\"><img src='/v/vspfiles/assets/images_template/btn_21x114b_close_window.gif'><br><br><img id=image_viewer_image></a></div>");
}

function closeImageViewer()
{
      var fr = document.getElementById( "image_viewer_frame"  );
      fr.style.visibility = "hidden";
}

function imageViewerImageLoaded()
{
      var im = document.getElementById( "image_viewer_image"  );
      var fr = document.getElementById( "image_viewer_frame"  );

      // get window size
      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
  
	  fr.style.left = ( ( myWidth - im.width - 96 ) / 2 ) + "px";
	  
	  var t = ( ( myHeight - im.height - 96 ) / 2 );
	  if( t < 20 ) t = 20;
	  fr.style.top = t + getScrollXY()[1] + "px";
	  
	  fr.style.visibility = "visible";

}

function showImage( img )
{
      var im = document.getElementById( "image_viewer_image"  );
      im.onload=imageViewerImageLoaded;
      im.src = img;
}
