initializeWindows = function(){

    MochaUI.searchWindow = function(search_term){
        new MochaUI.Window({
            id: 'cdmsearch',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://boundless.uoregon.edu/cdm4/results.php?app=true&' +			
                        'CISOOP1=all&CISOFIELD1=CISOSEARCHALL&CISOOP2=exact&CISOBOX2' +
                        '=&CISOFIELD2=CISOSEARCHALL&CISOOP3=any&CISOBOX3=&CISOFIELD3' +
                        '=CISOSEARCHALL&CISOOP4=none&CISOBOX4=&CISOFIELD4=CISOSEARCHALL' +
                        '&CISOROOT=/maic&app=maic&CISOBOX1=' + search_term,
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)
        });
        
    }

    MochaUI.searchGallery = function(){
        new MochaUI.Window({
            id: 'searchGallery',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://boundless.uoregon.edu/digcol/maic/site/gallery_search.php?app=maic',
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)
        });
        
    }

    MochaUI.showImage = function(image_pointer){
       
        new MochaUI.Window({
            id: 'image_detail',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://boundless.uoregon.edu/cdm4/item_viewer.php?CISOROOT=/maic&CISOBOX=1$REC=1&app=maic&CISOPTR=' + image_pointer,
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)
        });
        
    }

    MochaUI.showGallery = function(url){
       
        new MochaUI.Window({
            id: 'image_detail',
            title: '',
            loadMethod: 'iframe',
            contentURL: url + "&app=maic",
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)
        });
        
    }

    MochaUI.IneractiveMap = function(){
       
        new MochaUI.Window({
            id: 'IneractiveMap',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://mongolianaltai.uoregon.edu/components/interactive_map/map.html',
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)

        });
    }
    
    MochaUI.IneractiveMapCategory = function(category){
       
        new MochaUI.Window({
            id: 'IneractiveMapCategory',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://mongolianaltai.uoregon.edu/components/interactive_map/map.html#category=' + category,
            width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)

        });
			  if (isIE6() == true)
			    window.frames['IneractiveMapCategory_iframe'].location.reload(true)
    }
    
    MochaUI.IneractiveMapSite = function(site, category){
	
			if (category == undefined)
   			category = "Khirigsuur";

        new MochaUI.Window({
            id: 'IneractiveMapsite',
            title: '',
            loadMethod: 'iframe',
            contentURL: 'http://mongolianaltai.uoregon.edu/components/interactive_map/map.html#site=' + site + "&category=" + category,
	    width: 1024,
            height: 500,
            resizeLimit: {'x': [500, 1024], 'y': [500, 800]},
            scrollbars: true,
            padding: { top: 12, right: 12, bottom: 10, left: 12 },
            type: 'modal',
            y: ((pageHeight() - 500) / 2) + (posTop() - 50)

        });
    }
    
    	if ($('search_button')) {
            $('search_button').addEvent('click', function(e){
            new Event(e).stop();
                //grab our search value and search for it
                MochaUI.searchWindow($('search_text').value);
            });
        }
        if ($('search_gallery')) {
            $('search_gallery').addEvent('click', function(e){
            new Event(e).stop();
                MochaUI.searchGallery();
            });
        }
        if ($('home_page_search_gallery')) {
            $('home_page_search_gallery').addEvent('click', function(e){
            new Event(e).stop();
                MochaUI.searchGallery();
            });
        }
        if ($('map_link')) {
            $('map_link').addEvent('click', function(e){
            new Event(e).stop();
                MochaUI.IneractiveMap();
            });
        }
        if ($('overview_search_gallery')) {
          $('overview_search_gallery').addEvent('click', function(e){
          new Event(e).stop();
           MochaUI.searchGallery();
          });
        }
        if ($('overview_map_link')) {
          $('overview_map_link').addEvent('click', function(e){
          new Event(e).stop();
            MochaUI.IneractiveMap();
          });
        }
        if ($('map_image')) {
          $('map_image').addEvent('click', function(e){
          new Event(e).stop();
            MochaUI.IneractiveMap();
          });
        }
	if ($('map_image_home')) {
          $('map_image_home').addEvent('click', function(e){
          new Event(e).stop();
            MochaUI.IneractiveMap();
          });
        }
	
}

// Initialize MochaUI when the DOM is ready
window.addEvent('domready', function(){
    initializeWindows();
});

// This runs when a person leaves your page.
window.addEvent('unload', function(){
	if (MochaUI) MochaUI.garbageCleanUp();
});
