
// JScript File

/****************Begin*********************** Index *******************Begin*********************/
// 0:
// 1:
// 2:
// 3:
// 4:
// 5:
// 6:
// 7:
// 8:
// 9:
/****************End************************* Index *******************End***********************/

/****************Begin********************* Global Variables *******************Begin*******************/

/****************End*********************** Global Variables *******************End*********************/

/****************Begin*********************** Generic Interactivity Functions *******************Begin*********************/

function revealInteractive() {
    var toolboxWrapper = document.getElementById("toolboxWrapper");
    var roomsWrapper = document.getElementById("roomsAndSuitesWrapper");
    var spaTreatments = document.getElementById("spaTreatments");
    var meetingSpaces = document.getElementById("meetingSpaces");
    var meetingServices = document.getElementById("meetingServices");
    var ttdsWrapper = document.getElementById("ttdsWrapper");
    var mapWrapper = document.getElementById("interactiveMap");
    var galleryWrapper = document.getElementById("revolverContainer2");
    var pressKitsWrapper = document.getElementById("pressKits");
    var iWrapper = document.getElementById("iWrapper");
    var loaderdiv = document.getElementById("loaderDiv");
    if (toolboxWrapper != null){
        toolboxWrapper.style.visibility = "visible";
        toolboxWrapper.style.display = "block";
    }
    else if (roomsWrapper != null){
        roomsWrapper.style.display = "block";
    }
    else if (spaTreatments != null){
        spaTreatments.style.display = "block";
    }
    else if (meetingSpaces != null){
        meetingSpaces.style.display = "block";
    }
    else if (meetingServices != null){
        meetingServices.style.display = "block";
    }
    else if (ttdsWrapper != null){
        ttdsWrapper.style.display = "block"; 
    }
    else if (mapWrapper != null){
        mapWrapper.style.visibility = "visible";
    }
    else if (galleryWrapper != null){
        galleryWrapper.style.visibility = "visible";
    }
    else if (pressKitsWrapper != null) {
        pressKitsWrapper.style.display = "block";
    }
    else if (iWrapper != null) {
        iWrapper.style.display = "block";
    }
    if (loaderdiv != null){
        loaderdiv.style.display= "none";        
    }
}

function setIds(arrayObj, baseId, numIds) {
    for (i = 0; i < numIds; i++) {
        arrayObj[i] = baseId + (i+1);
    }
    return(arrayObj);
}

function setSliderObjects(arrayObj, arrayIds, numIds, mode) {
    for (i = 0; i < numIds; i++) {
        var sliderObj = new Fx.Slide(arrayIds[i], {mode: mode});
        arrayObj[i] = sliderObj;
    }
    return(arrayObj);
}

function hideAllSliders(arrayObj, numIds) {
    for (i = 0; i < numIds; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.hide();
    }
}

function slideInAllSliders(arrayObj, numIds) {
    for (i = 0; i < numIds; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.slideIn();
    }
}

function slideOutAllSliders(arrayObj, numIds) {
    for (i = 0; i < numIds; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.slideOut();
    }
}

function showAllSliders(arrayObj, numIds) {
    for (i = 0; i < numIds; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.show();
    }
}

// add functions to do the above allowing for start and indexes as well
function slideInRangeSliders(arrayObj, startIndex, endIndex) {
    for (i = startIndex; i <= endIndex; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.slideIn();
    }
}

function slideOutRangeSliders(arrayObj, startIndex, endIndex) {
    for (i = startIndex; i <= endIndex; i++) {
        var sliderObj = arrayObj[i];
        sliderObj.slideOut();
    }
}

// add functions to do the above except for one
function hideAllSlidersButOne(arrayObj, numIds, index) {
    for (i = 0; i < numIds; i++) {
        if (i != index)
            arrayObj[i].hide();
    }
}

function slideOutAllSlidersButOne(arrayObj, numIds, index) {
    for (i = 0; i < numIds; i++) {
        if (i != index)
            arrayObj[i].slideOut();
    }
}

// this is the function to call on the toggle within the html file
// need to make customizable
function slideInSlider(arrayObj, numIds, index, hotelName) {
    hideAllSliders(arrayObj, numIds);
    arrayObj[index].slideIn();
    setText(hotelName);
}

function createCollection(sliderObjects, sliderIdBase, numIds, mode) {
    var sliderIds = new Array();
    sliderIds = setIds(sliderIds, sliderIdBase, numIds);
    sliderObjects = setSliderObjects(sliderObjects, sliderIds, numIds, mode);
    return(sliderObjects);
}

/****************End************************* Generic Interactivity Functions *******************End***********************/

/****************Begin*********************** Global Home - Emotional Navigation *******************Begin*********************/

function hover(thisObj) {
	if (thisObj.className != "tab_selected") {
		thisObj.className = "tab_hover";
	}
}
function dehover(thisObj) {
	if (thisObj.className != "tab_selected") {
		thisObj.className = "tab";
	}
}
function sethover(thisObj) {
	thisObj.className = "tab_selected";
	// change back all others
	var tab = null;
	for (i = 0; i < 8; i++) {
		if (tabArray[i] == thisObj.id) {}
		else {
			tab = document.getElementById(tabArray[i]);
			tab.className = "tab";
		}
	}
}
var setNum = 1;

function changeImage(fileName) {
	var fansObj = document.getElementById("fans");
	fansObj.src = fileName;
}

function showImage(id) {
    var image = document.getElementById(id);
    image.className = "image";
}
function hideAll(id1, id2, id3, id4, id5, id6, id7) {
    var image1 = document.getElementById(id1);
    var image2 = document.getElementById(id2);
    var image3 = document.getElementById(id3);
    var image4 = document.getElementById(id4);
    var image5 = document.getElementById(id5);
    var image6 = document.getElementById(id6);
    var image7 = document.getElementById(id7);
    image1.className = "image2";
    image2.className = "image2";
    image3.className = "image2";
    image4.className = "image2";
    image5.className = "image2";
    image6.className = "image2";
    image7.className = "image2";
}	
/****************End************************* Global Home - Emotional Navigation *******************End***********************/

/*******************Begin******************** Corporate Photo Gallery ********************Begin*******************/
var globalName = 'Welcome to our photo gallery - click on your desired Mandarin Oriental hotel above.';
var pg_click = "false";
var pg_display = globalName;
var pg_hotel = "";

function setMarginTop(id, marginPx) {
    document.getElementById(id).style.marginTop = marginPx+'px';
}
function changeHotel(hotelName) {
    var nameWrapperObj = document.getElementById("nameWrapper");
    nameWrapperObj.innerHTML = "<h3>" + hotelName + "</h3>";
    pg_hotel = hotelName;
}
function setClick() {
    pg_display = pg_hotel;
    pg_click = "true";
}
function resetClick() {
    var nameWrapperObj = document.getElementById("nameWrapper");
    nameWrapperObj.innerHTML = "<h3>" + globalName + "</h3>";
    pg_click = "false";
}
function setOut() {
    var nameWrapperObj = document.getElementById("nameWrapper");
    if (pg_click == "false") {
        nameWrapperObj.innerHTML = "<h3>" + globalName + "</h3>";
    } else {
        nameWrapperObj.innerHTML = "<h3>" + pg_display + "</h3>";
    }
}
/********************End********************* Corporate Photo Gallery *********************End********************/

