/* 
 This file was generated by Dashcode.  
 You may edit this file to customize your widget or web page 
 according to the license.txt file included in the project.
 */

var selectedTripId = 0;

var detailController = {
    // This object acts as a controller for the detail UI.
    
    setTripItem: function(tripItem) {
        this._tripItem = tripItem;
        this._representedObject = tripItem.name;

        var detailForeignPrice = document.getElementById('detailForeignPrice');
        detailForeignPrice.innerHTML = this._tripItem.foreignPrice;
        var detailName = document.getElementById('detailName');
        detailName.innerHTML = this._tripItem.name;
        var detailShop = document.getElementById('detailShop');
        detailShop.innerHTML = this._tripItem.shopName;
        var detailTime = document.getElementById('detailTime');
        detailTime.innerHTML = this._tripItem.time;
        var detailCurrency = document.getElementById('detailCurrency');
        detailCurrency.innerHTML = this._tripItem.currency;
        var detailRate = document.getElementById('detailRate');
        detailRate.innerHTML = this._tripItem.rate;
        var imageFile = tripItem.thumbnail;
        if (imageFile == "") {
            detailThumbnail.style.background =  "url(Images/thumbnailI0.png)";
        }
        else {
            detailThumbnail.style.background =  "url(" + imageFile + ")";
        }
    }
    
};

//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
    dashcode.setupParts();
}


// This object implements the dataSource methods for the list.
var tripController0 = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		return trips0.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.label0) {
			templateElements.label0.innerText = trips0[rowIndex].name;
		}
        
        if (templateElements.dateLabel0) {
			templateElements.dateLabel0.innerText = trips0[rowIndex].date;
        }

		// Assign a click event handler for the row.
		rowElement.onclick = function(event) {
        
        

            listController0.setTripId(rowIndex + 0);
			document.getElementById('tripItemListI0').object.reloadData();
            listController1.setTripId(rowIndex + 0);
			document.getElementById('tripItemListI1').object.reloadData();
            listController2.setTripId(rowIndex + 0);
			document.getElementById('tripItemListI2').object.reloadData();
            var browser = document.getElementById('browser').object;
            browser.goForward(document.getElementById('listLevel'), trips0[rowIndex].name);
//            document.getElementById("rectangleShape1").style.visibility='visible';
//            document.getElementById("rectangleShape1").style.visibility='hidden';
		};
	}
};

// This object implements the dataSource methods for the list.
var tripController1 = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		return trips1.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.label1) {
			templateElements.label1.innerText = trips1[rowIndex].name;
		}
        
        if (templateElements.dateLabel1) {
			templateElements.dateLabel1.innerText = trips1[rowIndex].date;
        }

		// Assign a click event handler for the row.
		rowElement.onclick = function(event) {
        
        

            listController0.setTripId(rowIndex + 1);
			document.getElementById('tripItemListI0').object.reloadData();
            listController1.setTripId(rowIndex + 1);
			document.getElementById('tripItemListI1').object.reloadData();
            listController2.setTripId(rowIndex + 1);
			document.getElementById('tripItemListI2').object.reloadData();
            var browser = document.getElementById('browser').object;
            browser.goForward(document.getElementById('listLevel'), trips1[rowIndex].name);
//            document.getElementById("rectangleShape1").style.visibility='visible';
//            document.getElementById("rectangleShape1").style.visibility='hidden';
		};
	}
};


