 // Fallowing are The javaScript functions used in this js file
    
    // 1 Managing the tabs of the product layer
    // 2 On clicking the link,show the product layer
    // 3 On clicking the close button,hide the product layer
    // 4 Moving the product layer dynamically on the page
    // 5 On clicking the arrow on the layer,slide the div
    // 6 Function to fetch the data dynamically using controller  
    

//****************************************************************************************

// function to move the div(product layer) dynamically on the page
// Determine browser and version.
currentItemPL = 1 ;

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  //dragObj.elNode.style.zIndex = ++dragObj.zIndex; // Commented by Tejswita - to remove transperancy

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

//****************************************************************************************

// Function to manage the Tabs
function ManageTabPanelDisplay() {
//
// Between the parenthesis, list the id's of the div's that 
//     will be affected when tabs are clicked. List in any 
//     order. Put the id's in single quotes (apostrophes) 
//     and separate them with a comma -- all one line.
//
var idlist = new Array('tab1focus','tab2focus','tab1ready','tab2ready','content1','content2');

// No other customizations are necessary.
if(arguments.length < 1) { return; }
for(var i = 0; i < idlist.length; i++) {
   var block = false;
   for(var ii = 0; ii < arguments.length; ii++) {
      if(idlist[i] == arguments[ii]) {
         block = true;
         break;
         }
      }
   if(block) { document.getElementById(idlist[i]).style.display = "block"; }
   else { document.getElementById(idlist[i]).style.display = "none"; }
   }
}

var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}

// function to hide the Div(product layer)


// function to show the Div(product layer)
function showLayer(prodid,page) {
getProdInfo(prodid,page);
showQuickView();
  
}

// function to show the Div for Sale & shop page (product layer)
function showLayerSale(prodid,price,page) {
getProdInfoSale(prodid,price,page); 
showQuickView();
}

// function to show the Div for Web game (product layer)
function showLayerWeb(prodid,price,page,prodCnt) {
getProdInfoWeb(prodid,price,page,prodCnt); 
showQuickView();
}

function showQuickView()
{
	  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("QuickView")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("QuickView")');
  else
     document.poppedLayer = 
         eval('document.layers["QuickView"]');
         
  // to show the div on the center of the screen
  // *********************************************
  var IpopTop = ((screen.height - document.getElementById("QuickView").offsetHeight)/2) - (100 + 50);
  var IpopLeft = ((screen.width - document.getElementById("QuickView").offsetWidth)/2) - (75 + 10);

  document.getElementById("QuickView").style.left=IpopLeft + document.body.scrollLeft;
  document.getElementById("QuickView").style.top=IpopTop + document.body.scrollTop;
  // *********************************************         
  document.poppedLayer.style.visibility = "visible";
}

function show1() {
hide1();
	var obj1 = document.getElementById("viewLink");
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("view3d")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("view3d")');
  else
     document.poppedLayer = 
         eval('document.layers["view3d"]');
  document.poppedLayer.style.display = "block";
  
  //modified by liuxin 20080910
  //obj1.innerHTML="<a href=\"javascript:show2()\" value=\"show\" >Click Here for Image View</a>";
  obj1.innerHTML="<a href=\"javascript:show2()\" value=\"show\" >商品画像はこちら</a>";
}

function show2() {
hide2();
	var obj1 = document.getElementById("viewLink");
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("imgdiv")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("imgdiv")');
  else
     document.poppedLayer = 
         eval('document.layers["imgdiv"]');
  document.poppedLayer.style.display = "block";
  
  //modified by liuxin 20080910
  //obj1.innerHTML="<a href=\"javascript:show1()\" value=\"show\" >Click Here for 3D View</a>";
  obj1.innerHTML="<a href=\"javascript:show1()\" value=\"show\" >３Dビューはこちら</a>";
}

function hide() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("QuickView")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("QuickView")');
  else
     document.poppedLayer =   
        eval('document.layers["QuickView"]');
  document.poppedLayer.style.visibility = "hidden";
}