/*******************Begin******************** Awards ********************Begin*******************/
var tabClass = "";
function highlight(thisObj) {
    tabClass = "tab selected";
    thisObj.className = "tab selected";
}
function dehighlight(firstObj, secondObj) {
    var objOne = document.getElementById(firstObj);
    var objTwo = document.getElementById(secondObj);
    objOne.className = "tab";
    objTwo.className = "tab";
}
function hover(thisObj) {
    tabClass = thisObj.className;
    thisObj.className = "tab hover";
}
function dehover(thisObj) {
    if (tabClass == "tab selected") {
        thisObj.className = tabClass;
    } else {
        thisObj.className = "tab";
    }
}
function hl(thisObj) {
    thisObj.className = "yearTab selectedYear";
}
function dhl(a, b, c) {
    var aObj = document.getElementById(a);
    var bObj = document.getElementById(b);
    var cObj = document.getElementById(c);
    aObj.className = "yearTab";
    bObj.className = "yearTab";
    cObj.className = "yearTab";
}
function dhl5(a, b, c, d, e) {
    var aObj = document.getElementById(a);
    var bObj = document.getElementById(b);
    var cObj = document.getElementById(c);
    var dObj = document.getElementById(d);
    var eObj = document.getElementById(e);
    aObj.className = "yearTab";
    bObj.className = "yearTab";
    cObj.className = "yearTab";
    dObj.className = "yearTab";
    eObj.className = "yearTab";
}
function changeTab(num) {
	var obj1 = document.getElementById('tb1');
	var obj2 = document.getElementById('tb2');
	//var obj3 = document.getElementById('tb3');
	var obj4 = document.getElementById('tb4');
	var link1 = document.getElementById('yearToggle');
	var link2 = document.getElementById('spaToggle');
	//var link3 = document.getElementById('euroLink');
	var link4 = document.getElementById('restaurantToggle');
	switch (num) {
	case 1:
		obj1.className = "tabSelected";
		obj2.className = "tab tabBorder";
		//obj3.className = "tab tabBorder";
		obj4.className = "tab";
		link1.className = "tabSelected";
		link2.className = "tab";
		//link3.className = "tab";
		link4.className = "tab";
		break
	case 2:
		obj1.className = "tab";
		obj2.className = "tabSelected tabBorder";
		//obj3.className = "tab tabBorder";
		obj4.className = "tab";
		link1.className = "tab";
		link2.className = "tabSelected";
		//link3.className = "tab";
		link4.className = "tab";
		break
	case 3:
		obj1.className = "tab";
		obj2.className = "tab tabBorder";
		//obj3.className = "tabSelected tabBorder";
		obj4.className = "tab";
		link1.className = "tab";
		link2.className = "tab";
		//link3.className = "tabSelected";
		link4.className = "tab";
		break
	case 4:
		obj1.className = "tab";
		obj2.className = "tab tabBorder";
		//obj3.className = "tab tabBorder";
		obj4.className = "tabSelected";
		link1.className = "tab";
		link2.className = "tab";
		//link3.className = "tab";
		link4.className = "tabSelected";
		break
	default:
	}
}

/********************End********************* Awards *********************End********************/

/*******************Begin******************** Press Quotes ********************Begin*******************/
function toggle(id, id2) {
    var toggleObj = document.getElementById(id);
    var slideObj = document.getElementById(id2);
    var titleObj = document.getElementById(id + 'Title');
    if (toggleObj.className == "sliderHeader2") {
        toggleObj.className = "sliderHeader";
        slideObj.className = "sliderContent";
        titleObj.className = "sliderHeaderTitle";
    }
    else {
        toggleObj.className = "sliderHeader2";
        slideObj.className = "sliderContent2";
        titleObj.className = "sliderHeaderTitle2";
    }
}
function openQuote(id, id2) {
    var toggleObj = document.getElementById(id);
    var slideObj = document.getElementById(id2);
    var titleObj = document.getElementById(id + 'Title');
    toggleObj.className = "sliderHeader2";
    slideObj.className = "sliderContent2";
    titleObj.className = "sliderHeaderTitle2";
}
function closeQuote(id, id2) {
    var toggleObj = document.getElementById(id);
    var slideObj = document.getElementById(id2);
    var titleObj = document.getElementById(id + 'Title');
    toggleObj.className = "sliderHeader";
    slideObj.className = "sliderContent";
    titleObj.className = "sliderHeaderTitle";
}
function highlight(id) {
    var spanObj = document.getElementById(id + 'Title');
    spanObj.className = "sliderHeaderTitle2";
}
function dehighlight(id) {
    var headerObj = document.getElementById(id);
    if (headerObj.className == "sliderHeader") {
        var spanObj = document.getElementById(id + 'Title');
        spanObj.className = "sliderHeaderTitle";
    }
}
/********************End********************* Press Quotes *********************End********************/

/*******************Begin******************** Hotel Destination - Things to Do and See ********************Begin*******************/
function toggleFind(id, id2) {
	var toggleObj = document.getElementById(id);
	var findObj = document.getElementById(id + 'Span');
	var slideObj = document.getElementById(id2);
	var titleObj = document.getElementById(id + 'Title');
	if (toggleObj.className == "sliderHeader2") {
		findObj.className = "sliderHeaderFind";
		toggleObj.className = "sliderHeader";
		slideObj.className = "sliderContent";
		titleObj.className = "sliderHeaderTitle";
	}
	else {
		findObj.className = "sliderHeaderFind2";
		toggleObj.className = "sliderHeader2";
		slideObj.className = "sliderContent2";
		titleObj.className = "sliderHeaderTitle2";
	}
}
function toggleFindCase(id, id2, closeOpen) {
	var toggleObj = document.getElementById(id);
	var findObj = document.getElementById(id + 'Span');
	var slideObj = document.getElementById(id2);
	var titleObj = document.getElementById(id + 'Title');
	if (closeOpen == 0) {
		findObj.className = "sliderHeaderFind";
		toggleObj.className = "sliderHeader";
		slideObj.className = "sliderContent";
		titleObj.className = "sliderHeaderTitle";
	} else {
		findObj.className = "sliderHeaderFind2";
		toggleObj.className = "sliderHeader2";
		slideObj.className = "sliderContent2";
		titleObj.className = "sliderHeaderTitle2";
	}
}
function toggleFindAll(toggle, slide, num, closeOpen) {
	for (i = 1; i <= num; i++) {
		id = toggle + i;
		id2 = slide + i;
		toggleFindCase(id, id2, closeOpen);
	}
}

/********************End********************* Hotel Destination - Things to Do and See *********************End********************/

/*******************Begin******************** Rooms & Suites ********************Begin*******************/

function toggleRooms(startIndex, endIndex, toggle, idBase) {
	for (i = startIndex; i <= endIndex; i++) {
		toggleRoom(i, toggle, idBase);
	}
}

function toggleRoom(i, toggle, idBase) {
	var roomObj = document.getElementById(idBase + "room" + i);
	var rowDiv = document.getElementById(idBase + "rgr" + i);
	// for toggling "details | booking"
	var detailsDiv = document.getElementById(idBase + "roomDetails" + i);
	if (toggle == 0 || (roomObj.className == "rTW" && toggle != 1)) {
		roomObj.className = "rTW2";
		rowDiv.className = "headerRSType";
		detailsDiv.className = "room_details_hidden";
	} else {
		roomObj.className = "rTW";
		rowDiv.className = "headerRSType";
		detailsDiv.className = "roomDetails";
	}
}

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 ];
}
var scrollXYArray = new Array();

/********************End********************* Rooms & Suites *********************End********************/

/*******************Begin******************** Toolbox ********************Begin*******************/

/********************End********************* Toolbox *********************End********************/

// check if a slider is open
function isOpen(id) {
    var sliderObject = document.getElementById(id);
    var parentObject = sliderObject.parentNode;
    if (parseInt(parentObject.style.height) > 0)
        return true;
    else
        return false;
}

// id of currently clicked element
var currentId = null;

