
//----------------------------------------------------------
//    DOM HTML
//    Ver 0.9.4
//----------------------------------------------------------
//  Get elements by class name
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className.split(" ");
for (var j = 0; j < classes.length; j++) {
var className = classes[j];
if (className == cl) {
retnode.push(elem[i]);
}
}
}
return retnode;
}

var DomHTML = {

//-------------------------------------------------------
//    Document width
//-------------------------------------------------------
getDocumentWidth: function (_document) {
if (!_document) { _document = document;}
if(_document.body) {
if(_document.body.scrollWidth || _document.body.scrollWidth == 0) {
return _document.body.scrollWidth;
}
if(_document.documentElement) {
return _document.documentElement.offsetWidth;
}
return _document.body.offsetWidth;
}

if(_document.width || _document.width == 0) {
return _document.width;
}
return 0;
},


//-------------------------------------------------------
//    Get scroll top
//-------------------------------------------------------
getScrollTop: function() {
if(window.scrollY) { return window.scrollY;}
if(window.pageYOffset) { return window.pageYOffset;}
if(document.documentElement && document.documentElement.scrollTop){
return document.documentElement.scrollTop;
} else if(document.body && document.body.scrollTop) {
return document.body.scrollTop;
}
return 0;
},


//-------------------------------------------------------
//    Document height
//-------------------------------------------------------
getDocumentHeight: function () {
if(document.body) {
if(document.body.scrollHeight || document.body.scrollHeight == 0) {
return document.body.scrollHeight;
}
if(document.documentElement) {
return document.documentElement.offsetHeight;
}
return document.body.offsetHeight;
}
if(document.height || document.height == 0) {
return document.height;
}
return 0;
},


//-------------------------------------------------------
//    Effects
//-------------------------------------------------------
effects: {

//-----------------------
//  Set width
//-----------------------
width: function(_target, _width, _fade) {
var current = _target.offsetWidth;
if (!_fade) {
var width = _width;
} else {
var width = current + ((_width - current) / _fade);
if (width != current) {
setTimeout(function() { DomHTML.effects.width(_target, _width, _fade / 1.25)}, 50);
}
}
_target.style.width = width + "px";
},

//-----------------------
//  Set opacity
//-----------------------
opacity: function(_target, _opacity, _fade, _fadetype) {
var current = _target.style.opacity * 100;
if (!_fade) {
var opacity = _opacity;
} else {
var opacity = Math.round(current + ((_opacity - current) / _fade));
if (opacity != current) {
setTimeout(function() { DomHTML.effects.opacity(_target, _opacity, _fade / 1.25)}, 50);
}
}
_target.style.zoom = 1;
_target.style.filter = 'alpha(opacity=' + (opacity) + ')';
_target.style.MozOpacity = opacity / 100;
_target.style.opacity = opacity / 100;
}
},


//-------------------------------------------------------
//    Add event
//-------------------------------------------------------
addEvent: function(elemObj, eventType, funcName, useCapture) {
if (!elemObj) { return false;}
if (elemObj.addEventListener){
elemObj.addEventListener(eventType, funcName, useCapture);
} else if (elemObj.attachEvent){
elemObj.attachEvent("on"+eventType, funcName);
} else {
return false;
}
return true;
}

};

