﻿/*
--------------------------------------------------------

--------------------------------------------------------
*/

var iLayer = {
  defaultId : 'ilayer',

  show: function(p_div,p_ifr,p_url,p_width,p_height,p_align,p_valign,p_x,p_y,p_z) {

	if (!this.getElement("main")){
    	var mainElement = this.createElement("main");
	}else{
		var mainElement = this.getElement("main");
	}

	var iFElement = this.createElement(p_div);

	// IE以外。
	if (!document.all && (document.layers || document.getElementById)) {
	   var iFElement2 = document.createElement('iframe');
	   iFElement2.frameborder = 0;
	   iFElement2.allowtransparency='true';
	   iFElement2.setAttribute('frameborder',0);
	   }
	// ウィンドウズIE 6・標準モード。
	else if (document.getElementById && (document.compatMode=='CSS1Compat')) {
	   var iFElement2 = document.createElement("<iframe frameborder='0' allowtransparency='true'></iframe>");
	   }
	// その他のIE。
	else if (document.all) {
	   var iFElement2 = document.createElement("<iframe frameborder='0' allowtransparency='true'></iframe>");
	   }
	// その他(非対応)。
	else {
	   var iFElement2 = document.createElement('iframe');
	   iFElement2.frameborder = 0;
	   iFElement2.allowtransparency='true';
	   iFElement2.setAttribute('frameborder',0);
    }
   
    iFElement2.id = p_ifr; 
	iFElement2.src = p_url;
	this.resetSize(iFElement2, p_width, p_height, p_x, p_y);
	
	iFElement2.backgroundColor='#FFFFFF';
	iFElement2.scrolling='no';

	iFElement2.style.display = '';

	iFElement.style.zIndex = p_z;
	iFElement.style.position='absolute';
    iFElement.appendChild(iFElement2);

	this.resetPos(iFElement, p_width, p_height, p_x, p_y);
	
    iFElement.style.display = '';

	mainElement.appendChild(iFElement);
	this.setPos(mainElement,0,0);
	
    mainElement.style.display = '';
    
    return iFElement;
    
  },
  
  hide: function(p_div,p_ifr) {
	//---
	var iFElement = this.getElement(p_div);
	var iframe_ele = this.getElement(p_ifr);
	//---
    iFElement.style.display = 'none';
    iframe_ele.style.display = 'none';
    //---
    return iFElement;
    //---
  },
  
  setPos:function(p_Element,p_top,p_left){
  	
    if (p_left > 0){
		p_Element.style.left = p_left+"px";
	}else{
		p_Element.style.left = "0px";
	}
	
	if (p_top > 0){
		p_Element.style.top = p_top+"px";
	}else{
		p_Element.style.top = "0px";
	}
	
  },
  
  resetPos:function(iFElement,p_width,p_height,p_x,p_y){
  	
	var tmpLeft = p_x;
	var tmpTop = p_y;
	
	if (tmpLeft<0){
		tmpLeft=0;
	} 
	
	if (tmpTop<0){
		tmpTop=0;
	} 
	
	iFElement.style.left = tmpLeft+"px";
	iFElement.style.top = tmpTop+"px";
	
  },
  
  resetSize:function(p_element,p_width,p_height,p_x,p_y){
	
	var tmpWidth = p_width;
	var tmpHeight = p_height;
	p_element.width = tmpWidth;
	p_element.height = tmpHeight;

  },
  
  // Util
  getElement: function(element) {

    if (typeof element == 'string') {
      element = document.getElementById(element);
    }
    return element;
  },
  
  createElement: function(element,p_id,p_url,p_width,p_height) {
    var id = element;
    element = this.getElement(element);
    if (!element) {
		element = document.createElement('div');
		element.id = id;
	    element.style.display = 'none';
	    document.body.appendChild(element);
    }
    return element;
  },
  
  getWindowSize: function() {
	var winSizeObj = new Object();
	
    // IE以外。
	if (!document.all && (document.layers || document.getElementById)) {
	    winWidth=window.innerWidth;
	    winHeight=window.innerHeight;
	    }
	// ウィンドウズIE 6・標準モード。
	else if (document.getElementById && (document.compatMode=='CSS1Compat')) {
	    winWidth=document.documentElement.clientWidth;
	    winHeight=document.documentElement.clientHeight;
	    }
	// その他のIE。
	else if (document.all) {
	    winWidth=document.body.clientWidth;
	    winHeight=document.body.clientHeight;
	    }
	// その他(非対応)。
	else {
	    winWidth=1024;
	    winHeight=768;
    }
    
    winSizeObj.width = winWidth;
    winSizeObj.height = winHeight;
    
    return winSizeObj;
  }
  
}