function changeClass(id, className) {
    var object = document.getElementById(id);
    object.className = className;
}
// don't change class on mouseout if it has already been clicked
function changeClassExcept(idCur, idNew, className) {
    if (idCur != idNew) {
        var object = document.getElementById(idNew);
        object.className = className;
    }
}
// on mouseout revert to previous class
function changeClassPrevious(idCur, idNew, className, className2) {
    var object = document.getElementById(idNew);
    if (idCur != idNew) {
        object.className = className;
    } else {
        object.className = className2;
    }
}
// revert the previously clicked element before changing the currently clicked element
function changeClassAndRevert(id, id2, className, className2) {
    if (id != null) {
        var objPrev = document.getElementById(currentId);
        objPrev.className = className;
    }
    var object = document.getElementById(id2);
    object.className = className2;
    currentId = id2;
}
// change class on mouseout based on the state of a different element
function changeClassCheck(id, id2, className, className2) {
    var object = document.getElementById(id);
    if (object.className == className) {
        var object2 = document.getElementById(id2);
        object2.className = className2;
    }
}

// change classes for a collection of elements
function changeClasses(baseId, num, className) {
    for (i = 1; i <= num; i++) {
        strId = baseId + i;
        changeClass(strId, className);
    }
}

// change classes for a collection of elements except one
function changeClassesExceptOne(baseId, num, className, exceptNum, className2) {
    for (i = 1; i <= num; i++) {
        strId = baseId + i;
        if (i != exceptNum) {
            changeClass(strId, className);
        } else {
            changeClass(strId, className2);
        }
    }
}

/*******************Begin******************** Interactive Map - POI ********************Begin*******************/

// fill an element with text
function setText(id, text) {    // NEED TO CHANGE FUNCTION NAME SO AS NOT TO CONFLICT WITH CORP GALLERY
    var object = document.getElementById(id);
    object.innerHTML = text;
}
// fill an element with text from another element
function setText2(id, id2) {
    var object = document.getElementById(id);
    var object2= document.getElementById(id2);
    object.innerHTML = object2.innerHTML;
}
// display a hidden element
function revealElement(id) {
    var object = document.getElementById(id);
    object.style.display = "block";
}

/********************End********************* Interactive Map - POI *********************End********************/
/* Currency Converter Popup */
var LightboxExCC = {
	init: function(options){
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: true,
			defaultIframeWidth : 462, 
			defaultIframeHeight: 300
		}, options || {});

		// IE 6 - XML prolog problem
		if(window.ie6 && document.compatMode=="BackCompat"){
			this.options.animateCaption = false;
		}

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxExCC/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

        this.overlay = new Element('div', {'id':'lbOverlayExCC', 'class':'lbOverlayEx'}).injectInside(document.body);
        this.center = new Element('div', {'id':'lbCenterExCC', 'class':'lbCenterEx'}).setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
		this.canvas = new Element('div', {'id':'lbCanvasExCC', 'class':'lbCanvasEx'}).injectInside(this.center);

		this.closeBtnTop = new Element('a', {'id':'closeBtnTopCC', 'href':'#', 'class':'lbCloseBtnTop'}).injectInside(this.canvas);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.bottomContainer = new Element('div', {'id':'lbBottomContainerPopCC', 'class':'lbBottomContainerPop', 'styles': {'display':'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id':'lbBottomPopCC', 'class':'lbBottomPop'}).injectInside(this.bottomContainer);
		
		this.navBottom = new Element('div', {'id':'lbNavBottomPopCC', 'class':'lbNavBottomPop', 'styles': {'width':'468px'}}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id':'lbNavWrapperPopCC', 'class':'lbNavWrapperPop', 'styles': {'width':'460px'}}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id':'lbSubWrapperPopCC', 'class':'lbSubWrapperPop', 'styles': {'width':'360px'}}).injectInside(this.navWrapper);
		
		this.closeLink = new Element('div', {'id':'lbCloseLinkPopCC', 'class':'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);

		new Element('div').setStyle('clear', 'both').injectInside(this.bottom);

		/* Build effects */
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start('0'),
            resizeCenter: this.center.set('morph', {duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect}),
            image: this.canvas.set('tween',  { duration: 500, onComplete: nextEffect })/*,
            bottom: new Fx.Tween(this.bottomContainer, {property: 'height', duration: 400, onComplete: nextEffect })*/
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title, link.rev);

		var j, itemNumber, items = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < items.length; j++) if(items[j][0] == el.href && items[j][2] == el.rev) break;
				if (j == items.length){
					items.push([el.href, el.title, el.rev]);
					if (el.href == link.href && el.rev == link.rev) itemNumber = j;
				}
			}
		}, this);
		return this.open(items, itemNumber);
	},

	show: function(url, title, rev){
		return this.open([[url, title, rev]], 0);
	},

	open: function(items, itemNumber){
		this.items = items;
		this.position();
		this.setup(true);
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeItem(itemNumber);
	},

	position: function(){
		//IE6 - XML prolog problem.
		var ww = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.overlay.setStyles({top: st+'px', height: wh+'px', width:ww+'px'});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		if (window.ie) elements.extend(document.getElementsByTagName('select'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeItem(this.activeItem-1);
	},

	next: function(){
		return this.changeItem(this.activeItem+1);
	},

	changeItem: function(itemNumber){
		if (this.step || (itemNumber < 0) || (itemNumber >= this.items.length)) return false;
		this.step = 1;
		this.activeItem = itemNumber;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		//this.bottomContainer.style.display = 'none';
		//this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.fade('hide');
		//this.center.className = 'lbLoadingExHag';

		// discard previous content by clicking
		this.removeCurrentItem();
		
		// check item type
		var url = this.items[this.activeItem][0];
		var rev = this.items[this.activeItem][2];
		
		var re_imageURL = /\.(jpe?g|png|gif|bmp)/i;
		if( url.match(re_imageURL) ) {
			this.preload = new Image();	// JavaScript native Object
			this.preload.datatype = 'image';
			this.preload.w = this.matchOrDefault(rev, new RegExp("width=(\\d+%?)", "i"), -1); //-1 if use original size.
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+%?)", "i"), -1);
			this.preload.onload = this.nextEffect.bind(this);
			this.preload.src = url;
		}else{
			var ie7 = (document.all && !window.opera && window.XMLHttpRequest)? true : false;
			this.preload = new Object ();	// JavaScript native Object
			this.preload.datatype = 'iframe';
			this.preload.w =  this.matchOrDefault(rev, new RegExp("width=(\\d+)", "i"), this.options.defaultIframeWidth);
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+)", "i"), this.options.defaultIframeHeight);
			this.preload.h = (ie7)? 358 : this.preload.h;
			
			this.preload.src = url;
			this.nextEffect(); //asynchronous loading
		}

		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			//this.center.className = '';

			// create HTML element
			if( this.preload.datatype == 'image' ) {
				var ws = (this.preload.w == -1) ? this.preload.width.toString() : this.preload.w.toString();
				var hs = (this.preload.h == -1) ? this.preload.height.toString() : this.preload.h.toString();
				this.p_width = ( q = ws.match(/(\d+)%/) ) ? q[1] * this.preload.width * 0.01 : ws;
				this.p_height = ( q = hs.match(/(\d+)%/) ) ? q[1] * this.preload.height * 0.01 : hs;
				new Element('img').setProperties({id: 'lbImageExCC', src:this.preload.src, width:this.p_width, height:this.p_height}).injectInside(this.canvas);
				//this.nextLink.style.right = '';
			}else{
				this.p_width = this.preload.w;
				this.p_height = this.preload.h;
				// Safari would not update iframe content that has static id.
				this.iframeId = "lbFrame_"+new Date().getTime();
				//new Element('iframe').setProperties({id: this.iframeId, width: this.p_width, height: this.p_height, frameBorder:0, scrolling:'no', src:this.preload.src}).injectInside(this.canvas);
				this.iframe = new Element('iframe', {'id':this.iframeId, 'class':'ifsdf', 'src':this.preload.src, 'scrolling':'no', 'frameBorder':'0'}).injectInside(this.canvas);
				//, 'styles':{'width':'597px', 'height':'253px'}
				//this.nextLink.style.right = '25px';
			}
			this.canvas.style.width = this.p_width+'px';
			this.canvas.style.height = this.p_height+'px';

			//this.prevLink.style.height = this.nextLink.style.height = this.p_height+'px';

			//this.caption.set("html", this.items[this.activeItem][1] || '');
			//this.number.set("html",  (this.items.length == 1) ? '' : 'ページ ' + (this.activeItem+1) + ' of ' + this.items.length );

			if (this.activeItem) this.preloadPrev.src = this.items[this.activeItem-1][0];
			if (this.activeItem != (this.items.length - 1)) this.preloadNext.src = this.items[this.activeItem+1][0];
			if (this.center.clientHeight != this.canvas.offsetHeight){
				var oh = (this.p_height == this.canvas.clientHeight) ? this.canvas.offsetHeight : eval(this.p_height);
				this.fx.resizeCenter.morph({'height': oh});
				break;
			}

			this.step++;
		case 2:
			if (this.center.clientWidth != this.canvas.offsetWidth){
				var ow = (this.p_width == this.canvas.clientWidth) ? this.canvas.offsetWidth : eval(this.p_width)+18; // fix for ie
				this.fx.resizeCenter.morph({'width': ow, 'marginLeft': -ow/2});
				break;
			}
			this.step++;
		case 3:
			//this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height:'0px', marginLeft: this.center.style.marginLeft, width:this.center.style.width, display: ''});
			this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', marginLeft: this.center.style.marginLeft, width:this.center.style.width, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				// This is not smooth animation in IE 6 with XML prolog.
				// If your site is XHTML strict with XML prolog, disable this option.
				//this.fx.bottom.start(0,this.bottom.offsetHeight+10);
				break;
			}
			//this.bottomContainer.style.height = (this.bottom.offsetHeight+10)+'px';
		case 5:
			if (this.activeItem){
				//this.prevLink.style.display = '';
			}
			if (this.activeItem != (this.items.length - 1)){
				//this.nextLink.style.display = '';
			}
			this.step = 0;
		}
	},

	close: function(){
        if (document.getElementById("moduleToggle1") != null) {
            document.getElementById("moduleToggle1").className = "tan";
            currentId = null;
        }

		if (this.step < 0) return;
		this.step = -1;
		this.removeCurrentItem();	// discard content
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	},

	removeCurrentItem: function(){
		if (this.preload){
			if( this.preload.datatype == 'image' ) {
				$('lbImageExCC').dispose();
				this.preload.onload = function () {}; //Class.empty;
			}else{
				$(this.iframeId).dispose();
			}
			this.preload = null;
		}		
	},

	matchOrDefault: function(str, re, val){
		var hasQuery = str.match(re);
		return hasQuery ? hasQuery[1] : val;
	}

};
/*******************Begin******************** Lightbox Popups ********************Begin*******************/