//----------------------------------------------------------
//     HTML window open
//     2009.11.04 ver 0.1
//    usage
//        <a class="NewWindow[.dot separated attributes]" />
//    load
//        htmlWindow.start();
//        example)
//            DomHTML.addEvent (window, "load", htmlWindow.start);
//    attributes 
//        1. width as num (default 640)
//        2. height as num (default 480)
//        3. scroll as yes or no (default yes)
//        4. resize as yes or no (default yes)
//        5. toolbar as yes or no (default no)
//        6. location as yes or no (default no)
//        7. directories as yes or no (default no)
//        8. status as yes or no (default no)
//        8. menubar as yes or no (default no)
//----------------------------------------------------------
var htmlWindow = {

message: "新しいウィンドウで開きます。",

//-------------------------------------------------------
//    Set
//-------------------------------------------------------
start: function() {
var links = document.getElementsByTagName("a");
var imax = links.length;
for (var i=0;i<imax;i++) {
if (!links[i].className) { continue;}
if (!links[i].className.match(/NewWindow/)) { continue;}
var args = links[i].className.split(" ");
var jmax = args.length;
for (var j = 0; j < jmax; j++) {
if (args[j].match(/NewWindow/)) {
args = args[j];
break;
}
}
args = args.replace("NewWindow", "").split(".");
args.shift();
args.unshift(links[i].title);
args.unshift(links[i].href);
links[i].onclick = htmlWindow.setOpen (args);
links[i].title = htmlWindow.message;
}
},


//-------------------------------------------------------
//    Window open
//-------------------------------------------------------
setOpen: function(_args) {
var func = function() {
htmlWindow.open(_args);
return false;
}
return func;
},
open: function(_args) {
    var win;
URL = _args[0];
NAME = _args[1] || "NewWindow";
WIDTH = _args[2] || 640;
HEIGHT = _args[3] || 480;
SCROLL = _args[4] || "yes";
RESIZE = _args[5] || "yes";
TOOLBAR = _args[6] || "no";
LOCATION = _args[7] || "no";
DIRECTORIES = _args[8] || "no";
STATUS = _args[9] || "no";
MENUBAR = _args[10] || "no";
    win = window.open(
URL,
NAME,
"toolbar=" + TOOLBAR +
",location=" + LOCATION +
",directories=" + DIRECTORIES +
",status=" + STATUS +
",menubar=" + MENUBAR +
",scrollbars=" + SCROLL +
",resizable=" + RESIZE +
", width="+ WIDTH +
", height=" + HEIGHT
);
    win.focus();
}
};

//  Embed Flash ver 0.91
//----------------------------------------------------------
var embedFlash = {

//  Properties
//-------------------------------------------------------
pass: "",
top: "",
width: "",
height: "",
quality: "",
wmode: "",
bgcolor: "",
scale: "",

//  Constructor
//-------------------------------------------------------
setProperties: function(_pass, _top, _width, _height, _quality, _wmode, _bgcolor, _scale) {
embedFlash.pass = _pass;
embedFlash.top = _top;
embedFlash.width = _width;
embedFlash.height = _height;
embedFlash.quality = _quality;
embedFlash.wmode = _wmode;
embedFlash.bgcolor = _bgcolor;
embedFlash.scase = _scale;
},

//  Embed
//-------------------------------------------------------
embed: function() {
if (document.body.id != "toppage") { return false;}
var html = "";
html += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + embedFlash.width + "' height='" + embedFlash.height + "' align='middle'>";
html += "<param name='allowScriptAccess' value='sameDomain'>\n";
html += "<param name='movie' value='" + embedFlash.pass + "'>\n";
html += "<param name='quality' value='" + embedFlash.quality + "'>\n";
html += "<param name='wmode' value='" + embedFlash.wmode + "'>\n";
html += "<param name='bgcolor' value='" + embedFlash.bgcolor + "'>\n";
html += "<param name='scale' value='" + embedFlash.scale + "'>\n";
html += "<embed";
html += " src='" + embedFlash.pass + "' ";
html += " quality='" + embedFlash.quality + "' ";
html += " wmode='" + embedFlash.wmode + "' ";
html += " bgcolor='" + embedFlash.bgcolor + "' ";
html += " width='" + embedFlash.width + "' height='" + embedFlash.height + "' ";
html += " scale='" + embedFlash.scale + "' ";
html += " align='middle' ";
html += " allowScriptAccess='sameDomain' ";
html += " type='application/x-shockwave-flash' ";
html += " pluginspage='http://www.macromedia.com/go/getflashplayer'>\n";
html += "</embed>\n";
html += "</object>\n";
var container = document.createElement("div");
var flash = document.createElement("div");
container.style.zIndex = "4";
container.style.position = "absolute";
container.style.left = "0";
container.style.top = embedFlash.top + "px";
container.style.width = "100%";
container.style.textAlign = "center";
flash.style.width = embedFlash.width + "px";
flash.style.height = embedFlash.height + "px";
flash.style.margin = "0 auto";
flash.style.textAlign = "left";
flash.innerHTML = html;
container.appendChild(flash);
document.body.appendChild(container);
},

//  Add event
//-------------------------------------------------------
addEvent: function(elemObj, eventType, funcName, useCapture) {
if (elemObj.addEventListener){
elemObj.addEventListener(eventType, funcName, useCapture);
return true;
} else if (elemObj.attachEvent){
var r = elemObj.attachEvent("on"+eventType, funcName);
return r;
}
} 
}

