/*
 * Copyright (c) 2009, The Walt Disney Company All Rights Reserved.
 */


dojo._xdResourceLoaded(function (dojo, dijit, dojox) {
	return {depends:[["provide", "com.family.gap_12152009.entry.Entry"], ["require", "com.family.gap_12152009.Page"], ["require", "com.family.gap_12152009.vote.VoteBox"], ["require", "com.family.gap_12152009.search.SearchEntries"], ["require", "com.family.util.UI"]], defineResource:function (dojo, dijit, dojox) {
		if (!dojo._hasResource["com.family.gap_12152009.entry.Entry"]) {
			dojo._hasResource["com.family.gap_12152009.entry.Entry"] = true;
			dojo.provide("com.family.gap_12152009.entry.Entry");
			dojo.require("com.family.gap_12152009.Page");
			dojo.require("com.family.gap_12152009.vote.VoteBox");
			dojo.require("com.family.gap_12152009.search.SearchEntries");
			dojo.require("com.family.util.UI");
			uiUtil = com.family.util.UI;
			dojo.declare("com.family.gap_12152009.entry.Entry", [com.family.gap_12152009.Page], {userObject:null, imgList:[], currentStartIndex:0, constructor:function (document) {
				this._document = document;
				dojo.addOnLoad(dojo.hitch(this, "_onLoad"));
				dojo.NodeList.prototype.removeAttr = dojo.NodeList._adaptAsForEach(dojo.removeAttr);
				dojo.subscribe("com.family.gap_12152009.entry.Entry.ImgListChanged", dojo.hitch(this, "imgList_changed"));
			}, _onLoad:function () {
				this.inherited(arguments);
				this.makeMagicButtons();
				this.makeMagicImages();
				uiUtil.makeHoverable(".printList li a");
				try {
					this.imgList = dojo.fromJson(dojo.byId("imgSrcList").value);
					this.reloadCarousel();
				}
				catch (e) {
				}
			}, cycleImgListForward:function () {
				var el = this.imgList.shift();
				this.imgList.push(el);
				dojo.publish("com.family.gap_12152009.entry.Entry.ImgListChanged", [{imgList:this.imgList}]);
			}, cycleImgListBackward:function () {
				var el = this.imgList.pop();
				this.imgList.unshift(el);
				dojo.publish("com.family.gap_12152009.entry.Entry.ImgListChanged", [{imgList:this.imgList}]);
			}, imgList_changed:function (evt) {
				this.reloadCarousel();
			}, reloadCarousel:function () {
				var thumbSrc1 = "";
				var thumbSrc2 = "";
				var thumbSrc3 = "";
				if (this.imgList[0]) {
					dojo.attr("carouselThumb1", "src", this.imgList[0].imgSrc);
					dojo.style("carouselThumb1", "display", "block");
				} else {
					dojo.style("carouselThumb1", "display", "none");
				}
				if (this.imgList[1]) {
					dojo.attr("carouselThumb2", "src", this.imgList[1].imgSrc);
					dojo.style("carouselThumb2", "display", "block");
				} else {
					dojo.style("carouselThumb2", "display", "none");
				}
				if (this.imgList[2]) {
					dojo.attr("carouselThumb3", "src", this.imgList[2].imgSrc);
					dojo.style("carouselThumb3", "display", "block");
				} else {
					dojo.style("carouselThumb3", "display", "none");
				}
			}, makeMagicButtons:function () {
				uiUtil.makeHoverable(".imageNav button");
				dojo.query(".imageNav button").connect("onclick", dojo.hitch(this, "imageList_click"));
			}, imageList_click:function (evt) {
				if (evt.target.value == "forward") {
					this.cycleImgListForward();
				} else {
					if (evt.target.value == "back") {
						this.cycleImgListBackward();
					}
				}
			}, makeMagicImages:function () {
				uiUtil.makeHoverable(".imageList img");
				dojo.query(".imageList img").connect("onclick", dojo.hitch(this, "imgListImg_click"));
			}, imgListImg_click:function (evt) {
				var idx = evt.target.id.substring(evt.target.id.length - 1, evt.target.id.length) - 1;
				evt.target.blur();
				this.goToDetail(this.imgList[idx].userName, this.imgList[idx].entryId);
			}, goToDetail:function (username, entryId) {
				window.location = "../../" + username + "/" + entryId + "/";
			}});
			window._ThisPage = new com.family.gap_12152009.entry.Entry(document);
		}
	}};
});

