
//global variables  
// catalogs

//var nlsCat =  new Object(eval((new XMLHttpLoader()).getSync("./data/content/artists/artists_nls_data.json")));
var nlsCatGeneral =  new Object(eval((new XMLHttpLoader()).getSync("./data/content/common_stuff/general_nls_content.json")));
var titleCycleDelay = 5000;	


//end global variables

	

dojo.addOnLoad(function(){

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");


		
		var buildUI = function(){



	    	var filestore = new dojo.data.ItemFileReadStore({
 			 	url: "../../../data/context/artists.json"
 			 });




			var slideshow = new dojox.image.SlideShow({
				slideShowInterval: 15,
				loop: false,
				autoLoad: true,
				id: 'defaultslideshow',
				autoStart: false,
				noLink: true,
				dynamicScale: 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": "0",
				"border": "none"
				});
        	
    	
				
		slideshow.setDataStore(
    	  filestore,
      		{ query: {}, count:6 },
     		{
        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:52px",
				href:"../../../pages/artists/header.html",
				splitter:false,
				id:'header_container'
			}).placeAt(outer);
			
			
			var leftregion = new dojox.layout.ContentPane({
				region:"left",	
				style:"width:52px",
				href: '../../../pages/artists/left_region.html',
				splitter:false,
				id:'left_region'
			}).placeAt(outer);


			
			
			var rightregion = new dojox.layout.ContentPane({
				region:"right",
				style:"width:52px",
				href: '../../../pages/artists/right_region.html',
				splitter:false,
				id:'right_region'
			}).placeAt(outer);
			
			
			var bottomregion = new dojox.layout.ContentPane({
				region:"bottom",
				style:"height:52px;",
				href: "../../../pages/artists/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; overflow: visible;",
				id:'the_content_title',
				href:'../../../pages/artists/title.html'
			}).placeAt(core);
			


		var core_contentpane = new dojox.layout.ContentPane({
				region:"center",
				style:"margin: auto;",
				href:"../../../pages/artists/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();};
		hidden_content = dojo.byId("work_title_hidden");
		
			dojo.subscribe(
		dijit.byId("defaultslideshow").getShowTopicName(), 
		function(packet) {
			var title = dojo.byId('image_title');
			var hidetitle = dojo.animateProperty({node: title, duration: 500, properties: {opacity: { end: 0 }},	onEnd: function(){ title.innerHTML =  packet.title;} });
			var showtitle = dojo.animateProperty({node: title, duration: 500, properties: {opacity: { end: 1 }} });

			var titlereplacer = dojo.fx.chain([hidetitle, showtitle]);

	
	titlereplacer.play();

		});

	};

		


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();}

	//internationalize footer content
	nls.regCatId("i18n_newsletter_tooltip", nlsCatGeneral.i18n_newsletter_tooltip);
				
        connectNewsLetterTooltip();


	//internationalize footer content
	nls.regCatId("i18n_slideshow_playpayse_tt", nlsCatGeneral.i18n_slideshow_playpayse_tt);
	nls.regCatId("i18n_slideshow_prev_tt", nlsCatGeneral.i18n_slideshow_prev_tt);
	nls.regCatId("i18n_slideshow_next_tt", nlsCatGeneral.i18n_slideshow_next_tt);
	nls.regCatId("i18n_newsletter_tooltip", nlsCatGeneral.i18n_newsletter_tooltip);
				

       //variables needed by the content toggling function
	setupSlideshowNaviDisplacerVars();    

	slideshowNaviDisplacer();

	var hidecontentOnSlideshow = function(force) {
	if (dojo.hasClass("slideshow_playpause","slideShowActive") && force != "1") { 
		dojo.animateProperty({node: dijit.byId("core").domNode, duration: 500, properties: {opacity: { end: 0 }}, onEnd: function(){ dojo.style(dijit.byId("core").domNode, "display", "none");} }).play();
		} else {
		dojo.animateProperty({node: dijit.byId("core").domNode, duration: 500, properties: {opacity: { end: 1 }}, onEnd: function(){ dojo.style(dijit.byId("core").domNode, "display", "block");} }).play();
		};
	};


	//this is the new slideshow navigation menu, takes context from the first slideshow widget instantiated
	dojo.connect(dojo.byId("slideshow_playpause"), "onclick", dijit.byId("defaultslideshow"), 'toggleSlideShow');
	dojo.connect(dojo.byId("slideshow_playpause"), "onclick", function(){dojo.toggleClass(dojo.byId("slideshow_playpause"),"slideShowActive");})
	dojo.connect(dojo.byId("slideshow_playpause"), "onclick", function(){hidecontentOnSlideshow();});
	dojo.connect(dojo.byId("slideshow_next"), "onclick", dijit.byId("defaultslideshow"), '_next');
	dojo.connect(dojo.byId("slideshow_prev"), "onclick", dijit.byId("defaultslideshow"), '_prev');


	dojo.subscribe(
	    dijit.byId("defaultslideshow").getShowTopicName(),
	    function(packet) {
	
	dojo[+(dijit.byId("defaultslideshow").imageIndex) < 2 ? "addClass":"removeClass"](dojo.byId("slPrev"), "slideShowCtrlHide");
    dojo[(+(dijit.byId("defaultslideshow").imageIndex) + 1) >= dijit.byId("defaultslideshow").maxPhotos ? "addClass":"removeClass"](dojo.byId("slNext"), "slideShowCtrlHide");
    dojo[(+(dijit.byId("defaultslideshow").imageIndex) === 0) && (dijit.byId("defaultslideshow").maxPhotos == 1) ? "addClass":"removeClass"](dojo.byId("slPlay"), "slideShowCtrlHide");
	if (((+(dijit.byId("defaultslideshow").imageIndex) + 1) >= dijit.byId("defaultslideshow").maxPhotos) && dojo.hasClass("slideshow_playpause","slideShowActive"))  { dojo.removeClass(dojo.byId("slideshow_playpause"),"slideShowActive");};


});

	dojo.connect(dojo.byId("i18n_gallerytext"), "onclick", function(){dijit.byId("defaultslideshow").toggleSlideShow(); 	if (dojo.hasClass("slideshow_playpause","slideShowActive")) {   dojo.toggleClass(dojo.byId("slideshow_playpause"),"slideShowActive");} togglecontent(); hidecontentOnSlideshow("1"); });

};


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(){
	
	//detect layouting fail and correct the problem  
	if (outer._contentBox.h === 0) { location.reload();}
	
	// catalogs
//	nls.regCatId("i18n_subtitle_1_transdisciplinary", nlsCat.subtitle_1_transdisciplinary);

	var artist_1 = dojo.byId("artist_1");
	var artist_2 = dojo.byId("artist_2");
//	var artist_3 = dojo.byId("artist_3");
//	var artist_4 = dojo.byId("artist_4");
//	var artist_5 = dojo.byId("artist_5");



  dojo.connect(artist_1, "onclick", dijit.byId("defaultslideshow"), function(evt) { this.showImage(+(evt.target.id.split('_')[1])); togglecontent(); });
  dojo.connect(artist_2, "onclick", dijit.byId("defaultslideshow"), function(evt) { this.showImage(+(evt.target.id.split('_')[1])); togglecontent(); });
//  dojo.connect(artist_3, "onclick", dijit.byId("defaultslideshow"), function(evt) { this.showImage(+(evt.target.id.split('_')[1])); togglecontent(); });
//  dojo.connect(artist_4, "onclick", dijit.byId("defaultslideshow"), function(evt) { this.showImage(+(evt.target.id.split('_')[1])); togglecontent(); });
//  dojo.connect(artist_5, "onclick", dijit.byId("defaultslideshow"), function(evt) { this.showImage(+(evt.target.id.split('_')[1])); togglecontent(); });


 	
	};


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();}
		
	
		//internationalize stuff
		// animations
		//static texts
		nls.regCatId("i18n_about", nlsCatGeneral.about);
		nls.regCatId("i18n_exhibitions", nlsCatGeneral.exhibitions);
		nls.regCatId("i18n_artists", nlsCatGeneral.artists);
		nls.regCatId("i18n_collaborations", nlsCatGeneral.collaborations);
		nls.regCatId("i18n_profile", nlsCatGeneral.profile);
		nls.regCatId("i18n_manifesto", nlsCatGeneral.manifesto);		
		//tooltips
		nls.regCatId("i18n_homebutton_tooltip", nlsCatGeneral.homeButtonTooltip);
		
	};


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();

dojo.connect(outer, "onLoad",  statuscheck());



		};
		
		dojo.addOnLoad(buildUI);
		


  });
	