//--------------------------------------------------------+
//
//     IMAGE BOX ver 1.0
//     2009.08.26
//     <a href="imageURL" rel="imagebox" />
//     imagebox.start();
//
//--------------------------------------------------------+
//     g\
//     摜ɃeLXg\?
//     

//---------------------------------------------------------
//    [ Box object - imagebox ]
//---------------------------------------------------------
var imageboxBox = {

element: false,
frame: false,
toolbar: false,
content: false,

//-------------------------------------------------------
//    Construct
//-------------------------------------------------------
construct: function() {

//  Set box
imageboxBox.element = document.createElement("div");
imageboxBox.element.id = "imagebox";
imageboxBox.element.style.position = "absolute";
imageboxBox.element.style.left = "0";
imageboxBox.element.style.top = "0";
imageboxBox.element.style.height = DomHTML.getDocumentHeight() + "px";
imageboxBox.element.style.width = "100%";
imageboxBox.element.style.textAlign = "center";
imageboxBox.element.style.zIndex = "101";

//  Set frame
imageboxBox.frame = document.createElement("div");
imageboxBox.frame.id = "imagebox-frame";
imageboxBox.frame.style.backgroundColor = "#FFFFFF";
imageboxBox.frame.style.width = "100px";
imageboxBox.frame.style.overflow = "hidden";
imageboxBox.frame.style.margin = "0 auto";
imageboxBox.frame.style.textAlign = "left";
imageboxBox.frame.style.backgroundRepeat = "no-repeat";
imageboxBox.frame.style.backgroundPosition = "center center";

//  Set toolbar
imageboxBox.toolbar = document.createElement("div");
imageboxBox.toolbar.id = "imagebox-toolbar";
imageboxBox.toolbar.style.padding = "10px";
imageboxBox.toolbar.style.textAlign = "right";
imageboxBox.toolbar.style.overflow = "hidden";
var closebutton = document.createElement("a");
closebutton.innerHTML = "CLOSE";
closebutton.onclick = function() { imagebox.close(); return false;}
closebutton.href = "#";
var buttonparent = document.createElement("p");
buttonparent.id = "imagebox-toolbar-close";
buttonparent.appendChild(closebutton);
imageboxBox.toolbar.appendChild(buttonparent);

//  Set content
imageboxBox.content = document.createElement("img");
imageboxBox.content.id = "imagebox-content";
imageboxBox.content.style.display = "block";
imageboxBox.content.style.margin = "0 10px 10px";

//   Append box
imageboxBox.hide();
imageboxBox.frame.appendChild(imageboxBox.toolbar);
imageboxBox.frame.appendChild(imageboxBox.content);
imageboxBox.element.appendChild(imageboxBox.frame);
document.body.appendChild(imageboxBox.element);

},


//-------------------------------------------------------
//    Load & open
//-------------------------------------------------------
load: function(_url) {
imageboxBox.show();
var image = new Image();
image.src = _url;
imageboxBox.content.src = image.src;
image.onload = imageboxBox.open;
},
open: function() {
DomHTML.effects.width(imageboxBox.frame, imageboxBox.content.width + 20, 5);
setTimeout (function() { imageboxBox.setWidth(imageboxBox.content.width + 20);}, 50);
},


//-------------------------------------------------------
//    Resize
//-------------------------------------------------------
setWidth: function(_width) {
if (_width <= imageboxBox.frame.offsetWidth) {
imageboxBox.frame.style.backgroundImage = "";
setTimeout (function() { DomHTML.effects.opacity(imageboxBox.content, 100, 8)}, 300);
} else {
setTimeout (function() { imageboxBox.setWidth(_width);}, 50);
}
},


//-------------------------------------------------------
//    Visible
//-------------------------------------------------------
show: function() {
window.scrollTo(0,0);
imageboxBox.element.style.top = "20px";
imageboxBox.element.style.display = "block";
},
hide: function() {
DomHTML.effects.opacity(imageboxBox.content, 0);
imageboxBox.element.style.display = "none";
imageboxBox.frame.style.backgroundImage = "url('scripts/images/load.gif')";
imageboxBox.content.src = "";
}
}



