

//global variables  
// catalogs

var nlsNavigationElementsCat = new Object(eval((new XMLHttpLoader()).getSync("./data/content/common_stuff/navigation_elements.json"))); 
var nlsGenCat =  new Object(eval((new XMLHttpLoader()).getSync("./data/content/index/index_nls_data.json")));

//end global variables

	

dojo.addOnLoad(function(){
//hide the indexed content
dojo.style(dojo.byId("autohide"), "display", "none");
//require all the rest and start the magic
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.StackContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.dijit"); // optimize: load dijit layer
dojo.require("dojox.image.SlideShow");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.Tooltip");
dojo.require("dijit.Dialog");
dojo.require("dojox.layout.ContentPane");
dojo.require("dijit.TooltipDialog");


		
		var buildUI = function(){



	    	var filestore = new dojo.data.ItemFileReadStore({
 			 	url: "../../../data/context/index.json"
 			 });




			var slideshow = new dojox.image.SlideShow({
				slideShowInterval: 10,
				loop: true,
				autoLoad: true,
				id: 'defaultslideshow',
				autoStart: false,
				dynamicScale: true,
				hasNav: false,
				noLink: true
				}).placeAt(dojo.body());
		
			
			dojo.style(dijit.byId("defaultslideshow").domNode, {
				"position": "absolute",
				"left": "0px",
				"top": "0px",
				"width": "100%",
				"height": "100%",
				"text-align": "left",
				"margin": "0px",
				"padding": "0px",
				"z-index": "-1",
				"border": "none"
				});
        	
    	
				
		slideshow.setDataStore(
    	  filestore,
      		{ query: {}, count:3 },
     		{
        imageThumbAttr: "thumb",
        imageLargeAttr: "large"
      		}
    	);
				
		
			
		
			// the main BC
			var outer = new dijit.layout.BorderContainer({
				gutters: false,
				id: 'outer'
			}).placeAt(dojo.body());
			


			
			dojo.style(dijit.byId("outer").domNode, {
				"height": "100%",
            	"width": "100%"
        	});

			
			// top region:
			var topregion = new dojox.layout.ContentPane({
				region:"top",
				style:"height:30px",
				href:"../../../pages/index/header.html",
				splitter:false,
				id:'header_container'
			}).placeAt(outer);
			
			
			var leftregion = new dojox.layout.ContentPane({
				region:"left",	
				style:"width:30px",
				href: '../../../pages/index/left_region.html',
				splitter:false,
				id:'left_region'
			}).placeAt(outer);
	
			
			var rightregion = new dojox.layout.ContentPane({
				region:"right",
				style:"width:10px",
				href: '../../../pages/index/right_region.html',
				splitter:false,
				id:'right_region'
			}).placeAt(outer);
			
			
			var bottomregion = new dojox.layout.ContentPane({
				region:"bottom",
				style:"height:24px;",
				href: "../../../pages/index/footer_content.html",
				splitter:false,
				id: "bottom_region"
			}).placeAt(outer);
			
			
			var core = new dijit.layout.BorderContainer({ 
				region:"center", 
				style:"overflow: hidden;", 
				design: "sidebar", 
				gutters: false,
				id: 'core'
			}).placeAt(outer);


		var hiddentitle = new dojox.layout.ContentPane({
				region:"top",
				style:"height:99px;",
				id:'the_content_title',
				href:'../../../pages/index/title.html'
			}).placeAt(core);
			

		var core_contentpane = new dojox.layout.ContentPane({
				region:"center",
				style:"margin: auto;",
				href:"../../../pages/index/index_content.html",
				id:'the_content'
			}).placeAt(core);
			




			var statuscheck = function(){	




					var titlescript = function(){

					//detect layouting fail and correct the problem  
					if (outer._contentBox.h === 0) { location.reload();};

				};




			var titlescript_trigger = function(){return (dijit.byId("the_content_title").isLoaded === true) ? titlescript : dojo.connect(dijit.byId("the_content_title"),"onLoad", titlescript);};



			titlescript_trigger();


				var footerscript = function(){
				//detect layouting fail and correct the problem  
				if (outer._contentBox.h === 0) { location.reload();}

				//connect newsletter form


				//internationalize footer content

				//end internationalization
			
			};

			var footerscript_trigger = function(){return (dijit.byId("bottom_region").isLoaded === true) ? footerscript : dojo.connect(dijit.byId("bottom_region"),"onLoad", footerscript);};

			footerscript_trigger();


			var contentscript = function(){



		//content stuff 

			//detect layouting fail and correct the problem  
			if (outer._contentBox.h === 0) { location.reload();}
		
			// content stuff
	loadNlsLangFromCookie();
	nls.regCatId("i18n_descriptionText", nlsGenCat.descriptionText);
//	nls.regCatId("i18n_viewcollection", nlsGenCat.viewcollection);
//	nls.regCatId("i18n_bloglink_home", nlsGenCat.blogLink);

//	nls.regCatId("i18n_womens_home", nlsGenCat.womans);
//	nls.regCatId("i18n_children_home", nlsGenCat.children);			

	nls.regCatId("i18n_worldwide", nlsGenCat.worldwide);
	nls.regCatId("i18n_northItaly", nlsGenCat.northItaly);
	nls.regCatId("i18n_northItaly2", nlsGenCat.northItaly);	
	nls.regCatId("i18n_southTyrol1", nlsGenCat.southTyrolOnly);
	nls.regCatId("i18n_southTyrol2", nlsGenCat.southTyrol);
	nls.regCatId("i18n_southTyrol3", nlsGenCat.southTyrol);	
	nls.regCatId("i18n_southTyrol4", nlsGenCat.southTyrol);
	nls.regCatId("i18n_southTyrol5", nlsGenCat.southTyrol);
	nls.regCatId("i18n_southTyrol6", nlsGenCat.southTyrol);
    nls.regCatId("i18n_products", nlsNavigationElementsCat.products);


			//end content stuff



		};


	var contentscript_trigger = function(){return (dijit.byId("the_content").isLoaded === true) ? contentscript : dojo.connect(dijit.byId("the_content"),"onLoad", contentscript);};

	contentscript_trigger();



	var headerscript = function(){

			//detect layouting fail and correct the problem  
			if (outer._contentBox.h === 0) { location.reload();}


		//header stuff 	
	nls.regCatId("i18n_bloglink", nlsNavigationElementsCat.bloglink);	
	nls.regCatId("i18n_contact", nlsNavigationElementsCat.contact);	
	
		//end header stuff
				};


			var headerscript_trigger = function(){return (dijit.byId("header_container").isLoaded === true) ? headerscript : dojo.connect(dijit.byId("header_container"),"onLoad", headerscript);};

			headerscript_trigger();



				};



				// do all the layout etc
				outer.startup();

				statuscheck();
				//dojo.connect(outer, "onLoad",  statuscheck);



					};

				dojo.addOnLoad(buildUI);



			  });






			