function hide1() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("imgdiv")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("imgdiv")');
  else
     document.poppedLayer =   
        eval('document.layers["imgdiv"]');
  document.poppedLayer.style.display = "none";
}

function hide2() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("view3d")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("view3d")');
  else
     document.poppedLayer =   
        eval('document.layers["view3d"]');
  document.poppedLayer.style.display = "none";
  
}

// Function for scrolling starts here
// *************************************************************************************
currentItemPL = 1 ;
function sliderProductLayer(direction){

	if(!scrollObjectsPL['slideshowpl'].isMoving){
	
		tempItem = currentItemPL + direction ;
		if (tempItem > 0 && tempItem <= slideShowItemsPL) {
			if (tempItem == 1){
			
				slideLeftButVarPL.style.display = "none" ;	
			} else {
			
				slideLeftButVarPL.style.display = "block" ;
			}
			if (tempItem == slideShowItemsPL){
			
				slideRightButVarPL.style.display = "none" ;
			} else {
				slideRightButVarPL.style.display = "block" ;
			}
			
			scrollObjectPL.plScrollBy('slideshowpl',-1*direction*liWidthPL,0);
			currentItemPL += direction;
		}
	}
}

scrollObjectsPL = {};
function scrollObjectPL(divId,iniX,iniY){
	this.id=divId;
	scrollObjectsPL[this.id]=this;
	this.animString="scrollObjectsPL."+this.id;
	this.plLoad(divId,iniX,iniY);
};


scrollObjectPL.prototype.plLoad=function(divId,iniX,iniY){

	if(!document.getElementById)return;
	var scrollingDivPL;

	this.scrollingDivPL=document.getElementById(divId);
	
	this.scrollingDivPL.style.top=this.y=iniY;
	this.scrollingDivPL.style.left=this.x=iniX;
	
	this.ready=true;
};


scrollObjectPL.plSlideDur = 500; // duration of glide

scrollObjectPL.plScrollBy = function(divId, x, y, dur, hideWhenStop) {
	if ( scrollObjectsPL[divId] ) scrollObjectsPL[divId].plGlideBy(x, y, dur, hideWhenStop);
}


scrollObjectPL.prototype.plGlideBy = function(dx, dy, dur, hideWhenStop) {
  if ( !document.getElementById || this.isMoving ) return;
  this.plSlideDur = dur || scrollObjectPL.plSlideDur;
  this.destX = this.destY = this.distX = this.distY = 0;
  this.startX = this.x; this.startY = this.y;
  
  this.distY = dy;
  this.distX = dx;
  
  this.destX = this.startX + this.distX; 
  this.destY = this.startY + this.distY;
  
  this.hideWhenStop = hideWhenStop ;
  
  this.isMoving = true;
  this.per = Math.PI/(2 * this.plSlideDur);
  this.slideStart = (new Date()).getTime();
  this.aniTimer = setInterval(this.animString + ".plDoSlide()",10);
}

scrollObjectPL.prototype.plDoSlide = function() {
	var elapsed = (new Date()).getTime() - this.slideStart;
	if (elapsed < this.plSlideDur) {
		var x = this.startX + this.distX * Math.sin(this.per*elapsed);
		var y = this.startY + this.distY * Math.sin(this.per*elapsed);
    this.plShiftTo(this.scrollingDivPL, x, y); 
	} else {
    clearInterval(this.aniTimer); this.isMoving = false;
	this.plShiftTo(this.scrollingDivPL, this.destX, this.destY);
		if (this.hideWhenStop){
			this.scrollingDivPL.style.visibility="hidden";
		}
	}
}

scrollObjectPL.prototype.plShiftTo=function(scrollingDivPL,x,y){
	if(!scrollingDivPL.style)return;
	scrollingDivPL.style.left=(this.x=x)+"px";
	scrollingDivPL.style.top=(this.y=y)+"px";
};