/* Image Popups */
var LightboxPop = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 25,
			initialHeight: 25,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxPop/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayPop'}).injectInside(document.body);

		this.center = new Element('div', {'id': 'lbCenterPop', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		
		this.closeBtnTop = new Element('a').setProperties({id: 'closeBtnTopPopImg', href: '#'}).injectInside(this.center);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.image = new Element('div', {'id': 'lbImagePop'}).injectInside(this.center);
		
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerPop', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomPop'}).injectInside(this.bottomContainer);
                                this.caption = new Element('div', {'id': 'lbCaptionPop'}).injectInside(this.bottom);		
                                this.navBottom = new Element('div', {'id': 'lbNavBottomPop'}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop'}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop'}).injectInside(this.navWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberPop'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
                                this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		
		//new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
                                scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		//this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.bottomContainer.style.display = 'none';
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingPop';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.navBottom.style.width = this.preload.width+'px';
			this.navWrapper.style.width = this.preload.width-12+'px';   // -12 to account for border and padding
			this.subWrapper.style.width = this.preload.width-112+'px';
			//this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
                                                this.image.style.height = this.preload.height+'px';
			//this.caption.set("html", this.images[this.activeImage][1] || '');
                                                if (this.images[this.activeImage][1] != "") {
			    this.caption.style.visibility = "visible";
			    this.caption.style.display = "block";
			    this.caption.style.width = this.preload.width-10+'px';  // -10 to account for left-padding
			    this.caption.set("html", this.images[this.activeImage][1] || '');
			} else {
			    this.caption.style.visibility = "hidden";
			    this.caption.style.display = "none";
			}
			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth+18, 'marginLeft': -this.image.offsetWidth/2});    // added 18 pixels to width to account for margin and border around the image
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) /*this.prevLink.style.display = '';*/ this.prevLink.style.visibility = 'visible';
			if (this.activeImage != (this.images.length - 1)) /*this.nextLink.style.display = '';*/ this.nextLink.style.visibility = 'visible';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};
var LightboxRSfanfare = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 380,
			initialHeight: 380,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxfanfare/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayRS'}).injectInside(document.body);

		this.center = new Element('div', {'id': 'lbCenterRS', 'styles': {'width': this.options.initialWidth * 2, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth), 'display': 'none'}}).injectInside(document.body);
		this.image = new Element('div', {'id': 'lbImageRS', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight}}).injectInside(this.center);
		this.textArea = new Element('div', {'id': 'lbAwardDetails', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'left':this.options.initialWidth + 11}}).injectInside(this.center);
		
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerRS', 'styles': {'display': 'none', 'width': this.options.initialWidth * 2 + 4}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomRS', 'styles': {'width': this.options.initialWidth * 2, 'padding-bottom': 5, 'padding-top': 9}}).injectInside(this.bottomContainer);
		
		this.captionTitle = new Element('div', {'id': 'lbCaptionTitleRS'}).injectInside(this.textArea);
		this.caption = new Element('div', {'id': 'lbCaptionRS', 'styles': {'width': '94%', 'height': '85%', 'overflow-y': 'auto'}}).injectInside(this.textArea);
		
		this.navLinks = new Element('div', {'id': 'navLinksRS', 'styles': {'background': 'none', 'left': 0}}).injectInside(this.bottom);

		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop', 'styles': {'width': this.options.initialWidth * 2 - 11}}).injectInside(this.navLinks);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop', 'styles': {'width': '85%'}}).injectInside(this.navWrapper);
		this.category = new Element('div', {'id': 'lbCategoryRS', 'styles': {'left': 40, 'margin-right': 5}}).injectInside(this.subWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberPop'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
       	this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		this.category.set("html", '');
		
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},
	
	showRS: function(images){
		return this.open(images, 0);
	},
	
	showRSs: function(images, imageNum){
		return this.open(images, imageNum);
	},

	showRSfanfare: function(images, imageNum){
		return this.open(images, imageNum);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingRS';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		this.category.set("html", '<span>' + this.images[this.activeImage][2][0] + '</span>');
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.bottom.style.width = this.image.offsetWidth * 2 - 3 +'px';

			var strCaption = this.images[this.activeImage][1].substring(this.images[this.activeImage][1].search("::")+2);	// make use of tooltip title; has format "title :: caption"
			var strCaptionTitle = this.images[this.activeImage][1].substring(0, this.images[this.activeImage][1].search("::"));
			this.captionTitle.set("html", "<h3>" + strCaptionTitle + "</h3>" || '');
			this.caption.set("html", strCaption || '');

			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth * 2, 'marginLeft': -this.image.offsetWidth});
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) this.prevLink.style.display = '';
			if (this.activeImage != (this.images.length - 1)) this.nextLink.style.display = '';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};