var listController0 = {
    tripId: 0,

    setTripId: function(tripId) {
        this.tripId = tripId;
        selectedTripId = tripId;
		
		if (document.getElementById('textI0a') && dayItems[tripId] && dayItems[tripId][0]) {
            document.getElementById('textI0a').innerText = dayItems[tripId][0].dayString;
        }
        if (document.getElementById('textI0b') && dayItems[tripId] && dayItems[tripId][0]) {
            document.getElementById('textI0b').innerText = dayItems[tripId][0].timeString;
        }
    },
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
//        return tripItems[this.tripId][0].length;
		
		if (tripItems[this.tripId] && tripItems[this.tripId][0]) {
            document.getElementById("tripItemSectionI0").style.visibility='visible';
            document.getElementById("tripItemSectionI0").style.height='40px';
            return tripItems[this.tripId][0].length;
        }
        else {
            document.getElementById("tripItemSectionI0").style.visibility='hidden';
            document.getElementById("tripItemSectionI0").style.height='0px';
            return 0;
        }
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        if (templateElements.foreignPriceLabelI0) {
            templateElements.foreignPriceLabelI0.innerText = tripItems[this.tripId][0][rowIndex].foreignPrice;
        }
        if (templateElements.homePriceLabelI0) {
            templateElements.homePriceLabelI0.innerText = tripItems[this.tripId][0][rowIndex].homePrice;
        }
        if (templateElements.nameLabelI0) {
            templateElements.nameLabelI0.innerText = tripItems[this.tripId][0][rowIndex].name;
        }
        if (templateElements.shopNameLabelI0) {
            templateElements.shopNameLabelI0.innerText = tripItems[this.tripId][0][rowIndex].shopName;
        }
        if (templateElements.thumbnailI0) {
            var imageFile = tripItems[this.tripId][0][rowIndex].thumbnail;
            if (imageFile == "") {
                templateElements.thumbnailI0.style.background = "url(Images/thumbnailI0.png)";
            }
            else {
                templateElements.thumbnailI0.style.background = "url(" + imageFile + ")";
            }
        }
        
        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        rowElement.onclick = function(event) {
            var tripItem = tripItems[selectedTripId][0][rowIndex];
            detailController.setTripItem(tripItem);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevel'), tripItem.name);
        };
    }
};



var listController1 = {
    tripId: 0,

    setTripId: function(tripId) {
        this.tripId = tripId;
        selectedTripId = tripId;
		
		if (document.getElementById('textI1a') && dayItems[tripId] && dayItems[tripId][1]) {
            document.getElementById('textI1a').innerText = dayItems[tripId][1].dayString;
        }
        if (document.getElementById('textI1b') && dayItems[tripId] && dayItems[tripId][1]) {
            document.getElementById('textI1b').innerText = dayItems[tripId][1].timeString;
        }
    },
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
//        return tripItems[this.tripId][1].length;
		
		if (tripItems[this.tripId] && tripItems[this.tripId][1]) {
            document.getElementById("tripItemSectionI1").style.visibility='visible';
            document.getElementById("tripItemSectionI1").style.height='40px';
            return tripItems[this.tripId][1].length;
        }
        else {
            document.getElementById("tripItemSectionI1").style.visibility='hidden';
            document.getElementById("tripItemSectionI1").style.height='0px';
            return 0;
        }
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        if (templateElements.foreignPriceLabelI1) {
            templateElements.foreignPriceLabelI1.innerText = tripItems[this.tripId][1][rowIndex].foreignPrice;
        }
        if (templateElements.homePriceLabelI1) {
            templateElements.homePriceLabelI1.innerText = tripItems[this.tripId][1][rowIndex].homePrice;
        }
        if (templateElements.nameLabelI1) {
            templateElements.nameLabelI1.innerText = tripItems[this.tripId][1][rowIndex].name;
        }
        if (templateElements.shopNameLabelI1) {
            templateElements.shopNameLabelI1.innerText = tripItems[this.tripId][1][rowIndex].shopName;
        }
        if (templateElements.thumbnailI1) {
            var imageFile = tripItems[this.tripId][1][rowIndex].thumbnail;
            if (imageFile == "") {
                templateElements.thumbnailI1.style.background = "url(Images/thumbnailI0.png)";
            }
            else {
                templateElements.thumbnailI1.style.background = "url(" + imageFile + ")";
            }
        }
        
        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        rowElement.onclick = function(event) {
            var tripItem = tripItems[selectedTripId][1][rowIndex];
            detailController.setTripItem(tripItem);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevel'), tripItem.name);
        };
    }
};