function initSlideshowProductLayer(itemWidth) {

	if(document.getElementById){
	
		slideShowListPL = document.getElementById('slideshowlistpl');
		
		slideShowItemsPL = 0 ;
	
		slideShowChildNodes = slideShowListPL.childNodes ;
	
		
		for (i=0; i<slideShowChildNodes.length; i++){
		
			if (slideShowChildNodes[i].nodeName == "LI") slideShowItemsPL++ ;
		}
		
		slideLeftButVarPL=document.getElementById('leftArrowpl');		
		slideRightButVarPL=document.getElementById('rightArrowpl');
		//var count = 0;
		//count = slideShowItemsPL;
		slideLeftButVarPL.style.display = "none" ;
		if (slideShowItemsPL == 1){
			
			slideRightButVarPL.style.display = "none" ;

		}
		var slideShowPL = new scrollObjectPL('slideshowpl', 0, 0);
		
		liWidthPL = itemWidth;
		
	} 	
}
//  ****************************************************************************************


// Function to call the controller and get the dynamic data
//  ****************************************************************************************
var reqProdInfo;
function getProdInfo(prodid,page){
	var QuickView = document.getElementById("QuickView");
	QuickView.innerHTML = "";
	var url = "/REST/viewproductinfogems.htm?productid="+prodid+"&addtocart=no&ouCode=GEM&pgname="+page+"";
	//var url = "viewproductinfogems.htm?productid=16036&addtocart=no&ouCode=GEM";
	if (window.XMLHttpRequest){
		reqProdInfo = new XMLHttpRequest(); 
	}else if (window.ActiveXObject){
		reqProdInfo = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	reqProdInfo.open("GET", url, true);
	reqProdInfo.onreadystatechange = callBackProductInfoGems;
	reqProdInfo.send(null);
}


function getProdInfoSale(prodid,price,page){
	var QuickView = document.getElementById("QuickView");
	QuickView.innerHTML = "";
	var url = "/REST/viewproductinfogems.htm?productid="+prodid+"&price="+price+"&addtocart=no&ouCode=GEM&pgname="+page+"";
	//var url = "viewproductinfogems.htm?productid=16036&addtocart=no&ouCode=GEM";
	if (window.XMLHttpRequest){
		reqProdInfo = new XMLHttpRequest(); 
	}else if (window.ActiveXObject){
		reqProdInfo = new ActiveXObject("Microsoft.XMLHTTP");
	}		
	reqProdInfo.open("GET", url, true);
	reqProdInfo.onreadystatechange = callBackProductInfoGems;
	reqProdInfo.send(null);
}

function getProdInfoWeb(prodid,price,page,prodCnt){
	var QuickView = document.getElementById("QuickView");
	QuickView.innerHTML = "";
	
	var url = "/REST/viewproductinfogems.htm?productid="+prodid+"&price="+price+"&prodCnt="+prodCnt+"&addtocart=no&ouCode=GEM&pgname="+page+"";
	//var url = "viewproductinfogems.htm?productid=08681&price=36350&prodCnt=2&addtocart=no&ouCode=GEM&pgname=WEB";
	if (window.XMLHttpRequest){
		reqProdInfo = new XMLHttpRequest(); 
	}else if (window.ActiveXObject){
		reqProdInfo = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	reqProdInfo.open("GET", url, true);
	reqProdInfo.onreadystatechange = callBackProductInfoGems;
	reqProdInfo.send(null);
}
 
function callBackProductInfoGems(){
	var QuickView = document.getElementById("QuickView");

	if (reqProdInfo.readyState == 4){
		if (reqProdInfo.status == 200){
			var l = reqProdInfo.responseText;
			// Html to be replaced with Div(QuickView)
			currentItemPL = 1 ;
			QuickView.innerHTML = l;
			initSlideshowProductLayer(250);	
			// To get the layer on the center of page
		    var IpopTop = ((screen.height - document.getElementById("QuickView").offsetHeight)/2) - (100 + 50);
		    var IpopLeft = ((screen.width - document.getElementById("QuickView").offsetWidth)/2) - (75 + 10);
		    document.getElementById("QuickView").style.left=IpopLeft + document.body.scrollLeft;
		    document.getElementById("QuickView").style.top=IpopTop + document.body.scrollTop;
		    // To get the layer on the center of page
		}
	}
}
//  ****************************************************************************************