/* Fans Popups */
var LightboxFans = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 25,
			initialHeight: 25,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxFans/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayPop'}).injectInside(document.body);
		this.center = new Element('div', {'id': 'lbCenterPop', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		this.image = new Element('div', {'id': 'lbImagePop'}).injectInside(this.center);
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerPop', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomPop'}).injectInside(this.bottomContainer);
        this.caption = new Element('div', {'id': 'lbCaptionPop'}).injectInside(this.bottom);		
        this.navBottom = new Element('div', {'id': 'lbNavBottomPop'}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop'}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop'}).injectInside(this.navWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberFans'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
        this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');

        this.findOutWhy = new Element('div', {'id': 'lbFindOutWhyPop'}).injectInside(this.navWrapper);
        this.findOutWhy.onclick = this.swapImage.bind(this);
        this.findOutWhy.set("html", "&middot; 理由を表示...");
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる");
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		
		//new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};
		this.fx2 = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500})
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		this.bottomContainer.style.display = 'none';
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingPop';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

    swapImage: function(){ // swap between photo and text
		if (this.findOutWhy.innerHTML.indexOf("Find") == -1) {
		    this.fx2.image.hide();
		    this.fx2.image.start(1);
		    this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
		    this.findOutWhy.set("html", "&middot; 理由を表示...");
		} else {
		    this.fx2.image.hide();
		    this.fx2.image.start(1);
		    this.image.style.backgroundImage = 'url('+this.images[this.activeImage][1]+')';
		    this.findOutWhy.set("html", "&middot; ファン ページに戻る");
		}
    },

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.navBottom.style.width = this.preload.width+'px';
			this.navWrapper.style.width = this.preload.width-12+'px';   // -12 to account for border and padding
			this.subWrapper.style.width = this.preload.width-210+'px';  // find out why + close window divs -> 210
            this.image.style.height = this.preload.height+10+'px';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.findOutWhy.set("html", "&middot; 理由を表示...");

			this.caption.style.visibility = "hidden";
			this.caption.style.display = "none";
			
			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth+18, 'marginLeft': -this.image.offsetWidth/2});    // added 18 pixels to width to account for margin and border around the image
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) this.prevLink.style.visibility = 'visible';
			if (this.activeImage != (this.images.length - 1)) this.nextLink.style.visibility = 'visible';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};

var LightboxExGallery = {
	init: function(options){
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: true,
			defaultIframeWidth : 500, 
			defaultIframeHeight: 300
		}, options || {});

		// IE 6 - XML prolog problem
		if(window.ie6 && document.compatMode=="BackCompat"){
			this.options.animateCaption = false;
		}

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxExGallery/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div').setProperty('id', 'lbOverlayExGallery').injectInside(document.body);

		this.center = new Element('div').setProperty('id', 'lbCenterExGallery').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
		
		this.closeBtnTop = new Element('a').setProperties({id: 'closeBtnTopGallery', href: '#'}).injectInside(this.center);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.canvas = new Element('div').setProperty('id', 'lbCanvasExGallery').injectInside(this.center);
		this.prevLink = new Element('a').setProperties({id: 'lbPrevLinkExGallery', 'href': '#'}).setStyle('display', 'none').injectInside(this.canvas);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkExGallery').injectInside(this.canvas);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);

		this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainerExGallery').setStyle('display', 'none').injectInside(document.body);
		this.bottom = new Element('div').setProperty('id', 'lbBottomExGallery').injectInside(this.bottomContainer);
		this.closeLink = new Element('div', {'id': 'lbCloseLinkExGallery'}).injectInside(this.bottom);
                                this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
                                this.closeLink.set("html", '&middot; ウィンドウを閉じる');

		this.caption = new Element('div').setProperty('id', 'lbCaptionExGallery').injectInside(this.bottom);
		this.number = new Element('div').setProperty('id', 'lbNumberExGallery').injectInside(this.bottom);
		//new Element('div').setStyle('clear', 'both').injectInside(this.bottom);

		/* Build effects */
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resizeCenter: this.center.set('morph', {duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect}),
            image: this.canvas.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottomContainer, {property: 'height', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title, link.rev);

		var j, itemNumber, items = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < items.length; j++) if(items[j][0] == el.href && items[j][2] == el.rev) break;
				if (j == items.length){
					items.push([el.href, el.title, el.rev]);
					if (el.href == link.href && el.rev == link.rev) itemNumber = j;
				}
			}
		}, this);
		return this.open(items, itemNumber);
	},

	show: function(url, title, rev){
		return this.open([[url, title, rev]], 0);
	},

	open: function(items, itemNumber){
		this.items = items;
		this.position();
		this.setup(true);
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeItem(itemNumber);
	},

	position: function(){
		//IE6 - XML prolog problem.
		var ww = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.overlay.setStyles({top: st+'px', height: wh+'px', width:ww+'px'});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		if (window.ie) elements.extend(document.getElementsByTagName('select'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeItem(this.activeItem-1);
	},

	next: function(){
		return this.changeItem(this.activeItem+1);
	},

	changeItem: function(itemNumber){
		if (this.step || (itemNumber < 0) || (itemNumber >= this.items.length)) return false;
		this.step = 1;
		this.activeItem = itemNumber;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingExGallery';

		// discard previous content by clicking
		this.removeCurrentItem();
		
		// check item type
		var url = this.items[this.activeItem][0];
		var rev = this.items[this.activeItem][2];
		
		var re_imageURL = /\.(jpe?g|png|gif|bmp)/i;
		if( url.match(re_imageURL) ) {
			this.preload = new Image();	// JavaScript native Object
			this.preload.datatype = 'image';
			this.preload.w = this.matchOrDefault(rev, new RegExp("width=(\\d+%?)", "i"), -1); //-1 if use original size.
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+%?)", "i"), -1);
			this.preload.onload = this.nextEffect.bind(this);
			this.preload.src = url;
		}else{
			this.preload = new Object ();	// JavaScript native Object
			this.preload.datatype = 'iframe';
			this.preload.w =  this.matchOrDefault(rev, new RegExp("width=(\\d+)", "i"), this.options.defaultIframeWidth);
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+)", "i"), this.options.defaultIframeHeight);
			this.preload.src = url;
			this.nextEffect(); //asynchronous loading
		}

		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';

			// create HTML element
			if( this.preload.datatype == 'image' ) {
				var ws = (this.preload.w == -1) ? this.preload.width.toString() : this.preload.w.toString();
				var hs = (this.preload.h == -1) ? this.preload.height.toString() : this.preload.h.toString();
				this.p_width = ( q = ws.match(/(\d+)%/) ) ? q[1] * this.preload.width * 0.01 : ws;
				this.p_height = ( q = hs.match(/(\d+)%/) ) ? q[1] * this.preload.height * 0.01 : hs;
				new Element('img').setProperties({id: 'lbImage', src:this.preload.src, width:this.p_width, height:this.p_height}).injectInside(this.canvas);
				this.nextLink.style.right = '';
			}else{
				this.p_width = this.preload.w;
				this.p_height = this.preload.h;
				// Safari would not update iframe content that has static id.
				this.iframeId = "lbFrame_"+new Date().getTime();
				new Element('iframe').setProperties({id: this.iframeId, width: this.p_width, height: this.p_height, frameBorder:0, scrolling:'no', src:this.preload.src}).injectInside(this.canvas);
				this.nextLink.style.right = '25px';
			}
			this.canvas.style.width = this.bottom.style.width = this.p_width+'px';
			this.canvas.style.height = this.prevLink.style.height = this.nextLink.style.height = this.p_height+'px';

			this.caption.set("html", this.items[this.activeItem][1] || '');
			this.number.set("html",  (this.items.length == 1) ? '' : 'ページ ' + (this.activeItem+1) +" / "+ this.items.length );

			if (this.activeItem) this.preloadPrev.src = this.items[this.activeItem-1][0];
			if (this.activeItem != (this.items.length - 1)) this.preloadNext.src = this.items[this.activeItem+1][0];
			if (this.center.clientHeight != this.canvas.offsetHeight){
				var oh = (this.p_height == this.canvas.clientHeight) ? this.canvas.offsetHeight : eval(this.p_height)+18; // fix for ie
				this.fx.resizeCenter.morph({'height': oh});
				break;
			}

			this.step++;
		case 2:
			if (this.center.clientWidth != this.canvas.offsetWidth){
				var ow = (this.p_width == this.canvas.clientWidth) ? this.canvas.offsetWidth : eval(this.p_width)+18; // fix for ie
				this.fx.resizeCenter.morph({'width': ow, 'marginLeft': -ow/2});
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height:'0px', marginLeft: this.center.style.marginLeft, width:this.center.style.width, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				// This is not smooth animation in IE 6 with XML prolog.
				// If your site is XHTML strict with XML prolog, disable this option.
				this.fx.bottom.start(0,this.bottom.offsetHeight+10);
				break;
			}
			this.bottomContainer.style.height = (this.bottom.offsetHeight)+'px';
		case 5:
			if (this.activeItem){
				this.prevLink.style.display = '';
			}
			if (this.activeItem != (this.items.length - 1)){
				this.nextLink.style.display = '';
			}
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		this.removeCurrentItem();	// discard content
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	},

	removeCurrentItem: function(){
		if (this.preload){
			if( this.preload.datatype == 'image' ) {
				$('lbImage').dispose();
				this.preload.onload = function () {}; //Class.empty;
			}else{
				$(this.iframeId).dispose();
			}
			this.preload = null;
		}		
	},

	matchOrDefault: function(str, re, val){
		var hasQuery = str.match(re);
		return hasQuery ? hasQuery[1] : val;
	}

};

