var KUTA = {};

KUTA.ImageViewer = {

    show: function(id) {

        var title;
        var name;

        switch(id){
        case 1:
            title="Balinese Style Bungalows"; name="Balinese style bungalows"; break;
        case 2:
            title="Standard Bungalows"; name="Standard bungalows"; break;
        case 3:
            title="Deluxe Cottages"; name="Deluxe cottages"; break;
        case 4:
            title="Standard Cottages"; name="Standard cottages"; break;
        case 5:
            title="Pool"; name="poolside shots"; break;
        }

        var container = new YAHOO.widget.Panel(document.body.appendChild(document.createElement("div")), {
            width:"500px",
            fixedcenter: true,
            visible:false,
            draggable:true,
            close:true,
            modal: true }
        );
        container.hideEvent.subscribe(this.panelClose);

        //IE does not like carousel.addItem(); therfore have to build markup //
        var carouselHeader = "<p>See below for some images of our " + name + "</p><div id=\"carouselContainer\"><ol id=\"carousel\">";
        var carouselFooter = "</ol></div>";
        var carouselBody;
        
        switch(id){
        case 1:
            carouselBody = "<li><img src=\"/images/roomDetail/CNV00025.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00033.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00019.JPG\" height=\"350\" width=\"475\" /></li>";
            break;
        case 2:
            carouselBody = "<li><img src=\"/images/roomDetail/DSC_0241.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/DSC_0245.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/DSC_0256.JPG\" height=\"350\" width=\"475\" /></li>";
            break;
        case 3:
            carouselBody = "<li><img src=\"/images/roomDetail/CNV00018.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00013.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00016.JPG\" height=\"350\" width=\"475\" /></li>";
            break;
        case 4:
            carouselBody = "<li><img src=\"/images/roomDetail/CNV00004.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00007.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/roomDetail/CNV00012.JPG\" height=\"350\" width=\"475\" /></li>";
            break;
        case 5:
            carouselBody = "<li><img src=\"/images/poolDetail/P1010162.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/poolDetail/P1010168.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/poolDetail/P1010160.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/poolDetail/P1010170.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/poolDetail/P1010279.JPG\" height=\"350\" width=\"475\" /></li>" +
                        "<li><img src=\"/images/poolDetail/P1010199.JPG\" height=\"350\" width=\"475\" /></li>";
            break;
        }

        container.setBody(carouselHeader + carouselBody + carouselFooter);
        container.setHeader(title);
        container.render();

        var carousel = new YAHOO.widget.Carousel("carouselContainer", { isCircular: false, numVisible: 1 } );
        carousel.set("selectedItem", 0);
        carousel.render();
        
        carousel.show();
        container.show();
    },

    panelClose: function(e) {
        try {
            this.destroy();
        } catch(err) {
            alert(err);
            //this will catch: this.configChangedEvent is null - NO IT DOESNT
        }
    }
}

KUTA.Email = {
    emailDialog: null,

	handleSubmit: function() {
		this.submit();
	},
    
	handleCancel: function() {
		this.cancel();
	},
    
	handleSuccess: function(o) {
		alert("Email sent. You should hear back shortly.");
	},
    
	handleFailure: function(o) {
		alert("Submission failed: " + o.status);
	},

    validate: function() {
        var data = this.getData();
        if (data.name == "" || data.email == "" || data.content == "") {
            alert("Please enter all fields.");
            return false;
        } else {
            return true;
        }
    },

    show: function() {
        this.emailDialog = new YAHOO.widget.Dialog(document.body.appendChild(document.createElement("div")),
            { width : "30em",
              fixedcenter : true,
              visible : false,
              modal: true,
              constraintoviewport : true,
              hideaftersubmit: true,
              buttons : [ { text:"Submit", handler:this.handleSubmit, isDefault:true },
                          { text:"Cancel", handler:this.handleCancel } ]
            }
        );
        this.emailDialog.validate = this.validate;
        this.emailDialog.callback = { success: this.handleSuccess, failure: this.handleFailure };
        this.emailDialog.setBody("<p>" +
                                    "Please use the following form or send an email directly " +
                                    "to <a href=\"mailto:info@kutapuri.com\">info@kutapuri.com</a>" +
                                 "</p>" +
                                 "<form action=\"/cgi-bin/email.cgi\" method=\"POST\">" +
                                 "  <input type=\"hidden\" name=\"recipient\" value=\"info@kutapuri.com\">" +
                                 "  <input type=\"hidden\" name=\"subject\" value=\"Online query via www.kutapuri.com\">" +
                                 "  <label for=\"name\">Name: </label><input name=\"name\" type=\"text\" size=\"32\"><br />" +
                                 "  <label for=\"email\">Email:</label><input name=\"email\" type=\"text\" id=\"email\" size=\"32\"><br />" +
                                 "  <label for=\"content\">Query:</label><textarea name=\"content\" cols=\"32\" rows=\"5\"></textarea>" +
                                 "</form>");
        this.emailDialog.setHeader("Contact Us");

        this.emailDialog.render();
        this.emailDialog.show();
    }
};