//---------------------------------------------------------
//    [ Document lock object - imagebox ]
//---------------------------------------------------------
var imageboxDocumentLock = {

element: false,

//-------------------------------------------------------
//    Construct
//-------------------------------------------------------
construct: function() {
imageboxDocumentLock.element = document.createElement("div");
imageboxDocumentLock.element.style.position = "absolute";
imageboxDocumentLock.element.style.left = "0";
imageboxDocumentLock.element.style.top = "0";
imageboxDocumentLock.element.style.height = DomHTML.getDocumentHeight() + "px";
imageboxDocumentLock.element.style.width = "100%";
imageboxDocumentLock.element.style.textAlign = "center";
imageboxDocumentLock.element.style.backgroundColor = "#000000";
imageboxDocumentLock.element.style.zIndex  = "100";
DomHTML.effects.opacity(imageboxDocumentLock.element, 0);
imageboxDocumentLock.unlock();
document.body.appendChild(imageboxDocumentLock.element);
},


//-------------------------------------------------------
//    Lock
//-------------------------------------------------------
lock: function() {
imageboxDocumentLock.element.style.display = "block";
DomHTML.effects.opacity(imageboxDocumentLock.element, 70, 1);
},
unlock: function() {
DomHTML.effects.opacity(imageboxDocumentLock.element, 0, 2);
setTimeout(function() { imageboxDocumentLock.hide()}, 10);
},
hide: function() {
if (imageboxDocumentLock.element.style.opacity <= 0) {
imageboxDocumentLock.element.style.display = "none";
} else {
setTimeout(function() { imageboxDocumentLock.hide()}, 10);
}
}

}



//---------------------------------------------------------
//    [ Main object - imagebox ]
//---------------------------------------------------------
var imagebox = {

bg: imageboxDocumentLock,
box: imageboxBox,
toolbar: false,
frame: false,

//-------------------------------------------------------
//    Constructor
//-------------------------------------------------------
start: function() {

//  Set box
imagebox.bg.construct();
imagebox.box.construct();

//  Set function
var links = document.links;
var imax = links.length;
for (var i=0;i<imax;i++) {
if (links[i].rel == "imagebox") {
links[i].onclick = imagebox.set(links[i].href);
}
}
},
set: function(_url) {
return func = function() {
imagebox.open (_url);
return false;
}
},


//-------------------------------------------------------
//    Box control
//-------------------------------------------------------
close: function() {
imagebox.box.hide();
imagebox.bg.unlock();
},
open: function(_url) {
imagebox.bg.lock();
imagebox.box.load(_url);
}

}

function page_load() {
htmlWindow.start();
switch (document.body.id) {
case "toppage":
embedFlash.setProperties("/scripts/../docs/slideshow.swf?dir=/scripts/../docs/slideshow/toppage", "96", "898", "498", "high", "transparent", "#FFFFFF", "showall");
embedFlash.embed();
break;
case "collection_itemlist":
imagebox.start();
}
}
DomHTML.addEvent (window, "load", page_load);