var LightboxExFlash = {
	init: function(options){
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: true,
			defaultIframeWidth : 500, 
			defaultIframeHeight: 300
		}, options || {});

		// IE 6 - XML prolog problem
		if(window.ie6 && document.compatMode=="BackCompat"){
			this.options.animateCaption = false;
		}

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxExFlash/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		/*	Build float panel
			<div id="lbOverlay"></div>
			<div id="lbCenter">
				<div id="lbCanvas">
					<a id="lbPrevLink"></a>
					<a id="lbNextLink"></a>
					<!-- img or iframe element is inserted here -->
				</div>
			</div>
			<div id="lbBottomContainer">
				<div id="lbBottom">
					<a id="lbCloseLink"></a>
					<div id="lbCaption"></div>
					<div id="lbNumber"></div>
					<div style="clear:both;"></div>
				</div>
			</div>
		*/

		this.overlay = new Element('div').setProperty('id', 'lbOverlayExFlash').injectInside(document.body);

		this.center = new Element('div').setProperty('id', 'lbCenterExFlash').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
		this.canvas = new Element('div').setProperty('id', 'lbCanvasExFlash').injectInside(this.center);
		this.prevLink = new Element('a').setProperties({id: 'lbPrevLinkExFlash', href: '#'}).setStyle('display', 'none').injectInside(this.canvas);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkExFlash').injectInside(this.canvas);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);

		this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainerExFlash').setStyle('display', 'none').injectInside(document.body);
		this.bottom = new Element('div').setProperty('id', 'lbBottomExFlash').injectInside(this.bottomContainer);
		new Element('a').setProperties({id: 'lbCloseLinkExFlash', href: '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
		this.caption = new Element('div').setProperty('id', 'lbCaptionExFlash').injectInside(this.bottom);
		this.number = new Element('div').setProperty('id', 'lbNumberExFlash').injectInside(this.bottom);
		new Element('div').setStyle('clear', 'both').injectInside(this.bottom);

		/* Build effects */
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resizeCenter: this.center.set('morph', {duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect}),
            image: this.canvas.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottomContainer, {property: 'height', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title, link.rev);

		var j, itemNumber, items = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < items.length; j++) if(items[j][0] == el.href && items[j][2] == el.rev) break;
				if (j == items.length){
					items.push([el.href, el.title, el.rev]);
					if (el.href == link.href && el.rev == link.rev) itemNumber = j;
				}
			}
		}, this);
		return this.open(items, itemNumber);
	},

	show: function(url, title, rev){
		return this.open([[url, title, rev]], 0);
	},

	open: function(items, itemNumber){
		this.items = items;
		this.position();
		this.setup(true);
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.top = st + (wh / 15);
		this.center.setStyles({top: this.top+'px', display: ''});
		this.fx.overlay.start('0.8');
		return this.changeItem(itemNumber);
	},

	position: function(){
		//IE6 - XML prolog problem.
		var ww = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		this.overlay.setStyles({top: st+'px', height: wh+'px', width:ww+'px'});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		if (window.ie) elements.extend(document.getElementsByTagName('select'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeItem(this.activeItem-1);
	},

	next: function(){
		return this.changeItem(this.activeItem+1);
	},

	changeItem: function(itemNumber){
		if (this.step || (itemNumber < 0) || (itemNumber >= this.items.length)) return false;
		this.step = 1;
		this.activeItem = itemNumber;

		this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingExFlash';

		// discard previous content by clicking
		this.removeCurrentItem();
		
		// check item type
		var url = this.items[this.activeItem][0];
		var rev = this.items[this.activeItem][2];
		
		var re_imageURL = /\.(jpe?g|png|gif|bmp)/i;
		if( url.match(re_imageURL) ) {
			this.preload = new Image();	// JavaScript native Object
			this.preload.datatype = 'image';
			this.preload.w = this.matchOrDefault(rev, new RegExp("width=(\\d+%?)", "i"), -1); //-1 if use original size.
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+%?)", "i"), -1);
			this.preload.onload = this.nextEffect.bind(this);
			this.preload.src = url;
		}else{
			this.preload = new Object ();	// JavaScript native Object
			this.preload.datatype = 'iframe';
			this.preload.w =  this.matchOrDefault(rev, new RegExp("width=(\\d+)", "i"), this.options.defaultIframeWidth);
			this.preload.h = this.matchOrDefault(rev, new RegExp("height=(\\d+)", "i"), this.options.defaultIframeHeight);
			this.preload.src = url;
			this.nextEffect(); //asynchronous loading
		}

		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';

			// create HTML element
			if( this.preload.datatype == 'image' ) {
				var ws = (this.preload.w == -1) ? this.preload.width.toString() : this.preload.w.toString();
				var hs = (this.preload.h == -1) ? this.preload.height.toString() : this.preload.h.toString();
				this.p_width = ( q = ws.match(/(\d+)%/) ) ? q[1] * this.preload.width * 0.01 : ws;
				this.p_height = ( q = hs.match(/(\d+)%/) ) ? q[1] * this.preload.height * 0.01 : hs;
				new Element('img').setProperties({id: 'lbImage', src:this.preload.src, width:this.p_width, height:this.p_height}).injectInside(this.canvas);
				this.nextLink.style.right = '';
			}else{
				this.p_width = this.preload.w;
				this.p_height = this.preload.h;
				// Safari would not update iframe content that has static id.
				this.iframeId = "lbFrame_"+new Date().getTime();
				new Element('iframe').setProperties({id: this.iframeId, width: this.p_width, height: this.p_height, frameBorder:0, scrolling:'yes', src:this.preload.src}).injectInside(this.canvas);
				this.nextLink.style.right = '25px';
			}
			this.canvas.style.width = this.bottom.style.width = this.p_width+'px';
			this.canvas.style.height = this.prevLink.style.height = this.nextLink.style.height = this.p_height+'px';

			this.caption.set("html", this.items[this.activeItem][1] || '');
			this.number.set("html",  (this.items.length == 1) ? '' : 'ページ ' + (this.activeItem+1) + " / " + this.items.length );

			if (this.activeItem) this.preloadPrev.src = this.items[this.activeItem-1][0];
			if (this.activeItem != (this.items.length - 1)) this.preloadNext.src = this.items[this.activeItem+1][0];
			if (this.center.clientHeight != this.canvas.offsetHeight){
				var oh = (this.p_height == this.canvas.clientHeight) ? this.canvas.offsetHeight : eval(this.p_height)+18; // fix for ie
				this.fx.resizeCenter.morph({'height': oh});
				break;
			}

			this.step++;
		case 2:
			if (this.center.clientWidth != this.canvas.offsetWidth){
				var ow = (this.p_width == this.canvas.clientWidth) ? this.canvas.offsetWidth : eval(this.p_width)+18; // fix for ie
				this.fx.resizeCenter.morph({'width': ow, 'marginLeft': -ow/2});
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height:'0px', marginLeft: this.center.style.marginLeft, width:this.center.style.width, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				// This is not smooth animation in IE 6 with XML prolog.
				// If your site is XHTML strict with XML prolog, disable this option.
				this.fx.bottom.start(0,this.bottom.offsetHeight+10);
				break;
			}
			this.bottomContainer.style.height = (this.bottom.offsetHeight+10)+'px';
		case 5:
			if (this.activeItem){
				this.prevLink.style.display = '';
			}
			if (this.activeItem != (this.items.length - 1)){
				this.nextLink.style.display = '';
			}
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		this.removeCurrentItem();	// discard content
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	},

	removeCurrentItem: function(){
		if (this.preload){
			if( this.preload.datatype == 'image' ) {
				$('lbImageExFlash').dispose();
				this.preload.onload = function () {}; //Class.empty;
			}else{
				$(this.iframeId).dispose();
			}
			this.preload = null;
		}		
	},

	matchOrDefault: function(str, re, val){
		var hasQuery = str.match(re);
		return hasQuery ? hasQuery[1] : val;
	}

};

