
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 = {

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;
},


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;
},


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: {

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";
},

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;
}
},


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;
}

};


var imageReplace = {

mainImage: "",

start: function() {
var images = document.getElementsByTagName("img");
var imax = images.length;
for (var i=0;i<imax;i++) {
if (!images[i].className) { continue;}
if (images[i].className.match(/ImageReplacePlace/)) {
imageReplace.mainImage = images[i];
continue;
}
if (!images[i].className.match(/ImageReplaceOrigin/)) { continue;}
images[i].onmouseover = imageReplace.setReplace (images[i].src);
}
},


setReplace: function(SRC) {
var func = function() {
imageReplace.mainImage.src = SRC;
}
return func;
}

};

var confirmAndExe = {

start: function() {
var links = document.links;
var imax = links.length;
for (var i=0;i<imax;i++) {
if (links[i].rel.match (/confirmAndExe/)) {
links[i].onclick = confirmAndExe.set(links[i].href, links[i].title);
}
}
},

set: function (_url, _message) {
var func = function() {
var res = confirm (_message + "\nよろしいですか？");
if (res) {
location.href = _url;
}
return false;
}
return func;
}

}


var imageWindow = {

images: "",

start: function() {
imageWindow.images = new Array();
var images = document.getElementsByTagName("img");
var imax = images.length;
for (var i=0;i<imax;i++) {
if (!images[i].className) { continue;}
imageWindow.images[images[i].src] = new Image();
imageWindow.images[images[i].src].src = images[i].src;
if (!images[i].className.match(/ImageWindow/)) { continue;}
images[i].onclick = imageWindow.setOpen (images[i]);
images[i].style.cursor = "pointer";
}
},


setOpen: function(TARGET) {
var func = function() {
imageWindow.open(TARGET.src, "imageWindow", TARGET.width, TARGET.height);
}
return func;
},
open: function(URL, NAME, WIDTH, HEIGHT, SCROLL, RESIZE, TOOLBAR, LOCATION, DIRECTORIES, STATUS, MENUBAR) {
    var win;
WIDTH = imageWindow.images[URL].width;
HEIGHT = imageWindow.images[URL].height;
NAME = NAME || "imageWindow";
WIDTH = WIDTH || 640;
HEIGHT = HEIGHT || 480;
SCROLL = SCROLL || "no";
RESIZE = RESIZE || "yes";
TOOLBAR = TOOLBAR || "no";
LOCATION = LOCATION || "no";
DIRECTORIES = DIRECTORIES || "no";
STATUS = STATUS || "no";
MENUBAR = MENUBAR || "no";
if (WIDTH > (screen.width - 100)) {
WIDTH = screen.width - 100;
SCROLL = "yes";
}
if (HEIGHT > (screen.height - 200)) {
HEIGHT = screen.height - 200;
SCROLL = "yes";
}
    win = window.open(
"",
NAME,
"toolbar=" + TOOLBAR +
",location=" + LOCATION +
",directories=" + DIRECTORIES +
",status=" + STATUS +
",menubar=" + MENUBAR +
",scrollbars=" + SCROLL +
",resizable=" + RESIZE +
", width="+ WIDTH +
", height=" + HEIGHT
);
win.document.open();
win.document.write("<html><head><title>imageWindow</title><style type=\"text/css\">*{margin: 0;padding: 0;}</style></head><body><img src=\"" + URL + "\"></body></html>");
win.document.close();
win.moveTo(30, 30);
    win.focus();
}
};
function page_load() {

switch (document.body.id) {
case "shop_item":
imageReplace.start();
imageWindow.start();
break;
case "shop_mypage":
confirmAndExe.start();
break;
case "access":
imageReplace.start();
break;
}

}
DomHTML.addEvent (window, "load", page_load);
