/**
 * Last blog loader
 */
var LastBlogItems = {
	request: "/common/scripts/commonScripts/lastBlogLoader.php",
	xml: null,
	baseurl: null,
	blogitems: null,
	initialize: function (xml) {
		this.xml = xml;
		this.baseurl = this.xml.getElementsByTagName("baseurl").item(0).firstChild.nodeValue;
		this.blogitems = this.xml.getElementsByTagName("blogitems");
		this.createBlogItemLinks();
	},
	createBlogItemLinks: function() {
		var container = document.getElementById("lastestBlogItems");
		var ul = new Element("ul", {
			id: "lastestBlogItems"
		}).injectInside(container);


		var items = this.blogitems.item(0).childNodes;
		for (var i = 0; i < items.length; i++) {
			if (typeof items[i] == 'object') {
				var date = items[i].getAttribute("date");
				var itemid = items[i].getAttribute("itemid");
				var title = items[i].firstChild.nodeValue;
				var li = new Element("li", {}).injectInside(ul);
				var a  = new Element("a", {
					href: this.baseurl + itemid,
					html: "[" + date + "]&#160;" + title
				}).injectInside(li);
			}
		}
	}
}


/**
 * [COMMON]
 * Using MooTools
 * @author	Tom Goodsun (http://www.tom-gs.com/)
 * @date	2009.01.16
 */

// Wait for the content ...
window.addEvent('domready', function() {
	/* Override SqueezeBox.close() method to customize */

	SqueezeBox.close = function(e) {
		// Confirm closing the modal if form is changed
		// Add id attribute when it is created (ref.Line 369 in SqueezeBox.js)
		if (document.getElementById("sbox-window").getElementsByTagName("iframe")[0]){
			var iframeObject = document.getElementById("sbox-window").getElementsByTagName("iframe")[0].contentWindow;
			if (iframeObject.ContactForm){
				if(iframeObject.ContactForm.getFormChanged()){
					if (!confirm(iframeObject.ContactForm.getStatusMessage("close"))){
						return this;
					}
				}
			}
		}
		// The following script is the same as the native implementation of SqueezeBox.js
		var stoppable = ($type(e) == 'event');
		if (stoppable) e.stop();
		if (!this.isOpen || (stoppable && !$lambda(this.options.closable).call(this, e))) return this;
		this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));
		this.win.setStyle('display', 'none');
		this.trash();
		this.toggleListeners();
		this.isOpen = false;
		this.fireEvent('onClose', [this.content]);
		return this;
	}

	/**
	 * That CSS selector will find all <a> elements with the
	 * class boxed
	 *
	 * The example loads the options from the rel attribute
	 */

	SqueezeBox.assign($$('a.boxed'), {
		parse: 'rel'
	});
	SqueezeBox.assign($$('a.modalimage'));


	AutoAIP.initialize({
		enableSimple   : true,
		SRCompleteMatch: false,
		enableSR       : false
	});

	/**
	 * LAST BLOG LOADER
	 */
	var myRequest = new Request({
		method: "get", 
		url: LastBlogItems.request,
		onSuccess: function(responseText, responseXML){
			LastBlogItems.initialize(responseXML);
		}
	}).send();

	if ($("slideshowStage")) {
		var flashvars = {xmlFilePath: "./common/scripts/commonScripts/slideShowImages.php"};
		var params = {xmlFilePath: "./common/scripts/commonScripts/slideShowImages.php"};
		var attributes = {};
		swfobject.embedSWF("./common/images/slideshow.swf", "slideshowStage", "588", "294", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}

	MooTwitter.initialize();

/*
	var list = {
		0: {title: "ブログのRSS", url: "http://www.tom-gs.com/blog/xml-rss2.php"}
	};
	FeedByContext.initialize(list);
*/
	
	


});