var listController2 = {
    tripId: 0,

    setTripId: function(tripId) {
        this.tripId = tripId;
        selectedTripId = tripId;
		
		if (document.getElementById('textI2a') && dayItems[tripId] && dayItems[tripId][2]) {
            document.getElementById('textI2a').innerText = dayItems[tripId][2].dayString;
        }
        if (document.getElementById('textI2b') && dayItems[tripId] && dayItems[tripId][2]) {
            document.getElementById('textI2b').innerText = dayItems[tripId][2].timeString;
        }
    },
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
//        return tripItems[this.tripId][2].length;
		
		if (tripItems[this.tripId] && tripItems[this.tripId][2]) {
            document.getElementById("tripItemSectionI2").style.visibility='visible';
            document.getElementById("tripItemSectionI2").style.height='40px';
            return tripItems[this.tripId][2].length;
        }
        else {
            document.getElementById("tripItemSectionI2").style.visibility='hidden';
            document.getElementById("tripItemSectionI2").style.height='0px';
            return 0;
        }
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        if (templateElements.foreignPriceLabelI2) {
            templateElements.foreignPriceLabelI2.innerText = tripItems[this.tripId][2][rowIndex].foreignPrice;
        }
        if (templateElements.homePriceLabelI2) {
            templateElements.homePriceLabelI2.innerText = tripItems[this.tripId][2][rowIndex].homePrice;
        }
        if (templateElements.nameLabelI2) {
            templateElements.nameLabelI2.innerText = tripItems[this.tripId][2][rowIndex].name;
        }
        if (templateElements.shopNameLabelI2) {
            templateElements.shopNameLabelI2.innerText = tripItems[this.tripId][2][rowIndex].shopName;
        }
        if (templateElements.thumbnailI2) {
            var imageFile = tripItems[this.tripId][2][rowIndex].thumbnail;
            if (imageFile == "") {
                templateElements.thumbnailI2.style.background = "url(Images/thumbnailI0.png)";
            }
            else {
                templateElements.thumbnailI2.style.background = "url(" + imageFile + ")";
            }
        }
        
        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        rowElement.onclick = function(event) {
            var tripItem = tripItems[selectedTripId][2][rowIndex];
            detailController.setTripItem(tripItem);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevel'), tripItem.name);
        };
    }
};

var trips0 = [
{name: "London Trip", date: "Apr 10 - Apr 19" },];
var trips1 = [
{name: "Paris Trip", date: "Nov 20 - Nov 30" },];

var tripItems = [
[
[
{ foreignPrice: "£108.00", homePrice: "$161.85", name: "Silver Bracelet", shopName: "Links of London", time: "4/15/09 10:54 PM", currency: "U.S. Dollar", rate: "161.8488", thumbnail: "Images/i4.png"},
{ foreignPrice: "£2.49", homePrice: "$3.73", name: "Coin bag", shopName: "H&M", time: "4/15/09 10:51 PM", currency: "U.S. Dollar", rate: "3.7315", thumbnail: "Images/i3.png"},
{ foreignPrice: "£30.00", homePrice: "$44.96", name: "Flip flop", shopName: "Miss Sixty", time: "4/15/09 10:47 PM", currency: "U.S. Dollar", rate: "44.958", thumbnail: "Images/i2.png"},
],
[
{ foreignPrice: "£25.99", homePrice: "$34.26", name: "Tote Bag", shopName: "Accessorize", time: "4/14/09 8:39 PM", currency: "U.S. Dollar", rate: "34.26", thumbnail: "Images/i1.png"},
],
],
[
[
{ foreignPrice: "€399.99", homePrice: "$527.27", name: "Leather jacket", shopName: "French Connection", time: "11/29/08 6:21 PM", currency: "U.S. Dollar", rate: "527.2668", thumbnail: "Images/i8.png"},
],
[
{ foreignPrice: "€17.59", homePrice: "$23.19", name: "Mickey Mouse plush", shopName: "Disney Store", time: "11/28/08 2:27 PM", currency: "U.S. Dollar", rate: "23.1871", thumbnail: "Images/i7.png"},
],
[
{ foreignPrice: "€12.00", homePrice: "$15.82", name: "Body lotion", shopName: "Crabtree & Evelyn", time: "11/26/08 4:50 PM", currency: "U.S. Dollar", rate: "15.8184", thumbnail: "Images/i5.png"},
{ foreignPrice: "€75.00", homePrice: "$98.86", name: "Dunk low", shopName: "Nike", time: "11/26/08 5:19 AM", currency: "U.S. Dollar", rate: "98.865", thumbnail: "Images/i6.png"},
],
],
];

var dayItems = [
[
{dayString:"Day 6 (Wed)", timeString:"Apr 15, 2009"},
{dayString:"Day 5 (Tue)", timeString:"Apr 14, 2009"},
],
[
{dayString:"Day 11 (Sat)", timeString:"Nov 29, 2008"},
{dayString:"Day 10 (Fri)", timeString:"Nov 28, 2008"},
{dayString:"Day 8 (Wed)", timeString:"Nov 26, 2008"},
],
];