var LightboxAward = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 25,
			initialHeight: 25,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxAward/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayPop'}).injectInside(document.body);

		this.center = new Element('div', {'id': 'lbCenterPop', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		
		this.closeBtnTop = new Element('a').setProperties({id: 'closeBtnTopPopImg', href: '#'}).injectInside(this.center);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.image = new Element('div', {'id': 'lbImagePop'}).injectInside(this.center);
		this.awardDetails = new Element('div', {'id': 'lbAwardDetails'}).injectInside(this.center);
		this.awardHeading = new Element('div', {'id': 'lbAwardHeading'}).injectInside(this.awardDetails);
		this.awardContent = new Element('div', {'id': 'lbAwardContent'}).injectInside(this.awardDetails);
		
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerPop', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomPop'}).injectInside(this.bottomContainer);
        //this.caption = new Element('div', {'id': 'lbCaptionPop'}).injectInside(this.bottom);		
        this.navBottom = new Element('div', {'id': 'lbNavBottomPop'}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop'}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop'}).injectInside(this.navWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberPop'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
        this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		
		//new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            details: this.awardDetails.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					//images.push([el.href, el.title]);
					indexes = el.id.toString();
					var aIx = indexes.split("_");
					images.push([el.href, mainArray[aIx[0]][aIx[1]][aIx[2]]]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		//this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.bottomContainer.style.display = 'none';
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		this.fx.image.fade('hide');
		this.fx.details.fade('hide');
		this.center.className = 'lbLoadingPop';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.preload.width+'px';
			this.bottom.style.width = this.preload.width*2+2+'px';
			this.navBottom.style.width = this.preload.width*2+2+'px';
			this.navWrapper.style.width = this.preload.width*2-10+'px';   // -12 to account for border and padding
			this.subWrapper.style.width = this.preload.width*2-110+'px';
			//this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
            this.image.style.height = this.preload.height+'px';
			//this.caption.set("html", this.images[this.activeImage][1] || '');
			this.awardDetails.style.width = this.preload.width+1+'px';
			this.awardDetails.style.height = this.preload.height+'px';
			this.awardDetails.style.left = this.preload.width+11+'px';
			
			title = this.images[this.activeImage][1];
			i = title.indexOf("::");
			this.awardHeading.set("html", title.substring(0, i));
		    this.awardContent.set("html", title.substring(i+2, title.length));
			/*
            if (this.images[this.activeImage][1] != "") {
			    //this.caption.style.visibility = "visible";
			    //this.caption.style.display = "block";
			    //this.caption.style.width = this.preload.width-10+'px';  // -10 to account for left-padding
			    //this.caption.set("html", this.images[this.activeImage][1] || '');
			} else {
			    this.caption.style.visibility = "hidden";
			    this.caption.style.display = "none";
			}
			*/
			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight+10}); // add 10px to height
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth*2+18, 'marginLeft': -this.image.offsetWidth});    // added 18 pixels to width to account for margin and border around the image
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
		    this.fx.details.fade(1);
		    break;
		case 5:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 6:
			if (this.activeImage) /*this.prevLink.style.display = '';*/ this.prevLink.style.visibility = 'visible';
			if (this.activeImage != (this.images.length - 1)) /*this.nextLink.style.display = '';*/ this.nextLink.style.visibility = 'visible';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};

var LightboxCorporate = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 25,
			initialHeight: 25,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		/*$each(document.getElementsByTagName("div"), function(el){
			if (el.rel && el.rel.test(/^lightboxCorporate/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);*/
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxCorporate/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayPop'}).injectInside(document.body);

		this.center = new Element('div', {'id': 'lbCenterPop', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		
		this.closeBtnTop = new Element('a').setProperties({id: 'closeBtnTopPopImg', href: '#'}).injectInside(this.center);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.image = new Element('div', {'id': 'lbImagePop'}).injectInside(this.center);
		
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerPop', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomPop'}).injectInside(this.bottomContainer);
        this.caption = new Element('div', {'id': 'lbCaptionPopCorp'}).injectInside(this.bottom);
        this.downHigh = new Element('span', {'id': 'downloadHigh'}).injectInside(this.caption);
        this.downLow = new Element('span', {'id': 'downloadLow'}).injectInside(this.caption);
        this.downHigh.set("html", "<a href='#'>&middot; 高解像度でダウンロード</a>");
        this.downLow.set("html", "<a href='#'>&middot; 低解像度でダウンロード</a>");
        this.navBottom = new Element('div', {'id': 'lbNavBottomPop'}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop'}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop'}).injectInside(this.navWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberPop'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
                                this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		
		//new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title); // 8 for num chars in the word 'lightbox' -> signifies a single photo, not a collection

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.rev]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		//this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.bottomContainer.style.display = 'none';
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingPop';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.navBottom.style.width = this.preload.width+'px';
			this.navWrapper.style.width = this.preload.width-12+'px';   // -12 to account for border and padding
			this.subWrapper.style.width = this.preload.width-112+'px';
			//this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
            this.image.style.height = this.preload.height+'px';
			//this.caption.set("html", this.images[this.activeImage][1] || '');
            if (this.images[this.activeImage][1] != "") {
			    this.caption.style.visibility = "visible";
			    this.caption.style.display = "block";
			    this.caption.style.width = this.preload.width+'px';  // -10 to account for left-padding
			    this.downHigh.style.width = Math.floor(this.preload.width/2)-1+'px';
			    this.downLow.style.width = Math.floor(this.preload.width/2)+'px';
			    //this.caption.set("html", this.images[this.activeImage][1] || '');
			    links = this.images[this.activeImage][1]
			    i = links.indexOf("::");
			    highLink = links.substring(0, i);
			    lowLink = links.substring(i+2, links.length);
                                                    if (highLink.replace("/Images/", "") == "" && lowLink.replace("/Images/", "") == "") {
			        this.caption.style.display = "none";
			    } else {
                    if (highLink.replace("/Images/", "") == "") {
			            this.downHigh.set("html", "&nbsp;");
                    } else {
	    		        this.downHigh.set("html", "<a href='" + highLink + "'>&middot; 高解像度でダウンロード</a>");
                    }
                    if (lowLink.replace("/Images/", "") == "") {
			            this.downLow.set("html", "&nbsp;");
                    } else {
	    		        this.downLow.set("html", "<a href='" + lowLink + "'>&middot; 低解像度でダウンロード</a>");
                    }
                }
			} else {
			    this.caption.style.visibility = "hidden";
			    this.caption.style.display = "none";
			}
			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth+18, 'marginLeft': -this.image.offsetWidth/2});    // added 18 pixels to width to account for margin and border around the image
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) /*this.prevLink.style.display = '';*/ this.prevLink.style.visibility = 'visible';
			if (this.activeImage != (this.images.length - 1)) /*this.nextLink.style.display = '';*/ this.nextLink.style.visibility = 'visible';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};

