var $defined = function (a) {
	return (a !== undefined && a !== null);
};

var $is_empty = function (a) {
	return (a === null || a === '');
};

var Showroom = new Class({
	Implements: [Options,Events,Chain],
	
	options: {
		showroom_wrapper: 'pgt_showroom',
		content_wrapper: 'pgt_sh_content_section',
		header_wrapper: 'header',
		right_content: 'showroom_right_content',
		nav: 'pgt_showroom_main_nav',
		'loadingClass': 'loading',
		mask: {
			'opacitySelector': '.opa',
			'simple': 'mask',
			'double': 'dualmask',
			'complete': 'completemask'
		},
		price: 'pgt_sh_pricearea',
		breadcrumb: {
			from_selector: 'ul#kpp_showroom_breadcrumb',
			to_selector: '#breadcrumb'
		},
		tooltips: {
			selector: '.infos .i',
			tipsOpt: {
				fixed: true,
				onShow: function (tip, el) {
					if (tip.retrieve('size') == null) {
						var size = -(tip.getWidth().toInt() + 4) + 'px';
						tip.store('size', size);
					}
					else {
						var size = tip.retrieve('size');
					}
					tip.setStyles({
						'display':'block',
						'margin-left': size
					});
					if (Browser.ie7) {
						tip.getFirst().setStyle('width', (0 - size.toInt()) + 'px');
					}
				}
			}
		},
		navigation: {
			homeClass: 'home',
			toggler: 'a',
			activeClass: 'active',
			selector: '.subnav ul',
			openOnLoadClass: 'openonload',
			openOnLoadTime: 3, // in seconds
			letOpenClass: 'letopen',
			alreadySetClass: 'slideSet',
			slideOpt: {}
		},
		share: {
			main: {
				toggler: 'pgt_sh_mainshare',
				sharebox: '#pgt_sh_mainshare .tip-wrap'
			},
			plus_class: 'pgt_sh_addthis',
			download_class: 'pgt_sh_download'
		},
		intro: {
			'classname': 'pgt_sh_intro',
			content_id: 'pgt_sh_introflash'
		},
		hotspots: {
			ratio: 1.36,
			wrapper: {
				id: 'showroom_hotspots',
				points: 'showroom_hotspots_items'
			},
			direction: {
				wrapper: '#showroom_hotspots_items',
				selector: '#showroom_hotspots_items li',
				security: 95 // in %
			},
			desc: {
				toggler: 'ctd',
				main: 'showroom_hotspot_description',
				wrapper: 'sh_tg_description',
				delay: 2000 // in milliseconds
			},
			zoom: {
				wrapper: 'showroom_hotspot_zoom',
				subwrapper: 'showroom_hotspot_zoom_sub',
				background: 'sh_tg_img',
				swf: 'sh_tg_swf',
				video: 'sh_tg_video',
				table_xls: 'sh_tg_table',
				toolbar: 'showroom_toolbar',
				width: 738, // in pixels
				height: 348, // in pixels
				close_toolbar_class: 'close'
			}
		},
		videos: {
			wrapper: {
				id: 'showroom_videos'
			},
			player_id: 'player_replacement',
			player_src: 'showroom_playervideo.swf',
			player_width: 738, // in pixels
			player_height: 348, // in pixels
			flashvars: {
				'color': '0x5ac9fb'
			}
		},
		tcs: { // 360
			wrapper: {
				id: 'showroom_tcs'
			},
			flash_id: 'flash_replacement',
			flash_width: 738, // in pixels
			flash_height: 348, // in pixels
			flashvars: {
				'color': '0x5ac9fb'
			}
		},
		photos: {
			wrapper: {
				id: 'showroom_gallery',
				points : 'sh_g_medias'
			},
			controls: {
				left: 'toleft',
				right: 'toright'
			},
			nav: {
				'classname': 'sh_g_nav',
				wrapper : 'sh_g_w_n',
				wrapwrapper: 'sh_g_ww_n',
				thumb_prefix: 'thumb-',
				sd_prefix: 'sd-',
				init_show_delay: 3000, // in milliseconds
				toggler_size: 38 // in pixels
			},
			toolbar: {
				'classname': 'showroom_toolbar wide',
				left: 'left',
				zoom: 'zoom'
			},
			zoom: {
				popin: 'pgt_sh_popin',
				wrapper: 'pgt_sh_popin_wrapper',
				list: 'pgt_sh_popin_list'
			},
			activeClass: 'active',
			zoomlink: 'zoom'
		},
		swfobject: {
			'prefixid': 'target-hd-',
			'flashvars': {},
			'attributes': {
				'style': 'background-color:black;'
			},
			'params': {
				'menu': "true",
				'quality': "high",
				'pluginspage': "http://www.macromedia.com/go/getflashplayer",
				'align': "middle",
				'play': "true",
				'loop': "true",
				'scale': "showall",
				'bgcolor': "#000000",
				'wmode': "transparent",
				'devicefont': "false",
				'allowFullScreen': "true",
				'allowScriptAccess': "always",
				'salign': ""
			},
			'width': 960, // in pixels
			'height': 422, // in pixels
			'flashversion': '10.0.0',
			'src': 'showroom_zoom.swf'
		},
		labels: {
			hotspots_zoom_shareon: 'Partager sur',
			hotspots_zoom_close : 'Fermer',
			photo_zoom_link: 'Zoom',
			photos_zoom_shareon: 'Partager sur',
			photos_zoom_close: 'Fermer'
		}
	},
	
	params: {
		type: {},
		levels: {},
		hashs: {}
	},
	
	initialize: function (json_url, options) {
		// #Options
		this.setOptions(options);

		// #Intro
		this.checkIntro();
		
		// #BREADCRUMB + #TOOLTIPS + #JSON
		this.setBreadcrumb().setToolTips().setData(json_url);
		
		$$('.gray').setStyle('opacity', 0.9);
		
		// #IE FIX
		if (Browser.ie && !Browser.ie9) {
			if (Browser.ie7) {
				$$('.' + this.options.header_wrapper)[0].removeClass('scl');
			};
			$$(this.options.tooltips.selector).each(function(ttip){
				var parent = ttip.getParent();
				ttip.dispose().inject(parent, 'top');
			});
		}
		// #Add IE Class
		if (Browser.ie) {
			$(this.options.showroom_wrapper).addClass('ie' + Browser.version);
		};

		// IE7
		if (Browser.ie7) {
			this.setMask();
		};
		
		// SWFOBJECT DISABLE AUTO HIDE/SHOW
		if ($defined(swfobject)) {
			swfobject.switchOffAutoHideShow();
		}
		else {
			console.error('SWFObject is not included. Please include SWFObject Library.');
		}
		
		addthis.addEventListener('addthis.menu.open', function(evt){
			var triggerPosition = { 
				x: evt.data.element.getPosition().x - $('at15s').getWidth().toInt() + evt.data.element.getWidth().toInt(),
				y: evt.data.element.getPosition().y + evt.data.element.getHeight().toInt()
			};
			$('at15s').setStyles({
				'left': triggerPosition.x + 'px',
				'top': triggerPosition.y + 'px'
			});
			$('at15s').setStyle('visibility', 'visible');
		});
	},
	
	setData: function (json_url) {
		jsonRequest = new Request.JSON({
			url: json_url,
			onSuccess: this.setShowroom.bind(this)
		}).get();
	},
	
	setShowroom: function (data) {
		// #Store Json Data
		this.json = data;

		// #Continue Generating Showroom
		this.setUrlParams().getUrlParams().setNav().setSharebox();

		return this;
	},

	// #URLS
		getUrlParams: function (nohashchange) {
			if($defined(window.location.hash) && !$is_empty(window.location.hash))
			{
				
				// Bind "Hash change" fake-event
				if (!$defined(nohashchange)) {
					this.hashChange();
				}

				// Store first level menu of JSON Showroom DATA
				// FIX FOR FIRST HASH
				var tmp_currentParamData = this.json.showroom.menu[0].menu;



				// Browse all items of the menu to Set Content & re-browse sub-items
				$each(this.params.data, function (param, paramIndex){
					tmp_currentParamData = this.filterParam(param, tmp_currentParamData);
					// #Store Content Type of current param level
					if($defined(tmp_currentParamData))
					{
						if ($defined(tmp_currentParamData.content_type)) {
							var content_type = tmp_currentParamData.content_type;
							this.params.type[paramIndex] = {
								param: param,
								content_type: content_type
							};
							// #If we have a menu, we simply update them to "active" mode
							this.setNav(this.params.type[paramIndex].param);
							// #If not a menu, set the content
							if (content_type != 'menu') {
								this.setContent(content_type, tmp_currentParamData, param);
							}
							else {
								// STATS
								this.doJS(tmp_currentParamData, (this.params.data.length === (paramIndex + 1)));
							}

						}
						if ($defined(tmp_currentParamData.menu)) {
							tmp_currentParamData = tmp_currentParamData.menu;
						}
						else if($defined(tmp_currentParamData.items)) {
							tmp_currentParamData = tmp_currentParamData.items;
						}
					}
					}, this);

			}

			return this;
		},
		
		// #Get Data in Arrat from ID
		filterParam: function (param, data) {
			var new_data = data.filter(function (item, index){
				if (item.id == param) {
					return item;
				}
			});
			return new_data[0];
		},

		// #Store params and associated hash
		setUrlParams: function (data, paramlevel, hash) {
			if ($defined(data)) {
				var tmp_currentParamData = data;
				var currenthash = hash;
			}
			else {
				// COMMENT TO REMOVE FIRST HASH PARAM
				// var tmp_currentParamData = this.json.showroom.menu;
				var tmp_currentParamData = this.json.showroom.menu[0].menu;
				var paramlevel = 0;
				var currenthash = '';
			}
			$each(tmp_currentParamData, function (item, index){
				var newhash = currenthash + '/' + item.id;
				if ($defined(item.id)) {
					this.params.levels[item.id] = paramlevel;
					this.params.hashs[item.id] = newhash.substr(1);
				}
				if ($defined(item.menu)) {
					var newlevel = (paramlevel + 1);
					this.setUrlParams(item.menu, newlevel, newhash);
				}
				if($defined(item.items)) {
					var newlevel = (paramlevel + 1);
					this.setUrlParams(item.items, newlevel, newhash);
				}
			}, this);
			
			return this;
		},

		// #Fake Event binded when we change an hash into the url
		hashChange: function (hash) {
			if ($defined(hash)) {
				hash = hash.toURI().get('fragment').substr(1);
				this.params.data = hash.split('/');
			}
			else if($defined(window.location.hash) && !$is_empty(window.location.hash)) {
				
				// #Store Window HASH
				this.params.data = window.location.hash.substr(2).split('/');
			}
			
			return this;
		},

		// #Set or return an hash from an id
		setHash: function (id, toreturn) {
			index = this.params.levels[id];
			if (!$defined(toreturn)) {
				this.params.data = this.params.data.filter(function (it,id) { return id <= index; });
				this.params.data[index] = id;
				window.location.hash = '!' + this.params.data.join('/');
				
				return this;
			}
			else {
				return '!' + this.params.hashs[id];
			}
		},

		// #Remove the last hash level into the url
		removeLastHash: function () {
			newhash = '#!' + this.params.data.erase(this.params.data.getLast()).join('/');
			this.hashChange(newhash);
			window.location.hash = newhash;
			
			return this;
		},
	
	// #MASK
		setMask: function (mode) {
			if (!$defined(mode) || $is_empty(mode)) {
				$each(this.options.mask, function (maskClass){
					$(this.options.showroom_wrapper).removeClass(maskClass);
				}, this);
				$$(this.options.mask.opacitySelector).setStyle('opacity', '1');
				this.setPrice('show');
				if (Browser.ie7) {
					$(this.options.showroom_wrapper).addClass('iemask');
				};
			}
			else {
				this.setMask().setPrice('hide');
				$(this.options.showroom_wrapper).addClass(this.options.mask[mode]);
				if (mode == 'double') {
					$$(this.options.mask.opacitySelector).setStyle('opacity', '0.3');
				}
				else {
					$$(this.options.mask.opacitySelector).setStyle('opacity', '1');
				}
				if (Browser.ie7) {
					$(this.options.showroom_wrapper).removeClass('iemask');
				};
			}
			

			return this;
		},
	
	// #LOADING
		setLoading: function (mode) {
			if (!$defined(mode)) {
				$(this.options.showroom_wrapper).toggleClass(this.options.loadingClass);
			}
			else if (mode === true) {
				$(this.options.showroom_wrapper).addClass(this.options.loadingClass);
			}
			else if (mode === false) {
				$(this.options.showroom_wrapper).removeClass(this.options.loadingClass);
			}
			
			return this;
		},
	
	// #PRICE
		setPrice: function (mode) {
			if ($defined($(this.options.price))) {
				$(this.options.price).fade(mode);
			}

			return this;
		},
	// #BREADCRUMB
		setBreadcrumb: function () {
			/*
				- Récupération du breadcrumb formaté du site pour ré-injection dans le showroom
				- Breadcrumb d'origine masqué
			*/
			var fromBreadcrumb = $$(this.options.breadcrumb.from_selector);
			var toBreadcrumb = $$(this.options.breadcrumb.to_selector);
			if (fromBreadcrumb.length > 0 && toBreadcrumb.length > 0) {
				fromBreadcrumb = fromBreadcrumb[0];
				toBreadcrumb = toBreadcrumb[0].empty();

				fromBreadcrumb.dispose().inject(toBreadcrumb);
			}

			return this;
		},
	// #NAVIGATION
		// #Intialize main left navigation, or set status of current link on click
		setNav: function (param) {
			/*
				- Au clic
					- Fermeture de toutes les nav adjacentes
					- Ouverture de la nav ciblée
				- Sur les éléments avec class "openonload"
					- Ouverture de la sous-nav pendant 3 secondes, puis fermeture
			*/
			if ($defined(param)) {
				if ($defined($(param))) {
					$(param).getSiblings('.' + this.options.navigation.activeClass).clean().append($(param).getChildren('.' + this.options.navigation.activeClass).clean()).removeClass(this.options.navigation.activeClass).removeClass(this.options.navigation.letOpenClass);
					if (!$is_empty($(param).getParent('li'))) {
						$(param).getParent('li').addClass(this.options.navigation.letOpenClass).addClass(this.options.navigation.activeClass);
					}
					$(param).addClass(this.options.navigation.letOpenClass).addClass(this.options.navigation.activeClass);
				}
			}
			else {
				// Get all links "html-generated" and bind "hash change" fake-event on click
				var ahrefs = $$('#' + this.options.nav + ' a[href^=#!]');
				$each(ahrefs, function (ahref, i){
					ahref.addEvent('click', function (e){
						// Home link (back to showroom's home)
						if (ahref.getParent('li').hasClass(this.options.navigation.homeClass)) {
							e.stop();
							this.goHome(ahref);
						}
						else {
							this.hashChange(ahref.href).getUrlParams(true);
						}
					}.bind(this));
				}, this);

				var navs = $$('#' + this.options.nav + ' ' + this.options.navigation.selector + ':not(.' + this.options.navigation.alreadySetClass + ')');
				if (navs.length > 0) {
					$each(navs, function (nav){
						nav.store('toggler', nav.getParent('li').getChildren(this.options.navigation.toggler));
						// +Set Slide on subnav ul item
						var navSlide = new Fx.Slide(nav, this.options.navigation.slideOpt);
						// +Don't close it
						if (!nav.getParent('li').hasClass(this.options.navigation.letOpenClass)) {
							// +Let it open for x seconds if has the openOnLoad class
							if (nav.getParent('li').hasClass(this.options.navigation.openOnLoadClass)) {
								(function (){ navSlide.slideOut(); }.bind(this)).delay((1000 * this.options.navigation.openOnLoadTime));
							}
							else {
								// +Hide it
								navSlide.hide();
							}
						}
						// +Store it into menu
						nav.store('slide', navSlide);

						//+ Add Events
						nav.retrieve('toggler').addEvent(
							'click', function (e) {
								// +Close all other parent items
								alreadyOpen = navSlide.open;
								if (this.closeNavs($$(e.target.getParent('ul').getElements(this.options.navigation.selector).erase(nav)))) {
									// +Open selected nav if closed
									if (!alreadyOpen) {
										nav.retrieve('toggler').getParent().addClass(this.options.navigation.activeClass);
										navSlide.slideIn();
									}
									else {
										nav.retrieve('toggler').getParent().removeClass(this.options.navigation.activeClass);
										navSlide.slideOut();
										nav.getChildren('.' + this.options.navigation.activeClass).removeClass(this.options.navigation.activeClass);
										this.hideContent().removeLastHash();
										if ($defined(e)) {
											e.stop();
										}
									}
								}
							}.bind(this)
						);
						nav.addClass(this.options.navigation.alreadySetClass);
					}, this);
				}
			}


			return this;
		},
		// #Close all opened navs
		closeNavs: function (collection) {
			$each(collection, function (nav){
				nav.retrieve('toggler').getParent().removeClass(this.options.navigation.activeClass);
				nav.retrieve('slide').slideOut();
			}, this);

			return true;
		},
	
	// #SHAREBOX
		setSharebox: function (parent, url, empty, download_link) {
			/*
				- Show au mouseenter
				- Hide au mouseleave
			*/
			var shareToggler = $(this.options.share.main.toggler);
			var shareBox = $$(this.options.share.main.sharebox);

			if ($defined(this.json.showroom.common.social_networks)) {
				if (!$defined(parent)) {
					shareList = shareToggler.getElement('ul');
				}
				else {
					shareList = parent;
					if ($defined(empty)) {
						var toDestroy = shareList.getFirst().getAllNext();
						if (!$is_empty(toDestroy)) {
							toDestroy.destroy();
						}
					}
				}
				$each(this.json.showroom.common.social_networks, function (socnet, index){
					shareLi = new Element('li', {
						id: socnet.id + $random(1,99).toString() + $random(100,999).toString()
					}).inject(shareList);
					
					shareA = new Element('a', {
						'target': '_blank',
						'href': socnet.share_url,
						'events': {
							'click': function (e) {
								if ($defined(url)) {
									this.href += window.location.href.toURI().set('fragment', url).toString();
								}
								else {
									this.href += window.location.href;
								}
							},
							'mouseover': function (e) {
								this.setStyle('opacity','0.8');
							},
							'mouseout': function (e) {
								this.setStyle('opacity','1');
							}
						}
					}).inject(shareLi);
					
					shareImg = new Element('img', {
						src: socnet.icon,
						alt: socnet.title,
						width: 16,
						height: 16
					}).inject(shareA);
				});
				
				// ADDTHIS
				addthisLi = new Element('li', {
					id: 'pgt_sh_addthis-' + $random(1,99).toString() + $random(100,999).toString()
				}).inject(shareList);
				addthisA = new Element('a', {
					'id': 'addthislink-' + $random(1,99).toString() + $random(100,999).toString(),
					'class': this.options.share.plus_class
				}).inject(addthisLi);
				addthis.button(addthisA, {
					ui_hover_direction: -1,
					ui_offset_left: -230,
					ui_offset_top: -10,
					ui_click: true
				});
				addthisA.empty();
				addthisSpan = new Element('span').inject(addthisA);
				
				// DOWNLOAD LINK
				if ($defined(download_link)) {
					downloadLi = new Element('li', {
						'id': 'download-' + $random(1,99).toString() + $random(100,999).toString(),
						'class': this.options.share.download_class
					}).inject(shareList);
					downloadA = new Element('a', {
						'href': download_link,
						'target': '_blank'
					}).inject(downloadLi);
				}
				
				// if PARENT not defined
				if (!$defined(parent)) {
					if (shareBox.length > 0 && shareToggler != undefined) {
						shareBox = shareBox[0];
						shareToggler.addClass('hover');
						if (Browser.ie7) {
							shareBox.getFirst().setStyle('width', shareBox.getWidth());

							shareToggler.addEvents({
								'mouseenter': function() { this.addClass('hover'); },
								'mouseleave': function() { this.removeClass('hover'); }
							});
						};
						shareBox.setStyle('margin-left', -( (shareBox.getWidth().toInt() / 2) - ( shareToggler.getWidth().toInt() / 2 ) ) + 'px');
						shareToggler.removeClass('hover');
					}
				}
			}
			else {
				shareToggler.hide();
			}
			
			return this;
		},
		
	// #SET ADDTHIS FOR ONE ELEMENT
		addthis: function(parentEl) {
			if ($defined(parentEl)) {
				var item = parentEl.getElement('.' + this.options.share.plus_class);
				button(item, {
					ui_hover_direction: -1,
					ui_offset_left: -230,
					ui_offset_top: -10,
					ui_click: true,
					ui_508_compliant: true
				});
				item.empty();
				addthisSpan = new Element('span').inject(item);
				
				$('at15s').setStyle('visibility', 'hidden');
			}
			
			return this;
		},
	
	// #TOOLTIPS
		setToolTips: function () {
			var tooltips = $$(this.options.tooltips.selector);
			if (tooltips.length > 0) {
				$each(tooltips, function(tooltip){
					tooltip.store('tip:title', '').store('tip:text', tooltip.get('html'));
				}, this);
				mooTooltips = new Tips(this.options.tooltips.selector, this.options.tooltips.tipsOpt);
			}
			/*
				- Ouverture des tips au mouseover sur icon
				- Fermeture au mouseleave
			*/

			return this;
		},

	// #DOJS
	doJS: function(data, conditional) {
		if ($defined(data.js) && !$is_empty(data.js) && conditional) {
			try {
				eval(data.js);
			} catch(e) {
				// console.log(e);
			}
		};

		return this;
	},

	// #INTRO
		checkIntro: function() {
			var introEl = $$('.' + this.options.intro.classname);
			if (introEl.length > 0) {
				this.introElement = introEl[0];

				if (!swfobject.hasFlashPlayerVersion(this.options.swfobject.flashversion) || $is_empty(this.introElement.get('html').trim())) {
					this.introElement.fade('hide');
				};
			};			

			return this;
		},

		skipIntro: function() {
			if ($defined(this.introElement)) {
				new Fx.Tween(this.introElement, {
					duration: 'long',
					link: 'cancel',
					property: 'opacity',
					onComplete: function() {
						this.introElement.destroy();
						this.introElement = null;
					}.bind(this)
				}).start(1,0);
			};

			return this;
		},
		
	// #CONTENT
		setContent: function (type, data, param) {
			// console.log(type, data, param);
			
			// STATS
			this.doJS(data, (param === this.params.data.getLast()));

			switch (type) {
				case "hotspots_area":
					this.hotspots_setArea(data);
				break;
				case "hotspots_category":
					this.hotspots_setCategory(data);
				break;
				case "hotspot":
					this.hotspots_goTo(data);
				break;
				case "photos":
					this.photos_setGallery(data);
				break;
				case "photo":
					Asset.images([data.thumb, data.sd], {
						onComplete: function() {
							this.photos_goTo(data);
						}.bind(this)
					});
				break;
				case "photozoom":
					this.photos_zoomOn(data);
				break; 
				case "videos":
					this.videos_setPlayer(data.content);
				break;
				case "360":
					this.tcs_setContent(data.content);
				break;
				default:
					return this;
				break;
			}
			
			return this;
		},
		hideContent: function () {
			this.setMask();
			$$('.' + this.options.right_content).fade('out');
			this.destroyPreviousContent();
			return this;
		},
		destroyPreviousContent: function() {
			// VIDEO GALLERY
			if ($defined(this.videos) && $defined(this.videos.wrapper)) {
				this.videos.wrapper.empty();
			};

			// HOTSPOTS
			if ($defined(this.hotspots) && $defined(this.hotspots.zoom)) {
				var hotspots_zoom_elements = $$(this.hotspots.zoom.toolbar, this.hotspots.zoom.desc_wrapper);
					hotspots_zoom_elements.dispose();
					this.hotspots.zoom.wrapper.empty();
					hotspots_zoom_elements.inject(this.hotspots.zoom.wrapper);
			};

			return this;	
		},
		// #HOME
		goHome: function(ahref) {
			window.location.hash = '#!';
			this.hashChange().getUrlParams().hideContent();
			
			$$('li.' + this.options.navigation.activeClass + ':not(.' + this.options.navigation.homeClass + ')').each(function(item){
				item.removeClass(this.options.navigation.activeClass);
				var uls = item.getElement('ul');
				if (!$is_empty(uls)) {
					var slide = uls.retrieve('slide');
					if (!$is_empty(slide)) {
						slide.slideOut();
					}
				}
			}.bind(this));
			
			ahref.getParent('li').addClass(this.options.navigation.activeClass);
		},
		// #PHOTOS
		photos_setGallery: function (data) {
			this.hideContent().setMask('simple');
			// Set Area (create if not set, else visible)
				if (!$defined(this.photos)) {
					this.photos = {};
				}
				if (!$defined(this.photos.wrapper)) {
					// #WRAPPER
					this.photos.wrapper = new Element('div', {
						id: this.options.photos.wrapper.id,
						'class': this.options.right_content
					}).inject(this.options.content_wrapper).fade('hide');
					this.photos.wrapper_c = new Element('div', {
						id: this.options.photos.wrapper.points + '-panwrapper'
					}).inject(this.photos.wrapper);
					// #BIG LEFT CONTROL
					this.photos.big_left_control = new Element('a', {
						'class': this.options.photos.controls.left,
						'html': '<span></span>',
						id: 'big-' + this.options.photos.controls.left
					}).inject(this.photos.wrapper);
					// #PHOTOS LIST
					this.photos.big_list_wrapper = new Element('ul', {
						'class': this.options.photos.wrapper.points,
						'id': this.options.photos.wrapper.points + '-pancontainer'
					}).inject(this.photos.wrapper_c);
					// #BIG RIGHT CONTROL (cloned from LEFT)
					this.photos.big_right_control = this.photos.big_left_control.clone().set({
						'class': this.options.photos.controls.right,
						id: 'big-' + this.options.photos.controls.right
					}).inject(this.photos.wrapper);
					// #NAV WRAPPER
					var tmp_nav_wrapwrapper_n = new Element('div', {
						'class': this.options.photos.nav.wrapwrapper
					}).inject(this.photos.wrapper);
					var tmp_nav_wrapper = new Element('div', {
						'class': this.options.photos.nav.classname
					}).inject(tmp_nav_wrapwrapper_n);
					// #NAV SLIDER
					this.photos.nav_slider = new Fx.Slide(tmp_nav_wrapper, { 'wrapper': tmp_nav_wrapwrapper_n });
					var tmp_toggler_size = this.options.photos.nav.toggler_size;
					// tmp_nav_wrapper.store('slider', this.photos.nav_slider).addEvent('mouseleave', function(e){
					// 	this.retrieve('slider').slideOut();
					// 	this.open = false;
					// });
					$(document.body).store('gallery', this.photos.wrapper).store('gallery_thumbnavslider', this.photos.nav_slider).store('gallery_navwrapper', tmp_nav_wrapper).addEvent('mousemove', function(e){
						var cursPosY = (e.page.y - this.offsetTop);
						var cursPosX = (e.page.x - this.offsetLeft);
						var limitGalleryTOP = this.retrieve('gallery').getCoordinates().bottom - this.retrieve('gallery_navwrapper').getHeight().toInt();
						var limitGalleryBOTTOM = this.retrieve('gallery').getCoordinates().bottom;
						var limitGalleryLEFT = this.retrieve('gallery').getCoordinates().left - this.offsetLeft;
						var limitGalleryRIGHT = this.retrieve('gallery').getCoordinates().right - this.offsetLeft;
						if ( (cursPosY > (limitGalleryTOP - tmp_toggler_size) && cursPosY < limitGalleryBOTTOM && cursPosX > limitGalleryLEFT && cursPosX < limitGalleryRIGHT) && !this.retrieve('gallery_thumbnavslider').open ) {
							this.retrieve('gallery_thumbnavslider').slideIn();
							this.retrieve('gallery_navwrapper').fireEvent('mouseenter');
						}
						else if ((cursPosY < limitGalleryTOP || cursPosY > limitGalleryBOTTOM || cursPosX < limitGalleryLEFT || cursPosX > limitGalleryRIGHT) && this.retrieve('gallery_thumbnavslider').open) {
							this.retrieve('gallery_thumbnavslider').slideOut();
						}
					});
					// #SMALL LEFT CONTROL
					this.photos.small_left_control = new Element('a', {
						'class': this.options.photos.controls.left,
						id: 'small-' + this.options.photos.controls.left
					}).inject(tmp_nav_wrapper);
					// #SMALL PHOTOS LIST
					var tmp_nav_wrapper_n = new Element('div', {
						id: this.options.photos.nav.wrapper + '-panwrapper',
						'class': this.options.photos.nav.wrapper
					}).inject(tmp_nav_wrapper);
					// THUMB SLIDE
					/*
					var tmp_nav_wrapwrapper_n_slide = new Fx.Slide(tmp_nav_wrapper_n, { 'wrapper': tmp_nav_wrapwrapper_n });
					this.photos.wrapper.store('thumbslide', tmp_nav_wrapwrapper_n_slide);
					this.photos.wrapper.addEvent('mousemove', function(e){
						if (e.client.y > this.getHeight()) {
							this.retrieve('thumbslide').slideOut();
						}
					});
					*/
					// UL WRAPPER
					this.photos.small_list_wrapper = new Element('ul', {
						id: this.options.photos.nav.classname + '-pancontainer'
					}).inject(tmp_nav_wrapper_n);
					// #SMALL RIGHT CONTROL (cloned from left)
					this.photos.small_right_control = this.photos.big_right_control.clone().set({
						id: 'small-' + this.options.photos.controls.right
					}).inject(tmp_nav_wrapper);
					// #INITIALIZE TRUE
					var initialize = true;
				}
				else {
					this.photos.small_list_wrapper.empty();
					this.photos.big_list_wrapper.empty();
				}
				if (!$defined(this.photos.zoom)) {
					this.photos.zoom = {};
					// #POPIN <div>
					this.photos.zoom.open = false;
					this.photos.zoom.popin = new Element('div', {
						'class': this.options.photos.zoom.popin
					}).inject(this.options.content_wrapper).hide().fade('hide');
						// #left control <a>
						this.photos.zoom.left_control = new Element('a', {
							'class': this.options.photos.controls.left,
							'html': '<span></span>',
							id: 'zoom-' + this.options.photos.controls.left
						}).inject(this.photos.zoom.popin);
						// #wrapper <div>
						this.photos.zoom.wrapper = new Element('div', {
							'id': this.options.photos.zoom.wrapper + '-panwrapper',
							'class': this.options.photos.zoom.wrapper
						}).inject(this.photos.zoom.popin);
							//#close control
							var tmp_toolbar_z = new Element('div', {
								'class': this.options.photos.toolbar.classname + ' scl'
							}).inject(this.photos.zoom.wrapper);
							var tmp_toolbar_z_control = new Element('ul', {
								'class': 'scl'
							}).inject(tmp_toolbar_z);
							var tmp_zoom_close_a = new Element('a', {
								// href: '#' + this.setHash(photo.items[0].id, true),
								html: '<span>' + this.options.labels.photos_zoom_close + '</span>',
								events: {
									click: function (e){
										if (this.photos.zoom.open) {
											this.photos_closeZoomOn();
										};
									}.bind(this)
								}
							}).inject(tmp_toolbar_z_control);
							//#list <ul>
							this.photos.zoom.list = new Element('ul', {
								'id': this.options.photos.zoom.list + '-pancontainer',
								'class': this.options.photos.zoom.list
							}).inject(this.photos.zoom.wrapper);
						// #right control <a>
						this.photos.zoom.right_control = new Element('a', {
							'class': this.options.photos.controls.right,
							'html': '<span></span>',
							id: 'zoom-' + this.options.photos.controls.right
						}).inject(this.photos.zoom.popin);

						$(this.options.showroom_wrapper).getElements('.header, .mask').addEvent('click', function (){
							if (this.photos.zoom.open) {
								this.photos_closeZoomOn();
							}
						}.bind(this));
						
					if ($defined(swfobject)) {
						
					}
				}
				else {
					this.photos.zoom.list.empty();
					this.photos.nav_slider.show();
				}
				(function() { this.photos.nav_slider.slideOut(); }).delay(this.options.photos.nav.init_show_delay, this);
				
				var thumb_images = [];
				var sd_images = [];
				
				// #SET DATA CONTENT
				$each(data.items, function (photo, i){
					if ($defined(photo.thumb) && $defined(photo.sd) && $defined(photo.items)) {
						// #THUMB
							// <li>
							var tmp_li = new Element('li', {
								id: this.options.photos.nav.thumb_prefix + photo.id,
								'class': ((i==0) ? this.options.photos.activeClass : '')
							}).inject(this.photos.small_list_wrapper).store('json_id', photo.id);
							// <a href="#!photo">
							var tmp_a = new Element('a', {
								href: '#' + this.setHash(photo.id, true),
								events: {
									click: function (e){
										tmp_a.getParent().addClass(this.options.photos.activeClass).getSiblings('.' + this.options.photos.activeClass).removeClass(this.options.photos.activeClass);
										this.hashChange(tmp_a.href);
										this.photos.big_panslider.toPan(tmp_a.retrieve('related'));
									}.bind(this)
								}
							}).inject(tmp_li);
							// <img />
							var tmp_img = new Element('img', {
								src: photo.thumb,
								alt: (($defined(photo.title)) ? photo.title : '')
							}).inject(tmp_a);
							
							// Store thumb
							thumb_images.push(photo.thumb);
						
						// #SD
							// <li>
							var tmp_li_b = new Element('li', {
								id: this.options.photos.nav.sd_prefix + photo.id
							}).inject(this.photos.big_list_wrapper).store('json_id', photo.id);
							// div.toolbar
							var tmp_toolbar_b = new Element('div', {
								'class': this.options.photos.toolbar.classname + ' scl'
							}).inject(tmp_li_b);
								// ul.left.scl
								var tmp_share_ul = new Element('ul').inject(tmp_toolbar_b);
								// inject Zoom link if there is "HD" Photo available
								if ($defined(photo.items[0].hd)) {
									var tmp_zoom_ul = tmp_share_ul.clone().set('class', this.options.photos.toolbar.left + ' scl').inject(tmp_toolbar_b);
									var tmp_zoom_a = new Element('a', {
										'class': this.options.photos.toolbar.zoom,
										href: '#' + this.setHash(photo.items[0].id, true),
										html: '<span>' + this.options.labels.photo_zoom_link + '</span>',
										events: {
											click: function (e){
												this.hashChange(tmp_zoom_a.href).setContent(photo.items[0].content_type, photo.items[0], photo.items[0].id);
											}.bind(this)
										}
									}).inject(tmp_zoom_ul);
									tmp_li.addClass('isZoomable');
								}
								var tmp_li_share = new Element('li', {
									html: '<span>' + this.options.labels.photos_zoom_shareon + '</span>'
								}).inject(tmp_share_ul);
								
								// DEFINE DOWNLOAD LINK (HD if exists, SD otherwise)
								if ($defined(photo.items[0].downloadlink)) {
									tmp_download_link = photo.items[0].downloadlink;
								}
								else if ($defined(photo.items[0].hd)) {
									tmp_download_link = photo.items[0].hd;
								}
								else {
									tmp_download_link = photo.sd;
								}
								
								// DEFINE SHAREBOX
								this.setSharebox(tmp_share_ul, this.setHash(photo.id, true), null, tmp_download_link);

							// <a href="#!photo/zoom">
							var tmp_a_b = new Element('a').inject(tmp_li_b);
							// <img />
							var tmp_img_b = new Element('img', {
								src: photo.sd,
								alt: (($defined(photo.title)) ? photo.title : '')
							}).inject(tmp_a_b);
							
							// Store sd
							sd_images.push(photo.sd);
						
						tmp_a.store('related', tmp_li_b);
						// big_a.store('related', small_a);
						
						// #HD - ZOOM VIEW
						if ($defined(swfobject) && $defined(photo.items[0].hd)) {
							var tmp_li_hd = new Element('li', {
								id: this.options.swfobject.prefixid + '-pan-' + photo.items[0].id
							}).inject(this.photos.zoom.list).store('relsd', tmp_li_b);
							var tmp_div_hd = new Element('div', {
								id: this.options.swfobject.prefixid + photo.items[0].id,
								styles: {
									width: this.options.swfobject.width + 'px',
									height: this.options.swfobject.height + 'px'
								}
							}).inject(tmp_li_hd);
							var flashvars = Object.merge(this.options.swfobject.flashvars, {
								'photo': photo.items[0].hd
							});
							swfobject.embedSWF(this.options.swfobject.src, (this.options.swfobject.prefixid + photo.items[0].id), this.options.swfobject.width, this.options.swfobject.height, this.options.swfobject.flashversion, false, flashvars, this.options.swfobject.params, this.options.swfobject.attributes);
						}
						
					}
				}, this);
				
				// #PAN SLIDERS
				if ($defined(deliaPanSlider)) {
					this.photos.wrapper.show();
					(function () {
						if ($defined(initialize)) {
							
							// Asset
							Asset.images(thumb_images.combine(sd_images), {
								onComplete: function(){
									// #THUMBS
									this.photos.small_panslider = new deliaPanSlider({
										panWrapper: this.options.photos.nav.wrapper + '-panwrapper',
										panContainer: this.options.photos.nav.classname + '-pancontainer',
										pansSelector: '#' + this.options.photos.nav.classname + '-pancontainer > li',
										scrollby: 1,
										controllers:
										{
											left: this.photos.small_left_control,
											right: this.photos.small_right_control,
											disabled: 'smalldisabled'
										}
									});
									
									// #BIG
									this.photos.big_panslider = new deliaPanSlider({
										panWrapper: this.options.photos.wrapper.points + '-panwrapper',
										panContainer: this.options.photos.wrapper.points + '-pancontainer',
										pansSelector: '#' + this.options.photos.wrapper.points + '-pancontainer > li',
										scrollby: 1,
										controllers:
										{
											left: this.photos.big_left_control,
											right: this.photos.big_right_control,
											disabled: 'bigdisabled'
										},
										onChange: function (pos) {
											var target = $$('#' + this.options.photos.nav.classname + '-pancontainer > li')[pos].addClass(this.options.photos.activeClass);
											this.photos.small_panslider.toPan(target);
											var newhash = '#' + target.getElement('a').href.toURI().get('fragment');
											this.hashChange(newhash);
											window.location.hash = newhash;
											target.getSiblings('.' + this.options.photos.activeClass).removeClass(this.options.photos.activeClass);
										}.bind(this)
									});
									
									// #HD
									this.photos.zoom.popin.show();
									this.photos.hd_panslider = new deliaPanSlider({
										panWrapper: this.options.photos.zoom.wrapper + '-panwrapper',
										panContainer: this.options.photos.zoom.list + '-pancontainer',
										pansSelector: '#' + this.options.photos.zoom.list + '-pancontainer > li',
										scrollby: 1,
										controllers:
										{
											left: this.photos.zoom.left_control,
											right: this.photos.zoom.right_control,
											disabled: 'hddisabled'
										},
										onChange: function (pos) {
											var target = $$('#' + this.options.photos.nav.classname + '-pancontainer > li.isZoomable a')[pos];
											target.fireEvent('click');
										}.bind(this)
									});
									this.photos.zoom.popin.hide();
								}.bind(this)
							});
							
							// Asset
							// Asset.images(sd_images, {
							// 	onComplete: function(){
							// 	}.bind(this)
							// });
						}
						else {
							this.photos.small_panslider.reset();
							this.photos.big_panslider.reset();
							this.photos.hd_panslider.reset();
						}
					}).delay(500, this);
					this.photos.wrapper.hide();
				}
				else {
					console.error('## Delia Pan Slider is not loaded or defined. ##');
				}
			// Set Thumbs List
				// Set Data
					// Use .store(id, value)
				// Set Onclicks
					// -> this.photos_goTo(photo_id)
			// Set SD List
				// Set Zoom data
					// Use .store(id, value)
				// Set Onclick
					// -> this.photos_zoomOn(data);
			
			this.photos.wrapper.show().fade('in');
			
			return this;
		},
		photos_goTo: function (data) {
			// Go to "photo_id"
			var thumb = $(this.options.photos.nav.thumb_prefix + data.id);
			var sd = $(this.options.photos.nav.sd_prefix + data.id);
			(function (){
				// this.photos.small_panslider.toPan(thumb);
				this.photos.big_panslider.toPan(sd);
			}).delay(1200, this);
			
			return this;
		},
		photos_zoomOn: function (data) {
			this.setLoading(true);
			(function() {
				this.setMask('double');
				this.photos.zoom.open = true;
				this.photos.zoom.popin.show();
				targetPan = $(this.options.swfobject.prefixid + '-pan-' + data.id);
				pos = this.photos.zoom.list.getElements('li').indexOf(targetPan);
				if (pos != 0) {
					this.photos.hd_panslider.setStart(targetPan);
				}
				else {
					this.photos.hd_panslider.toPan(targetPan);
				}
				this.photos.zoom.popin.fade('in');
				this.setLoading(false);
			}.bind(this)).delay(1000);
			return this;
		},
		photos_closeZoomOn: function () {
			this.photos.zoom.popin.fade('out').hide();
			// this.photos.zoom.popin.hide();
			this.removeLastHash();
			this.photos.zoom.open = false;
			this.setMask('simple');
		},
		// #VIDEOS
		videos_setPlayer: function (data) {
			this.hideContent().setMask('simple');
			
			if (!$defined(this.videos)) {
				this.videos = {};
				// #WRAPPER
				this.videos.wrapper = new Element('div', {
					id: this.options.videos.wrapper.id,
					'class': this.options.right_content
				}).inject(this.options.content_wrapper).fade('hide');
			}

			// #PLAYER REPLACEMENT
			this.videos.player = new Element('div', {
				id: this.options.videos.player_id
			}).inject(this.videos.wrapper);			
			
			// Set Flashvar with XML URL (and XML PARAM) if defined
			if ($defined(data.xmlurl)) {
				var xmlparam = 'xml';
				if ($defined(data.xmlparam)) {
					xmlparam = data.xmlparam;
				}
				var tmp_flashvars = {};
					tmp_flashvars[xmlparam] = data.xmlurl;
				var tmp_flashvars = Object.merge(this.options.swfobject.flashvars, this.options.videos.flashvars, tmp_flashvars);
			}
			else {
				var tmp_flashvars = Object.merge(this.options.swfobject.flashvars, this.options.videos.flashvars);
			}
			
			var attributes = Object.merge(this.options.swfobject.attributes, {'id': this.options.videos.player_id});
			
			// Inject flash
			swfobject.embedSWF(this.options.videos.player_src, this.options.videos.player_id, this.options.videos.player_width, this.options.videos.player_height, this.options.swfobject.flashversion, false, tmp_flashvars, this.options.swfobject.params, attributes);
			
			this.videos.wrapper.fade('in');
		},
		videos_goTo: function (video_id) {
			// Call Javascript to video
		},
		// #HOTSPOTS
		hotspots_setArea: function (data) {

			this.hideContent().setMask('simple');

			// Set HTML Structure
			if (!$defined(this.hotspots)) {
				this.hotspots = {};
			}
			if (!$defined(this.hotspots.wrapper)) {
				this.hotspots.wrapper = new Element('div', {
					id: this.options.hotspots.wrapper.id,
					'class': this.options.right_content
				}).inject(this.options.content_wrapper).fade('hide');
				this.hotspots.points_wrapper = new Element('div', {
					id: this.options.hotspots.wrapper.points
				}).inject(this.hotspots.wrapper);
				this.hotspots.list_container = new Element('ul').inject(this.hotspots.points_wrapper);
			}

			// Set Background
			this.hotspots_fx_setBg(data.menu[0].background, data.menu[0].label);
			
			// Set Menu
			this.hotspots_fx_setNav(data.menu);

			// Set Description
			if ($defined(data.menu[0].description) && $defined(data.menu[0].description.content) && !$is_empty(data.menu[0].description.content.trim())) {
				this.hotspots_fx_setDesc(data.menu[0].description.label, data.menu[0].description.content);
			}
			else {
				this.hotspots.desc_wrapper.hide();
			}

			// Set Hotspots
			if ($defined(data.menu[0].items)) {
				this.hotspots_fx_setHotspots(data.menu[0].items);
			}
			
			this.hotspots.wrapper.fade('in');
			
			return this;
		},
		hotspots_goTo: function (data) {
			// console.log(data);
			this.setMask('double');
			if (!$defined(this.hotspots.zoom)) {
				this.hotspots.zoom = {};
				// #WRAPPER
				this.hotspots.zoom.wrapper = new Element('div', {
					id: this.options.hotspots.zoom.wrapper,
					'class': this.options.right_content
				}).inject(this.options.content_wrapper).fade('hide');
				// #BACKGROUND
				// this.hotspots.zoom.background = new Element('img', {
				// 					id: this.options.hotspots.zoom.background
				// 				}).inject(this.hotspots.zoom.wrapper);
				// #TOOLBAR
				this.hotspots.zoom.toolbar = new Element('div', {
					'class': this.options.hotspots.zoom.toolbar + ' scl'
				}).inject(this.hotspots.zoom.wrapper);
				// #SHARE
				/*
				tmp_ul_share = new Element('ul',{
					'class': 'scl'
				}).inject(this.hotspots.zoom.toolbar);
				*/
				tmp_ul_close = new Element('ul',{
					'class': this.options.hotspots.zoom.close_toolbar_class + ' scl'
				}).inject(this.hotspots.zoom.toolbar);
				tmp_li_close = new Element('li').inject(tmp_ul_close);
				// Close Hotspot Zoom View
				tmp_a_close = new Element('a', {
					'html': this.options.labels.hotspots_zoom_close,
					'events': {
						'click': function (e){
							if ($defined(e)) {
								e.stop();
							}
							
							this.hotspots.zoom.wrapper.fade('out');
							this.removeLastHash();
							this.setMask('simple');
							this.destroyPreviousContent();
						}.bind(this)
					}
				}).inject(tmp_li_close);
				/*
				tmp_li_share = new Element('li', {
					html: '<span>' + this.options.labels.hotspots_zoom_shareon + '</span>'
				}).inject(tmp_ul_share);
				*/
				
				
				// #DESCRIPTION
				this.hotspots.zoom.desc_wrapper = new Element('div', {
					'class': this.options.hotspots.desc.main,
					html: '<div class="' + this.options.hotspots.desc.wrapper + ' description_content"></div>'
				}).inject(this.hotspots.zoom.wrapper);
				this.hotspots.zoom.desc_toggler = new Element('a', {
					'href': '#',
					'class': this.options.hotspots.desc.toggler + ' sc',
					'events': {
						'click': function(e) {
							if ($defined(e)) {
								e.stop();
							}
							this.fireEvent('mouseenter');
						},
						'mouseenter': function (e){
							if ($defined(e)) {
								e.stop();
							}
							var slide = this.retrieve('desc').retrieve('slide');
							if (slide.open == false) {
								slide.slideIn();
							}
						}
					}
				}).inject(this.hotspots.zoom.desc_wrapper, 'top');
				this.hotspots.zoom.desc_label = this.hotspots.zoom.desc_wrapper.getElement('.' + this.options.hotspots.desc.toggler);
				this.hotspots.zoom.desc_content = this.hotspots.zoom.desc_wrapper.getElement('.' + this.options.hotspots.desc.wrapper);
				var slide = new Fx.Slide(this.hotspots.zoom.desc_content, {
					onStart: function (e) {
						if (this.open == false) {
							this.wrapper.getParent().addClass('open');
						}
					},
					onComplete: function (e) {
						if (this.open == true) {
							this.wrapper.getParent().removeClass('open');
						}
					}
				}).hide();
				this.hotspots.zoom.desc_content.store('slide', slide);
				this.hotspots.zoom.desc_label.store('desc', this.hotspots.zoom.desc_content).addEvent('click', function (e){
					if ($defined(e)) {
						e.stop();
					}
					var slide = this.retrieve('desc').retrieve('slide');
					slide.toggle();
				});
				this.hotspots.zoom.desc_wrapper.addEvents({
					'mouseleave': function (e){
						if ($defined(e)) {
							e.stop();
						}
						var slide = this.getFirst().retrieve('desc').retrieve('slide');
						if (slide.open == true) {
							slide.slideOut();
						}
					}
				});
			}
			
			// Set Share
			// this.setSharebox(tmp_ul_share.show(), this.setHash(data.id, true), true);
			
			/* DESTROY ALL PREVIOUS CONTENT */
			// this.destroyPreviousContent();
			
			
			/* PHOTO */
			if ($defined(data.background) && !$is_empty(data.background)) {
				// Set Background
				this.hotspots.zoom.background = new Element('img', {
					id: this.options.hotspots.zoom.background,
					src: data.background,
					alt: data.label
				}).inject(this.hotspots.zoom.wrapper);
			}
			/* FLASH / SWF */
			else if ($defined(data.swf) && !$is_empty(data.swf)) {
				// Create empty div to be replaced with SWF OBject
				this.hotspots.zoom.swf = new Element('div', {
					id: this.options.hotspots.zoom.swf
				}).inject(this.hotspots.zoom.wrapper);
				
				// Set Flashvar with XML URL (and XML PARAM) if defined
				if ($defined(data.xmlurl)) {
					var xmlparam = 'xml';
					if ($defined(data.xmlparam)) {
						xmlparam = data.xmlparam;
					}
					var tmp_flashvar = {};
						tmp_flashvar[xmlparam] = data.xmlurl;
					var flashvars = Object.merge(this.options.swfobject.flashvars, tmp_flashvar);
				}
				else {
					var flashvars = this.options.swfobject.flashvars;
				}
				
				// Inject flash
				swfobject.embedSWF(data.swf, this.options.hotspots.zoom.swf, this.options.hotspots.zoom.width, this.options.hotspots.zoom.height, this.options.swfobject.flashversion, false, flashvars, this.options.swfobject.params, this.options.swfobject.attributes);
			}
			/* VIDEO */
			else if ($defined(data.video) && !$is_empty(data.video)) {
				// tmp_ul_share.hide();
				// Create empty div to be replaced with SWF OBject
				this.hotspots.zoom.video = new Element('div', {
					id: this.options.hotspots.zoom.video
				}).inject(this.hotspots.zoom.wrapper);
				
				// Set Flashvar with XML URL (and XML PARAM) if defined
				if ($defined(data.xmlurl)) {
					var xmlparam = 'xml';
					if ($defined(data.xmlparam)) {
						xmlparam = data.xmlparam;
					}
					var tmp_flashvar = {};
						tmp_flashvar[xmlparam] = data.xmlurl;
					var flashvars = Object.merge(this.options.swfobject.flashvars, this.options.videos.flashvars, tmp_flashvar);
				}
				else {
					var flashvars = Object.merge(this.options.swfobject.flashvars, this.options.videos.flashvars);
				}
				
				// Inject flash
				swfobject.embedSWF(this.options.videos.player_src, this.options.hotspots.zoom.video, this.options.hotspots.zoom.width, this.options.hotspots.zoom.height, this.options.swfobject.flashversion, false, flashvars, this.options.swfobject.params, this.options.swfobject.attributes);
			}
			/* TABLE */
			else if($defined(data.table_xls) && !$is_empty(data.table_xls)) {
				this.hotspots.zoom.table_xls = new Element('div', {
					id: this.options.hotspots.zoom.table_xls,
					html: data.table_xls
				}).inject(this.hotspots.zoom.wrapper);

				$each(this.hotspots.zoom.table_xls.getElements('tr'), function(line) {
					var nb_vide = 0;
					var cells = line.getElements('td');
					$each(cells, function(cell){
						if ($is_empty(cell.get('html').trim())) {
							nb_vide += 1;
						};
					});
					if (nb_vide == cells.length) {
						line.destroy();
					};
				});
			}
			
			// Set Description
			if ($defined(data.description) && $defined(data.description.content) && !$is_empty(data.description.content.trim())) {
				this.hotspots.zoom.desc_label.set('html', '<span class="sh_tg_title">' + data.description.label + '</span>');
				this.hotspots.zoom.desc_content.set('html', data.description.content).retrieve('slide').show();
				this.hotspots.zoom.desc_wrapper.addClass('open').show();
				(function (){ this.hotspots.zoom.desc_content.retrieve('slide').slideOut(); }).delay(this.options.hotspots.desc.delay, this);
			}
			else {
				this.hotspots.zoom.desc_wrapper.hide();
			}
			
			this.hotspots.zoom.wrapper.show().fade('in');
			return this;
		},
		hotspots_setCategory: function (data) {
			this.hotspots.wrapper.fade('hide');
			this.setMask('simple');

			// Set Background
			this.hotspots_fx_setBg(data.background, data.label);

			// Set Description
			if ($defined(data.description) && $defined(data.description.content) && !$is_empty(data.description.content.trim())) {
				this.hotspots_fx_setDesc(data.description.label, data.description.content);
			}
			else {
				this.hotspots.desc_wrapper.hide();
			}

			// Set Nav
			this.hotspots.nav.getElements('.' + this.options.navigation.activeClass).clean().removeClass(this.options.navigation.activeClass);
			$(data.id).addClass(this.options.navigation.activeClass);
			if (!$is_empty($(data.id).getParent('li'))) {
				$(data.id).getParent('li').addClass(this.options.navigation.activeClass);
			}

			// Set Hotspots
			if ($defined(data.items)) {
				this.hotspots_fx_setHotspots(data.items);
			}

			// Auto-hide navigation when changing category (setting description)
			this.hotspots.nav.addClass('hide');
			(function() { this.hotspots.nav.removeClass('hide'); }).delay(1000, this);			

			// Show the hotspot wrapper
			this.hotspots.wrapper.fade('in');

			return this;
		},
			hotspots_fx_setBg: function (imgsrc, alt) {
				if (!$defined(this.hotspots.background_image)) {
					this.hotspots.background_image = new Element('img').inject(this.hotspots.wrapper);
				}
				if ($is_empty(imgsrc)) {
					var imgsrc = '';
					this.hotspots.background_image.hide();
				}
				else {
					this.hotspots.background_image.show();
				}
				
				this.hotspots.background_image.set({
					src: imgsrc,
					alt: alt
				});
				
				return this;
			},
			hotspots_fx_setNav: function (data, hsparent) {
				// #Create Nav Wrapper if not exists
				if (!$defined(this.hotspots.nav)) {
					this.hotspots.nav = new Element('div', {
						'class': 'sh_h_nav',
						'styles': {
							'opacity': '0.85'
						}
					}).inject(this.hotspots.wrapper);
				}
				// #Set Main as parent if not exists
				if (!$defined(hsparent)) {
					var hsparent = this.hotspots.nav;

					// Empty Nav Wrapper
					hsparent.empty();
					
					// To add class on first item
					var isFirst = true;
					var isMain = true;
				}
				else {
					var isFirst = false;
					var isMain = false;
				}
				
				// Create new UL wrapper
				var tmp_ul = new Element('ul').inject(hsparent);
				if (!isMain) {
					var tmp_ul_slide = new Fx.Slide(tmp_ul);
					hsparent.store('slide', tmp_ul_slide);
					if (!hsparent.hasClass(this.options.navigation.letOpenClass)) {
						tmp_ul_slide.hide();
					}
				}
				
				// Browse each "menu" element of the current category to generate menu (recursive)
				$each(data, function (item, index){
					var tmp_li = new Element('li', {
						id: item.id,
						'class': (($defined(item.menu)) ? 'subnav' : '') + ((isFirst) ? ' ' + this.options.navigation.activeClass + ' ' + this.options.navigation.letOpenClass : '')
					}).inject(tmp_ul);
						isFirst = false;
						var tmp_a = new Element('a', {
							href: '#' + this.setHash(item.id, true),
							html: '<span>' + item.label + '</span>',
							events: {
								click: function (e){
									this.hashChange(tmp_a.href);

									// EVAL JAVASCRIPT FUNCTION IF DEFINED IN JSON (i.e: statistics, log functions, etc.)
									this.doJS(item, true);

									if (e.target.getParent('li').retrieve('slide') != null) {
										$each(this.hotspots.nav.getElements('li'), function(item) {
											if (item.retrieve('slide') != null) {
												if (item != e.target.getParent('li')) {
													item.retrieve('slide').slideOut();	
												}
												else {
													item.retrieve('slide').toggle();
												}
											}
										});
									}
									else if(e.target.getParent('li').getParent('li') == null) {
										$each(this.hotspots.nav.getChildren('ul>li'), function(item) {
											if (item.retrieve('slide') != null) {
												item.retrieve('slide').slideOut();	
											}
										});
									}
								}.bind(this)
							}
						}).inject(tmp_li);

						// #Set icon manually
						if ($defined(item.icon)) {
							if ($defined(item.icon.classname)) {
								tmp_a.set('class', item.icon.classname);
							}
							else if ($defined(item.icon.over) && $defined(item.icon.out)) {
								tmp_a.set({
									styles: {
										'background-image': "url('" + item.icon.out + "')"
									},
									events: {
										'mouseover': function (a){
											a.setStyle('background-image', "url('" + item.icon.over + "')");
										}.bind(this),
										'mouseout': function (a){
											a.setStyle('background-image', "url('" + item.icon.out + "')");
										}.bind(this)
									}
								});
							}
						}
						else {
							tmp_a.set('class','nav-icon-defaut');
						}
						
						// #Set click action to load hotspots
						if ($defined(item.items)) {
							tmp_a.addEvent('click', function (e) {
								this.hashChange(tmp_a.href).hotspots_setCategory(item);
							}.bind(this));
						}
						
						// #Set Subnav if exists
						if ($defined(item.menu)) {
							this.hotspots_fx_setNav(item.menu, tmp_li);
						}
				}, this);
				
				return this;
			},
			hotspots_fx_setDesc: function (label, description) {
				if (!$defined(this.hotspots.desc_label) && !$defined(this.hotspots.desc_content)) {
					this.hotspots.desc_wrapper = new Element('div', {
						'class': this.options.hotspots.desc.main,
						html: '<div class="' + this.options.hotspots.desc.wrapper + ' description_content">' + description + '</div>'
					}).inject(this.hotspots.wrapper);
					this.hotspots.desc_toggler = new Element('a', {
						'class': this.options.hotspots.desc.toggler + ' sc',
						'html': '<span class="sh_tg_title">' + label + '</span>'
					}).inject(this.hotspots.desc_wrapper, 'top');
					this.hotspots.desc_toggler.addEvents({
						'mouseenter': function (e){
							if ($defined(e)) {
								e.stop();
							}
							var slide = this.retrieve('desc').retrieve('slide');
							if (slide.open == false) {
								slide.slideIn();
							}
						}
					});
					this.hotspots.desc_label = this.hotspots.desc_wrapper.getElement('.' + this.options.hotspots.desc.toggler);
					this.hotspots.desc_content = this.hotspots.desc_wrapper.getElement('.' + this.options.hotspots.desc.wrapper);
					var slide = new Fx.Slide(this.hotspots.desc_content, {
						onStart: function (e) {
							if (this.open == false) {
								this.wrapper.getParent().addClass('open');
							}
						},
						onComplete: function (e) {
							if (this.open == true) {
								this.wrapper.getParent().removeClass('open');
							}
						}
					}).hide();
					this.hotspots.desc_content.store('slide', slide);
					this.hotspots.desc_label.store('desc', this.hotspots.desc_content).addEvent('click', function (e){
						if ($defined(e)) {
							e.stop();
						}
						var slide = this.retrieve('desc').retrieve('slide');
						slide.toggle();
					});
					this.hotspots.desc_wrapper.addEvents({
						'mouseleave': function (e){
							if ($defined(e)) {
								e.stop();
							}
							var slide = this.getFirst().retrieve('desc').retrieve('slide');
							if (slide.open == true) {
								slide.slideOut();
							}
						}
					});
				}
				else {
					this.hotspots.desc_label.set('html', '<span class="sh_tg_title">' + label + '</span>');
					this.hotspots.desc_content.set('html', description).retrieve('slide').show();
					this.hotspots.desc_wrapper.addClass('open').show();
					// Auto close
					// (function (){ this.hotspots.desc_content.retrieve('slide').toggle(); }).delay(this.options.hotspots.desc.delay, this);
				}
			},
			hotspots_fx_setHotspots: function (data) {
				// #Empty the hotspots list
				if ($defined(this.hotspots.list_container)) {
					this.hotspots.list_container.empty();
				}

				// #Get Hotspots Area Size
				var hotspotWrapperWidth = this.hotspots.points_wrapper.getWidth().toInt() * (this.options.hotspots.direction.security / 100);

				// #Browse all hotspot data to insert them
				$each(data, function (hotspot, index){
					// #Create "list element"
					hotspotEl = new Element('li', {
						id: hotspot.id,
						styles: {
							left: 0,
							top: 0
						}
					}).inject(this.hotspots.list_container);

					// #Create link element with default style for calculating size
					tmp_a = new Element('a',{
						'class': 'sc',
						href: '#' + this.setHash(hotspot.id, true),
						styles: {
							visibility: 'hidden',
							display: 'block'
						},
						events: {
							click: function (e) {
								this.hashChange(tmp_a.href);
								this.hotspots_goTo(hotspot);
								this.doJS(hotspot, true);
							}.bind(this)
						}
					}).inject(hotspotEl);

					// #Create span with label
					tmp_span_corner = new Element('span', {
						'class': 'corner'
					}).inject(tmp_a);
					tmp_span = new Element('span',{
						'class': 'txt',
						html: hotspot.label
					}).inject(tmp_span_corner);

					

					// #Calculating single hotspot size
					var hotspotSize = (hotspot.coordinates.x / this.options.hotspots.ratio).toInt() + hotspotEl.addClass('hover').getWidth().toInt();
					tmp_span.setStyle('width', tmp_span.getStyle('width'));
					hotspotEl.removeClass('hover');
					// #If hotspot position+size bigger than wrapper size, apply "right" class to change direction of hotspot
					if (hotspotSize > hotspotWrapperWidth) {
						hotspotEl.addClass('right');
					}

					// #Then remove style previously set for calculating size
					hotspotEl.setStyles({
						left: (hotspot.coordinates.x / this.options.hotspots.ratio).toInt() + 'px',
						top: (hotspot.coordinates.y / this.options.hotspots.ratio).toInt() + 'px'
					});
					tmp_a.removeProperty('style');
				}, this);

				return this;
			},
		// #360
		tcs_setContent: function(data) {
			this.hideContent().setMask('simple');

			if (!$defined(this.tcs)) {
				this.tcs = {};
				// #WRAPPER
				this.tcs.wrapper = new Element('div', {
					id: this.options.tcs.wrapper.id,
					'class': this.options.right_content
				}).inject(this.options.content_wrapper).fade('hide');
			}

			// FLASH REPLACEMENT
			this.tcs.flash = new Element('div', {
				id: this.options.tcs.flash_id
			}).inject(this.tcs.wrapper);

			// Set SWFDIR
			if ($defined(data.swfdir)) {
				var tmp_flashvars = {};
					tmp_flashvars['swfDir'] = data.swfdir;
				var tmp_flashvars = Object.merge(this.options.swfobject.flashvars, this.options.tcs.flashvars, tmp_flashvars);
			}
			else {
				var tmp_flashvars = Object.merge(this.options.swfobject.flashvars, this.options.tcs.flashvars);
			}

			var attributes = Object.merge(this.options.swfobject.attributes, {'id': this.options.tcs.flash_id});

			// Inject flash
			swfobject.embedSWF(data.swffile, this.options.tcs.flash_id, this.options.tcs.flash_width, this.options.tcs.flash_height, this.options.swfobject.flashversion, false, tmp_flashvars, this.options.swfobject.params, attributes);

			if (!$is_empty(data.swffile)) {
				this.tcs.wrapper.fade('in');
			};
		}
});//end