var LightboxNews = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 25,
			initialHeight: 25,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightboxNews/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = new Keyboard({
			eventType: 'keydown'			
		});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlayPop'}).injectInside(document.body);

		this.center = new Element('div', {'id': 'lbCenterPop', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		
		this.closeBtnTop = new Element('a').setProperties({id: 'closeBtnTopPopImg', href: '#'}).injectInside(this.center);
		this.closeBtnTop.set("html", "閉じる");
		this.closeBtnTop.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.image = new Element('div', {'id': 'lbImagePop'}).injectInside(this.center);
		
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainerPop', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottomPop'}).injectInside(this.bottomContainer);
        this.caption = new Element('div', {'id': 'lbCaptionPop'}).injectInside(this.bottom);
        this.body = new Element('div', {'id': 'lbBodyNews'}).injectInside(this.bottom);
        //this.body.set("html", "<p></p>");
        this.visit = new Element('div', {'id': 'lbVisitNews'}).injectInside(this.bottom);
        //this.visit.set("html", "<a href=''>Visit Riviera Maya >></a>");
        this.navBottom = new Element('div', {'id': 'lbNavBottomPop'}).injectInside(this.bottom);
		this.navWrapper = new Element('div', {'id': 'lbNavWrapperPop'}).injectInside(this.navBottom);
		new Element('div', {'class': 'tlc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'trc'}).injectInside(this.navWrapper);
		new Element('div').injectInside(this.navWrapper);   // empty div added for IE6
		this.subWrapper = new Element('div', {'id': 'lbSubWrapperPop'}).injectInside(this.navWrapper);
		this.prevLink = new Element('p', {'id': 'lbPrevLinkPop'}).injectInside(this.subWrapper);
		this.number = new Element('p', {'id': 'lbNumberPop'}).injectInside(this.subWrapper);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLinkPop').injectInside(this.subWrapper);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
                                this.prevLink.set("html", '<< 前へ');
		this.nextLink.set("html", '次へ >>');
		
		this.closeLink = new Element('div', {'id': 'lbCloseLinkPop'}).injectInside(this.navWrapper);
		this.closeLink.onclick = this.overlay.onclick = this.close.bind(this);
		this.closeLink.set("html", "&middot; ウィンドウを閉じる")
		
		new Element('div').injectInside(this.navWrapper);   // emtpy div added for IE6
		new Element('div', {'class': 'blc'}).injectInside(this.navWrapper);
		new Element('div', {'class': 'brc'}).injectInside(this.navWrapper);
		
		//new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
            overlay: new Fx.Tween(this.overlay, {property: 'opacity', duration: 500}).start(0),
            resize: this.center.set('morph', $extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
            image: this.image.set('tween',  { duration: 500, onComplete: nextEffect }),
            bottom: new Fx.Tween(this.bottom, {property: 'marginTop', duration: 400, onComplete: nextEffect })
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 12) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop();
		scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});
		this.fx.overlay.start('0.4');
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.top = window.getScrollTop();
        scrollXYArray = getScrollXY();
		this.center.setStyles({top: scrollXYArray[1], display: ''});

		//this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.bottomContainer.style.display = 'none';
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		this.fx.image.fade('hide');
		this.center.className = 'lbLoadingPop';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.navBottom.style.width = this.preload.width+'px';
			this.navWrapper.style.width = this.preload.width-12+'px';   // -12 to account for border and padding
			this.subWrapper.style.width = this.preload.width-112+'px';
			//this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
            this.image.style.height = this.preload.height+'px';
			//this.caption.set("html", this.images[this.activeImage][1] || '');
            if (this.images[this.activeImage][1] != "") {
			    this.caption.style.visibility = "visible";
			    this.caption.style.display = "block";
			    this.caption.style.width = this.preload.width-10+'px';  // -10 to account for left-padding
			    title = this.images[this.activeImage][1];
			    i = title.indexOf("::");
			    j = title.indexOf("++");
			    txt1 = title.substring(0, i);
			    txt2 = title.substring(i+2, j);
			    txt3 = title.substring(j+2, title.length);
			    this.caption.set("html", txt1 || '');
			    this.body.style.width = this.preload.width+'px';
			    this.visit.style.width = this.preload.width+'px';
			    this.body.set("html", "<p>" + txt2 + "</p>");
			    this.visit.set("html", "<a href='" + txt3 + "' target='_blank'>訪問 " + txt1 + " >></a>");
			} else {
			    this.caption.style.visibility = "hidden";
			    this.caption.style.display = "none";
			}
			this.number.set("html", (!this.options.showCounter || (this.images.length == 1)) ? '' : (this.activeImage+1)+" / "+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.morph({'height': this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.morph({'width': this.image.offsetWidth+18, 'marginLeft': -this.image.offsetWidth/2});    // added 18 pixels to width to account for margin and border around the image
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.fade('1');
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.start(0, -this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) /*this.prevLink.style.display = '';*/ this.prevLink.style.visibility = 'visible';
			if (this.activeImage != (this.images.length - 1)) /*this.nextLink.style.display = '';*/ this.nextLink.style.visibility = 'visible';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = function () {}; //Class.empty;
			this.preload = null;
		}
		//for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.start('opacity', 0).chain(this.setup.pass(false, this));
		return false;
	}
};
/********************End********************* Lightbox Popups *********************End********************/

/*******************Begin******************** Notes ********************Begin*******************/
/*
No change - to line 1516
Changes -
*/
/********************End********************* Notes *********************End********************/
/********************Begin*************** URL Query Opening Table Content ****************Begin********************/
function sliderOpenOnPageLoad(){
    
    if (window.location.search != ""){
        var qString = window.location.search; //query string value
        var strVal;
        var nvPairs = new Array;
        var id;
        var id2;
        var id3;
        var id4;
        
        qString = qString.substring(1); // removes '?' from string
       
        strVal = qString.split('&'); // for muliple query name values

        // goes through and splits the nave and value at the '=' and creates a 2d array based on the pairs.
        // gets the value from each pair and associates it with the 4 elements in the dom that are needed 
        // to open the slider on the page
        for (i=0; i<strVal.length; i++){
            nvPairs[i] = strVal[i].split('=');
        }
		
		var nvLength = nvPairs.length;
		var keyContainer;
		var selectedIndex;
		
		for(i=0; i<nvLength; i++){
			if(nvPairs[i][0] == "id"){
				keyContainer = document.getElementById(nvPairs[i][1]);
				selectedIndex = (keyContainer)? parseInt(keyContainer.innerHTML) : nvPairs[i][1];
			}
		}
		
		if(selectedIndex){
			id = document.getElementById("mainCat" + selectedIndex + "Toggle");
			id2 = document.getElementById("mainCat" + selectedIndex + "Toggle1");
			id3 = document.getElementById("cat" + selectedIndex + "Content");
			id4 = document.getElementById("mc" + selectedIndex + "d");
			
			if (id) {
			 id.className = "header_selectedTTDS header_border_closed header_top";
                                                 id2.className = "upTTDS header_text";
                                                 id3.parentNode.setStyle('height', 'auto');
                                                 id3.parentNode.style.float= "left";
                                                 id3.setStyle('margin', '0px');
                                                 id4.parentNode.style.display = "none";

                                                    id.scrollIntoView()
		                }
			
		}
    } // ends if
}
/********************End*************** URL Query Opening Table Content ****************End********************/