﻿if (typeof(MenuSlider) == 'undefined') { var MenuSlider = {}; }

MenuSlider = Class.create({
	'attempts': {},
	'contact_method': {},
	'container': null,
	'data': {
		'name_by_key': {},
		'solution_by_id': {},
		'subtopic_id_by_key': {},
		'subtopic_key_by_id': {},
		'subtopic_name_by_id': {},
		'subtopic_solutions_by_id': {},
		'topic_id_by_key': {},
		'topic_key_by_id': {},
		'topic_name_by_id': {},
		'topic_solutions_by_id': {}
	},
	'defaultLang': 'en',
	'defaultLocale': 'en_US',
	'emailpath': '',
	'expertpath': '',
	'haschat': false,
	'hasemail': false,
	'hasexpert': false,
	'hasphone': false,
	'hastopicbeenrequested': {},
	'more_link': {},
	'phonepath': '',
	'results': {},
	'solutions_built': 0,
	'topics_requested': {},
	
	'buildMoreLink': function(topic_id, div_collection) {
		var more_link = this.more_link[topic_id];
		if (more_link != undefined && more_link.enabled == true) {
			var morelink_text = more_link.name;
			var morelink_p = new Element('p').addClassName('see_all');
			var morelink_ahref = new Element('a', { 
				'href': more_link.url,
				'target': '_blank'	
			});
			morelink_ahref.update(morelink_text);
			morelink_p.insert(morelink_ahref);
			div_collection.insert(morelink_p);
		}
	},
	
	'buildSolutions': function(solution_id, container, topic_id, subtopic_id) {
		var solution = this.data.solution_by_id[solution_id];
		var solution_key = (solution.type != 'page' && solution.type != 'video') ? solution.article : solution.key;
		var attempt = 0;
		var max_attempts = 100;
		if (this.results[solution_key] != undefined) {
			this.buildSolutionElement(solution_key, container, topic_id, subtopic_id);
			this.solutions_built++;
		}
		else {
			new PeriodicalExecuter(function(pe) {
				if (this.results[solution_key] != undefined) {
					this.buildSolutionElement(solution_key, container, topic_id, subtopic_id);
					this.solutions_built++;
					pe.stop();
				}
				else if (attempt >= max_attempts) {
					pe.stop();
				}
				attempt++;
			}.bind(this), 0.3);
		}
	},
	
	'buildSolutionElement': function(solution_key, container, topic_id, subtopic_id) {
		var result = this.results[solution_key];
		var h4 = new Element('h4');
		var result_title = result.title.replace(/'/g, '\\\'');
		var trackclick = [result.key, result.type, result_title, result.url].join('\',\'');
		/* dont open manual links in overlay */		
		var ahref = new Element('a', {
			'href': result.url,
			'target': '_blank'
		});
		ahref.update(result.title);
		if (result.type == 'page' || result.type == 'video') {
			ahref.observe('click', function(evt) {
				eval('MenuSlider.prototype.trackClick(\'' + trackclick + '\')');
			});
			if (result.type == 'video') {
				ahref.addClassName('video');
			}
		}
		else {
			var contact_method = this.contact_method[topic_id];
			var overlay_options = [];
			overlay_options.push(solution_key);
			if (contact_method.email != false) {
				overlay_options.push(contact_method.email.form);
			}
			ahref.observe('click', function(evt) {
				if (evt) evt.stop();
				eval('MenuSlider.prototype.trackClick(\'' + trackclick + '\')');
				eval('window.overlay.update(\'' + overlay_options.join('\',\'') + '\')');
			});
		}
		h4.insert(ahref);
		var p = new Element('p');
		var solution_excerpt = result.excerpt;
		p.update(solution_excerpt);
		container.insert(h4);
		container.insert(p);
		if ($('haveyoutried').hasClassName('loading')) {
			$('haveyoutried').removeClassName('loading');
		}
	},
	
	'buildSubtopicsNavElement': function(topic_id, subtopic_id) {
		var subtopic_key = this.data.subtopic_key_by_id[subtopic_id];
		var span_1 = new Element('span');
		var span_2 = new Element('span').update(this.data.name_by_key[subtopic_key]);
		var li = new Element('li', {'id': 'subtopic_' + subtopic_id});
		span_1.insert(span_2);
		li.observe('click', this.clickSubtopic.bindAsEventListener(this, topic_id, subtopic_id));
		li.insert(span_1);
		return li;
	},
	
	'buildTopicNavElement': function(topic_id, ul) {
		var topic_key = this.data.topic_key_by_id[topic_id];
		var div_topic = new Element('div', {'id': 'topic_' + topic_id});
		div_topic.addClassName('topic').addClassName('category');
		var div_subtopic = new Element('div', {'id': 'subtopics_' + topic_id});
		div_subtopic.addClassName('subtopics').addClassName('drawer').hide();
		var h3 = new Element('h3');
		h3.update(this.data.name_by_key[topic_key]);
		h3.observe('click', this.clickTopic.bindAsEventListener(this, topic_id));
		div_subtopic.insert(ul);
		div_topic.insert(h3);
		div_topic.insert(div_subtopic);
		this.container.insert(div_topic);
	},
	
	'clickSubtopic': function(e) {
		var args = Array.prototype.slice.call(arguments);
		var topic_id = args[1];
		var topic_key = this.data.topic_key_by_id[topic_id];
		var subtopic_id = args[2];
		var subtopic_solutions = this.data.subtopic_solutions_by_id[subtopic_id];
		
		/* handle topic nav */
		$$('div.topic.selected').each(function(div_topic) {
			div_topic.removeClassName('selected');
		}.bind(this));
		$$('div.subtopics li.selected').each(function(div_subtopic) {
			if (div_subtopic.identify() != 'subtopic_' + subtopic_id) {
				div_subtopic.removeClassName('selected');
			}
		}.bind(this));
		if (!$('subtopic_' + subtopic_id).hasClassName('selected')) {
			$('subtopic_' + subtopic_id).addClassName('selected')
		}
		
		/* clear out right panel */
		$('articles').descendants().invoke('remove');
		
		/* display service: apple expert, chat or email */
		var contact_method = this.contact_method[topic_id];
		if (contact_method.expert != false) {
			if ($('helpexpert')) { $('helpexpert').show(); }
			if ($('helpphone')) { $('helpphone').hide(); }
			if ($('helpchat')) { $('helpchat').hide(); }
			if ($('helpemail')) { $('helpemail').hide(); }
			if ($('expert_button')) { this.updateExpertUrl(topic_id, subtopic_id); }
		}
		else if (contact_method.phone != false) {
			if ($('helpexpert')) { $('helpexpert').hide(); }
			if ($('helpphone')) { $('helpphone').show(); }
			if ($('helpchat')) { $('helpchat').hide(); }
			if ($('helpemail')) { $('helpemail').hide(); }
			if ($('phone_button')) { this.updatePhoneUrl(topic_id, subtopic_id); }
		}
		else if (contact_method.chat != false) {
			if ($('helpexpert')) { $('helpexpert').hide(); }
			if ($('helpphone')) { $('helpphone').hide(); }
			/* display of chat/email is also handled in mtagconfig.js  */
			if ($('helpchat') && $('helpemail')) {
				if (lastChatStatus == 'chat') { 
					$('helpemail').hide();
					$('helpchat').show();
				}
				else if (lastChatStatus == 'email' || lastChatStatus == '') { 
					$('helpchat').hide();
					$('helpemail').show();	
				}
			}
			if ($('email_button')) { this.updateEmailUrl(topic_id, subtopic_id); }
		}
		else if (contact_method.email != false) {
			var email = contact_method.email;
			if ($('helpexpert')) { $('helpexpert').hide(); }
			if ($('helpphone')) { $('helpphone').hide(); }
			if ($('helpchat')) { $('helpchat').hide(); }
			if ($('helpemail')) { $('helpemail').show(); }
			if ($('email_button')) { this.updateEmailUrl(topic_id, subtopic_id); }
		}
		else {
			if ($('helpexpert')) { $('helpexpert').hide(); }
			if ($('helpphone')) { $('helpphone').hide(); }
			if ($('helpchat')) { $('helpchat').hide(); }
			if ($('helpemail')) { $('helpemail').hide(); }
		}
		
		/* build solutions / article links and excerpt */
		var div_collection = new Element('div').addClassName('collection selected');
		$('articles').insert(div_collection);
		this.solutions_built = 0;
		for (var i = 0; i < subtopic_solutions.length; i++) {
			this.buildSolutions(subtopic_solutions[i], div_collection, topic_id, subtopic_id);
		}
						
		/* add more link */
		var attempt = 0;
		if (this.solutions_built == subtopic_solutions.length) {
			this.buildMoreLink(topic_id, div_collection);
		}
		else {
			var max_attempts = 100;
			new PeriodicalExecuter(function(pe) {
				if (this.solutions_built == subtopic_solutions.length) {
					this.buildMoreLink(topic_id, div_collection);
					pe.stop();
				}
				else if (attempt >= max_attempts) {
					pe.stop();
				}
				attempt++;
			}.bind(this), 0.3);
		}
		
		/* display */
		$('articles').show();
		$('stillneedhelp').show();
		$('haveyoutried').show();
		$('select-category').removeClassName('selected');
		$('select-topic').removeClassName('selected');
		$('select-article').addClassName('selected');
		
		/* sitecatalyst click tracking */
		var track_click_title = this.data.topic_name_by_id[topic_id] + ' - ' + this.data.subtopic_name_by_id[subtopic_id];
		this.trackClick(undefined, undefined, track_click_title, undefined);
	},
	
	'clickTopic': function(e) {
		var args = Array.prototype.slice.call(arguments);
		var topic_id = args[1];
		var topic_key = this.data.topic_key_by_id[topic_id];
		var topic_solutions = this.data.topic_solutions_by_id[topic_id];
		var click_action = 'open';
		
		if (!$('haveyoutried').hasClassName('loading')) {
			$('haveyoutried').addClassName('loading');
		}
		
		if (topic_solutions != undefined) {
			this.sendRequest(topic_id, topic_solutions);
		}
		
		var div_topic_id = 'topic_' + topic_id;
		var div_subtopics_id = 'subtopics_' + topic_id;
		
		$$('div.subtopics li.selected').each(function(div_subtopic) {
			div_subtopic.removeClassName('selected');
		});
		
		if ($(div_topic_id).hasClassName('selected')) {
			$(div_topic_id).removeClassName('selected');
			Effect.BlindUp($(div_subtopics_id), {duration: 0.3});
			click_action = 'close';
		}
		else {
			if ($(div_subtopics_id).visible()) {
				$(div_topic_id).removeClassName('selected');
				Effect.BlindUp($(div_subtopics_id), {duration: 0.3});
				click_action = 'close';
			}
			else {
				$$('div.topic').each(function(div_topic) {
					if (div_topic.identify() != div_topic_id) {
						div_topic.removeClassName('selected');
						Effect.BlindUp(div_topic.select('div.subtopics').first(), {duration: 0.3});
					}
				});
				$(div_topic_id).addClassName('selected');
				Effect.BlindDown($(div_subtopics_id), {duration: 0.3});
				click_action = 'open';
			}
		}
		
		if ($(div_topic_id).hasClassName('selected')) {
			$('select-category').removeClassName('selected');
			$('select-topic').addClassName('selected');
			$('select-article').removeClassName('selected');
			var contact_method = this.contact_method[topic_id];
			if (contact_method.expert) {
				if ($('topicexpert')) { $('topicexpert').show(); }
				if ($('topicphone')) { $('topicphone').hide(); }
				if ($('topicchat')) { $('topicchat').hide(); }
				if ($('topicemail')) { $('topicemail').hide(); }
			}
			else if (contact_method.phone) {
				if ($('topicexpert')) { $('topicexpert').hide(); }
				if ($('topicphone')) { $('topicphone').show(); }
				if ($('topicchat')) { $('topicchat').hide(); }
				if ($('topicemail')) { $('topicemail').hide(); }
			}
			else if (contact_method.chat) {
				if (contact_method.chat.enabled == 'true') {
					if ($('helpemail') && $('helpemail').visible()) {
						$('helpchat').hide();
					}
					else if ($('helpchat') && $('helpchat').visible()) {
						$('helpemail').hide();
					}
					/* create chat button (mtagconfig.js) */
					createChatButton(contact_method.chat.skill, contact_method.chat.language, this.data.topic_name_by_id[topic_id], this.getPageCountry());
				}
				if ($('topicexpert')) { $('topicexpert').hide(); }
				if ($('topicphone')) { $('topicphone').hide(); }
				if ($('topicchat')) { $('topicchat').show(); }
				if ($('topicemail')) { $('topicemail').hide(); }
			}
			else if (contact_method.email) {
				if ($('topicexpert')) { $('topicexpert').hide(); }
				if ($('topicphone')) { $('topicphone').hide(); }
				if ($('topicchat')) { $('topicchat').hide(); }
				if ($('topicemail')) { $('topicemail').show(); }
			}
		}
		else {
			$('select-category').addClassName('selected');
			$('select-topic').removeClassName('selected');
			$('select-article').removeClassName('selected');
		}
		$('stillneedhelp').hide();
		$('haveyoutried').hide();
		
		/* sitecatalyst click tracking */
		if (click_action == 'open') {
			var track_click_title = this.data.topic_name_by_id[topic_id];
			this.trackClick(undefined, undefined, track_click_title, undefined);
		}
	},
	
	'convertLocaleForKmLoader': function(locale) {
		/* US Latino */
		if (locale == 'es_US') {
			return 'es_ES';
		}
		/* EMEA */
		else if (locale == 'en_EM') {
			return 'en_US';
		}
		else {
			return locale;
		}
	},
	
	'doesOnlyListExist': function(item) {
		return (item.getAttribute('only') != null) ? true : false;
	},
	
	'extractName': function(item, tag, lang_override) {
		var name = null;
		if (item != undefined && tag != undefined) {
			var langs = [];
			if (lang_override != undefined) {
				langs = [lang_override];
			}
			else {
				langs = [this.getPageLocale(), this.getPageLang(), this.defaultLang];
			}
			for (i = 0; i < langs.length; i++) {
				var subitem = item.getElementsByTagName(tag);
				for (var j = 0; j < subitem.length; j++) {
					if (name == null && subitem[j].getAttribute('lang') == langs[i]) {
						name = this.getValue(subitem[j]);
					}
				}
			}
		}
		return name;
	},
	
	'getHelpPath': function(url) {
		return url.replace(/http\:\/\/docs\.info\.apple\.com\/article.html\?path\=/, '');
	},
	
	'getHostForKmLoader': function() {
		return KmLoader.akamaiUrl;
	},
	
	'getLangDir': function() {
		if (this.getPageLocale() == 'pt_BR') { return 'pt-br'; }
		else if (this.getPageLocale() == 'pt_PT') { return 'pt-pt'; }
		else if (this.getPageLocale() == 'zh_CN') { return 'zh-cn'; }
		else if (this.getPageLocale() == 'zh_TW') { return 'zh-tw'; }
		else { return this.getPageLang(); }
	},
	
	'getLocaleForKmLoader': function() {
		if (this.getPageLang() == 'de') { return 'de_DE'; }
		else if (this.getPageLang() == 'en') { return 'en_US'; }
		else if (this.getPageLang() == 'es') { return 'es_ES'; }
		else if (this.getPageLang() == 'fr') { return 'fr_FR'; }
		else if (this.getPageLang() == 'nl') { return 'nl_NL'; }
		else { return this.getPageLocale(); }
	},
	
	'getPageCountry': function() {
		return ACWPod.getCountry();
	},
	
	'getPageLang': function() {
		return ACWPod.getLang();
	},
	
	'getPageLocale': function() {
		/* override POD for HK */
		if (ACWPod.getLocale() == 'zh_HK') {
			return 'zh_TW';
		}
		else {
			return ACWPod.getLocale();
		}
	},
	
	'getValue': function(xmlnode) {
		return xmlnode.textContent || xmlnode.text || xmlnode.innerText;
	},
	
	'hasTopicBeenRequested': function(topic_id) {
		if (this.topics_requested[topic_id] == undefined) {
			this.topics_requested[topic_id] = topic_id;
			return false;
		}
		else {
			return true;
		}
	},
	
	'initialize': function(container) {
		if (!container) { return false; }
		this.container = container;
		this.loadSolutionsAndTopics();
		window.overlay = new MenuSlider.Overlay();
		
		/* hide solution elements */
		$('stillneedhelp').hide();
		$('haveyoutried').hide();
	},
	
	'isExcludeListMember': function(item) {
		var exclude = item.getAttribute('exclude');
		if (exclude != null) {
			exclude = exclude.replace(/\s+/g, '');
			var locales = exclude.split(',');
			var locale_match = false;
			for (var i = 0; i < locales.length; i++) {
				if (locales[i] == this.getPageLocale()) {
					locale_match = true;
				}
			}
			return locale_match;
		}
		else {
			return false;
		}
	},
	
	'isOnlyListMember': function(item) {
		var only = item.getAttribute('only');
		if (only != null) {
			only = only.replace(/\s+/g, '');
			var locales = only.split(',');
			var locale_match = false;
			for (var i = 0; i < locales.length; i++) {
				if (locales[i] == this.getPageLocale()) {
					locale_match = true;
				}
			}
			return locale_match;
		}
		else {
			return false;
		}
	},
	
	'isShowable': function(item) {
		if (this.doesOnlyListExist(item)) {
			return (this.isOnlyListMember(item)) ? true : false;
		}
		else if (this.isExcludeListMember(item)) {
			return false;
		}
		else {
			return true;
		}
	},
	
	'isTier1and2': function() {
		var locales = ['da_DK', 'es_LA', 'fi_FI', 'it_IT', 'ko_KR', 'nl_BE', 'nl_NL', 'no_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ru_RU', 'sv_SE', 'zh_CN', 'zh_HK', 'zh_TW'];
		var ismatch = false;
		for (var i = 0; i < locales.length; i++) {
			if (this.getPageLocale() == locales[i]) {
				ismatch = true;
			}
		}
		return ismatch;
	},
	
	'loadScript': function(url) {
		$$('head').first().insert(new Element('script', {
			'src': url,
			'type': 'text/javascript',
			'charset': 'utf-8'
		}));
	},
	
	'loadSolutionsAndTopics': function() {
		var topic_names = null;
		var solutions = null;
		new Ajax.Request('/support/itunes/feeds/topic_names.xml', {
			method: 'get',
			onSuccess: function(transport) {
				topic_names = transport.responseXML;
			}
		});
		new Ajax.Request('/support/itunes/feeds/solutions.xml', {
			method: 'get',
			onSuccess: function(transport) {
				solutions = transport.responseXML;
			}
		});
		new PeriodicalExecuter(function(pe) {
			if (topic_names != null && solutions != null) {
				this.parseTopicNames(topic_names);
				this.parseSolutions(solutions);
				pe.stop();
			}
		}.bind(this), 0.1);

	},
	
	'parseResults': function(json, requestId) {
		for (var i = 0 ; i < json.results.length; i++) {
			var result = json.results[i];
			var result_key = '';
			var result_type = '';
			var result_url = '';
			/* kb article result */
			if (result.documentid != undefined) {
				result_key = result.documentid;
				result_type = 'kb';
				result_url = result.url;
			}
			/* help article result */
			else if (result.url != undefined) {
				result_key = this.getHelpPath(result.url);
				result_key = result_key.replace(/^(.+\/)[^\/]+(\/[^\/]+)$/, '$1' + 'locale' + '$2');
				result_type = 'help';
				result_url = result.url;
			}
			this.storeResult(result_key, result_type, result.title, result_url, result.excerpt);
		}
	},
	
	'parseSolutions': function(xml) {
		var topic_id = 0;
		var subtopic_id = 0;
		var solution_id = 0;
		
		/* topics */
		var topics = xml.getElementsByTagName('topic');
		for (var i = 0; i < topics.length; i++) {
			var topic = topics[i];
			
			if (this.isShowable(topic)) {
				var topic_key = topic.getAttribute('key');
				this.data.topic_id_by_key[topic_key] = topic_id;
				this.data.topic_key_by_id[topic_id] = topic_key;
				this.data.topic_name_by_id[topic_id] = this.data.name_by_key[topic_key];
				this.data.topic_solutions_by_id[topic_id] = [];
				
				var ul = new Element('ul');
				
				/* subtopics */
				var subtopics = topic.getElementsByTagName('subtopic');
				for (var j = 0; j < subtopics.length; j++) {
					var subtopic = subtopics[j];
					
					if (this.isShowable(subtopic)) {
						var subtopic_key = subtopic.getAttribute('key');
						this.data.subtopic_id_by_key[subtopic_key] = subtopic_id;
						this.data.subtopic_key_by_id[subtopic_id] = subtopic_key;
						this.data.subtopic_name_by_id[subtopic_id] = this.data.name_by_key[subtopic_key];
						this.data.subtopic_solutions_by_id[subtopic_id] = [];
														
						/* solutions */
						var solutions = subtopic.getElementsByTagName('solution');
						for (var k = 0; k < solutions.length; k++) {
							var solution = solutions[k];
							
							if (this.isShowable(solution)) {
								var solution_article = this.getValue(solution);
								this.data.solution_by_id[solution_id] = {
									'key': solution.getAttribute('key'),
									'type': solution.getAttribute('type'),
									'article': solution_article,
									'excerpt': solution.getAttribute('excerpt')
								};
								this.data.topic_solutions_by_id[topic_id].push(solution_id);
								this.data.subtopic_solutions_by_id[subtopic_id].push(solution_id);
								solution_id++;
							}
						}
						
						/* builds and inserts dom elements for subtopic nav */
						ul.insert(this.buildSubtopicsNavElement(topic_id, subtopic_id));
						
						subtopic_id++;
					}
				}
				
				/* more link */
				this.storeMoreLink(topic, topic_id);
				
				/* which contact method available for topic: apple expert, chat, or email */
				this.storeContactMethods(topic, topic_id);
				
				/* builds and inserts dom elements for topic nav */
				this.buildTopicNavElement(topic_id, ul);

				topic_id++;
			}
		}
		
		this.container.removeClassName('loading');
		
		/* show right panel description at startup */
		var iconclass = 'helpicons_';
		if (this.hasexpert || this.hasphone) { iconclass += 'x'; }
		if (this.haschat) { iconclass += 'c'; }
		if (this.hasemail) { iconclass += 'e'; }
		$('select-category').addClassName(iconclass);
		$('select-category').addClassName('selected');
		
		/* expand topic if specified in url */
		var urlhash = window.location.hash.replace(/\#/,'');
		if (this.data.topic_id_by_key[urlhash] != undefined) {
			this.clickTopic(this, this.data.topic_id_by_key[urlhash]);
		}
		
		/* get an store email path */
		if ($('email_button')) { this.emailpath = $('email_button').getAttribute('href'); }
		if ($('expert_button')) { this.expertpath = $('expert_button').getAttribute('href'); }
		if ($('phone_button')) { this.phonepath = $('phone_button').getAttribute('href'); }
	},
	
	'parseTopicNames': function(topic_names) {
		var topics = topic_names.getElementsByTagName('topic_name');
		for (var i = 0; i < topics.length; i++) {
			this.storeName(topics[i], 'topic');
			var subtopics = topics[i].getElementsByTagName('subtopic_name');
			for (var j = 0; j < subtopics.length; j++) {
				this.storeName(subtopics[j], 'subtopic');
				var solutions = subtopics[j].getElementsByTagName('solution_name');
				for (var k = 0; k < solutions.length; k++) {
					this.storeName(solutions[k], 'solution');
					var excerpts = solutions[k].getElementsByTagName('excerpt_name');
					for (var l = 0; l < excerpts.length; l++) {
						this.storeName(excerpts[l], 'excerpt', solutions[k].getAttribute('key') + '_excerpt');
					}
				}
			}
			var more_links = topics[i].getElementsByTagName('more_link_name');
			for (var j = 0; j < more_links.length; j++) {
				this.storeName(more_links[j], 'more_link', topics[i].getAttribute('key') + '_more_link');
			}
		}
	},
	
	'receiveSuccess': function(json, requestId) {
		if (json == undefined || json == null) {
			alert('Something went wrong. Please try again!') 
		}
		else if (json.results) {
			var loadingImages = $('haveyoutried').getElementsBySelector('img.loading');
			loadingImages.each(function(image) {
				image.remove();
			});
			/* for title, link & excerpt */
			this.parseResults(json, requestId);
		}
		else if (json.records) {
			/* for article content */
			MenuSlider.Article.prototype.parseRecord(json, requestId);
		}
	},
	
	'requestHelpArticle': function(helpid, locale) {
		this.loadScript(this.getHostForKmLoader() + '/docs/kmrecord.html?requestid=1&locale=' + this.convertLocaleForKmLoader(locale) + '&paths=' + escape(helpid) + '&callback=MenuSlider.prototype.receiveSuccess');
	},
	
	'requestHelpArticles': function(requestid, helpids) {
		this.loadScript(this.getHostForKmLoader() + '/docs/kmdata.html?requestid=' + requestid + '&locale=' + this.getLocaleForKmLoader() + '&excerpt=y&paths=' + escape(helpids) + '&callback=MenuSlider.prototype.receiveSuccess');
	},
	
	'requestKbArticle': function(articleid, locale) {
		this.loadScript(this.getHostForKmLoader() + '/kb/index?page=kmrecord&requestid=1&locale=' + this.convertLocaleForKmLoader(locale) + '&documentids=' + escape(articleid) + '&callback=MenuSlider.prototype.receiveSuccess');
	},
	
	'requestKbArticles': function(requestid, articleids) {
		this.loadScript(this.getHostForKmLoader() + '/kb/index?page=kmdata&requestid=' + requestid + '&locale=' + this.getLocaleForKmLoader() + '&excerpt=y&documentids=' + escape(articleids) + '&maxrecords=30&callback=MenuSlider.prototype.receiveSuccess');
	},
	
	'sendRequest': function(topic_id, solution_ids) {
		if (topic_id != undefined && solution_ids != undefined) {
			var article_kb_list = [];
			var article_help_list = [];
			for (var i = 0; i < solution_ids.length; i++) {
				var solution = this.data.solution_by_id[solution_ids[i]];
				if (solution.type == 'kb') {
					article_kb_list.push(solution.article);
				}
				else if (solution.type == 'help') {
					article_help_list.push(solution.article);
				}
				/* dont send request for type=page solutions */
				else if (solution.type == 'page' || solution.type == 'video') {
					var solution_title = this.data.name_by_key[solution.key];
					var solution_excerpt = this.data.name_by_key[solution.key + '_excerpt'];
					this.storeResult(solution.key, solution.type, solution_title, solution.article, solution_excerpt);
				}
			}
			if (this.hasTopicBeenRequested(topic_id) == false) {
				if (article_kb_list.length > 0) {
					this.requestKbArticles(topic_id, article_kb_list.join(','));
				}
				if (article_help_list.length > 0) {
					this.requestHelpArticles(topic_id, article_help_list.join(','));
				}
			}
		}
	},
	
	'storeContactMethods': function(topic, topic_id) {
		this.contact_method[topic_id] = {};
		
		/* apple expert */
		this.contact_method[topic_id].expert = false;
		var experts = topic.getElementsByTagName('expert');
		for (var j = 0; j < experts.length; j++) {
			var expert = experts[j];
			var expert_enabled = this.getValue(expert);
			if (this.isShowable(expert) && expert_enabled == 'true') {
				this.contact_method[topic_id].expert = true;
				this.hasexpert = true;
			}
		}
		/* phone */
		this.contact_method[topic_id].phone = false;
		var phones = topic.getElementsByTagName('phone');
		for (var j = 0; j < phones.length; j++) {
			var phone = phones[j];
			var phone_enabled = this.getValue(phone);
			if (this.isShowable(phone) && phone_enabled == 'true') {
				this.contact_method[topic_id].phone = true;
				this.hasphone = true;
			}
		}
		/* chat */
		this.contact_method[topic_id].chat = false;
		var chats = topic.getElementsByTagName('chat');
		for (var j = 0; j < chats.length; j++) {
			var chat = chats[j];
			var chat_enabled = this.getValue(chat);
			if (this.isShowable(chat) && chat_enabled == 'true') {
				var chat_lang = chat.getAttribute('language');
				var chat_skill = chat.getAttribute('skill');
				if (chat_lang != null && chat_skill != null) {
					this.contact_method[topic_id].chat = { 
						'language': chat_lang,
						'skill': chat_skill,
						'enabled': chat_enabled
					};
					this.haschat = true;
				}
			}
		}
		/* email */
		this.contact_method[topic_id].email = false;
		var emails = topic.getElementsByTagName('email');
		for (var j = 0; j < emails.length; j++) {
			var email = emails[j];
			var email_enabled = this.getValue(email);
			if (this.isShowable(email) && email_enabled == 'true') {
				var email_form = email.getAttribute('form');
				if (email_form != null) {
					this.contact_method[topic_id].email = { 'form': email_form };
					this.hasemail = true;
				}
			}
		}
	},
	
	'storeMoreLink': function(topic, topic_id) {
		var topic_key = this.data.topic_key_by_id[topic_id];
		this.more_link[topic_id] = {};
		this.more_link[topic_id].enabled = false;
		var more_links = topic.getElementsByTagName('more_link');
		for (var j = 0; j < more_links.length; j++) {
			var more_link = more_links[j];
			var more_link_enabled = this.getValue(more_link);
			if (this.isShowable(more_link) && more_link_enabled == 'true') {
				this.more_link[topic_id].enabled = true;
				this.more_link[topic_id].name = this.data.name_by_key[topic_key + '_more_link'];
				this.more_link[topic_id].url = 'http://support.apple.com/kb/index?page=search&src=support_site.psp.itunes.more&q=' + escape(this.data.name_by_key[topic_key]);
			}
		}
	},
	
	'storeResult': function(key, type, title, url, excerpt) {
		if (type != 'page' && type != 'video') {
			this.results[key] = {
				'key': (key != undefined && key != null) ? key : '',
				'type': (type != undefined && type != null) ? type : '',
				'title': (title != undefined && title != null) ? title : '',
				'url': (url != undefined && url != null) ? url : '',
				'excerpt': (excerpt != undefined && excerpt != null) ? this.truncateExcerpt(excerpt) : ''
			};
		}
		else {
			this.results[key] = {
				'key': (key != undefined && key != null) ? key : '',
				'type': (type != undefined && type != null) ? type : '',
				'title': (title != undefined && title != null) ? title : '',
				'url': (url != undefined && url != null) ? url : '',
				'excerpt': (excerpt != undefined && excerpt != null) ? this.truncateExcerpt(excerpt) : ''
			};
		}
	},
	
	'storeName': function(item, tag, key) {
		if (item != undefined && tag != undefined) {
			var name = this.extractName(item, tag);
			var en_name = this.extractName(item, tag, 'en');
			if (name != null) {
				if (key != undefined) {
					this.data.name_by_key[key] = name;
					this.data.name_by_key[key + '-en'] = en_name;
				}
				else if (item.getAttribute('key') != undefined) {
					this.data.name_by_key[item.getAttribute('key')] = name;
					this.data.name_by_key[item.getAttribute('key') + '-en'] = en_name;
				}
			}
		}
	},
	
	'trackClick': function(id, type, title, url) {
		// send click tracking data to sitecatalyst
		var title = (title != undefined) ? title : '';
		var url = (url != undefined) ? url: document.URL;
		var tracking_title = '';
		if (id != undefined && type != undefined) {
			if (type == 'kb') {
				tracking_title += id + ': ';
			}
			if (title != '') {
				tracking_title += title;
			}
		}
		else if (title != '') {
			tracking_title += title;
		}
		if (typeof(SCReporting) != 'undefined') {
			SCReporting.trackClick(tracking_title, url);
		}
	},
	
	'truncateExcerpt': function(excerpt) {
		var truncated_excerpt = excerpt;
		var excerptLimit = 150;
		if (this.getPageLang() == 'ja') {
			if (truncated_excerpt.indexOf('。') != -1) {
				var shortened = truncated_excerpt.split('。');
				truncated_excerpt = shortened[0] + '。';
			}
		}
		if (truncated_excerpt.length > excerptLimit) {
			truncated_excerpt = truncated_excerpt.truncate(excerptLimit);
			var words = truncated_excerpt.split(' ');
			truncated_excerpt = '';
			words = words.without(words.last());
			words.each(function(word) {
				truncated_excerpt += ' ' + word;
			});
			truncated_excerpt += '...';
		}
		return truncated_excerpt;
	},
	
	'updateEmailUrl': function(topic_id, subtopic_id) {
		var topic_key = this.data.topic_key_by_id[topic_id];
		var subtopic_key = this.data.subtopic_key_by_id[subtopic_id];
		if (this.isTier1and2()) {
			topic_key += '-en';
			subtopic_key += '-en';
		}
		var topic_name = encodeURI(this.data.name_by_key[topic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');  
		var subtopic_name = encodeURI(this.data.name_by_key[subtopic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');
		var contact_method = this.contact_method[topic_id].email;
		if (contact_method != undefined && contact_method.form != '') {
			$('email_button').setAttribute('href', this.emailpath + '?form=' + contact_method.form + '&topic=' + topic_name + '&subtopic=' + subtopic_name);
		}
		else {
			$('email_button').setAttribute('href', this.emailpath);
		}
	},
	
	'updateExpertUrl': function(topic_id, subtopic_id) {
		var topic_key = this.data.topic_key_by_id[topic_id] + '-en';
		var subtopic_key = this.data.subtopic_key_by_id[subtopic_id] + '-en';
		var topic_name = encodeURI(this.data.name_by_key[topic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');  
		var subtopic_name = encodeURI(this.data.name_by_key[subtopic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');
		var contact_method = this.contact_method[topic_id].expert;
		if (contact_method != undefined) {
			$('expert_button').setAttribute('href', this.expertpath + '?topic=' + topic_name + '&subtopic=' + subtopic_name);
		}
		else {
			$('expert_button').setAttribute('href', this.expertpath);
		}
	},
	
	'updatePhoneUrl': function(topic_id, subtopic_id) {
		var topic_key = this.data.topic_key_by_id[topic_id] + '-en';
		var subtopic_key = this.data.subtopic_key_by_id[subtopic_id] + '-en';
		var topic_name = encodeURI(this.data.name_by_key[topic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');  
		var subtopic_name = encodeURI(this.data.name_by_key[subtopic_key]).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');
		var contact_method = this.contact_method[topic_id].phone;
		if (contact_method != undefined) {
			$('phone_button').setAttribute('href', this.phonepath + '?topic=' + topic_name + '&subtopic=' + subtopic_name);
		}
		else {
			$('phone_button').setAttribute('href', this.phonepath);
		}
	}

});


MenuSlider.Overlay = Class.create();
Object.extend(MenuSlider.Overlay.prototype, MenuSlider.prototype);
Object.extend(MenuSlider.Overlay.prototype, {

	initialize: function(title, articleid, options) {
		this.title = title;
		this.articleid = articleid;

		this.options = options || {};
		if (!this.options.show) this.options.show = {};
		if (!this.options.hide) this.options.hide = {};

		this.options.show.afterFinish = function() {
			$('overlay').down('.content').addClassName('selected');
		}
		this.options.hide.beforeStart = function() {
			$('overlay').down('.content').removeClassName('selected');
		}

		this.createOverlay();
		this.createShadow();
		this.createObstruction();
	},

	createOverlay: function() {
		if (this.overlay) return false;

		this.overlay = new Element('div', { id:'overlay', 'style':'display:none;' });

		// bring in overlay html:
		var url = '/support/itunes/' + this.getLangDir() + '/overlay.html';
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				// embed html into page
				this.overlay.innerHTML = transport.responseText;
				// set event handlers
				var close = this.overlay.down('.close a')
				close.observe('click', function() {
					this.options.hide['afterFinish'] = '';
					this.trackClick(this.articleid, this.articletype, this.truncateTitle(this.title)+' - Close', this.articleurl);
					this.hide();
				}.bind(this));
				
				var yes = this.overlay.down('.yes a');
				yes.observe('click', function() {
					this.options.hide['afterFinish'] = function() {
						this.reset();
					}.bind(this);
					this.trackClick(this.articleid, this.articletype, this.truncateTitle(this.title)+' - Yes', this.articleurl);
					this.hide();
				}.bind(this));

				var no = this.overlay.down('.no a')
				no.observe('click', function() {
					this.options.hide['afterFinish'] = '';
					this.trackClick(this.articleid, this.articletype, this.truncateTitle(this.title)+' - No', this.articleurl);
					this.hide();
				}.bind(this));

				var contact = this.overlay.down('.contact a');
				contact.observe('click', function(evt) {
					if (evt) evt.stop();

					if (this.emailonly == false) {
						this.options.hide['afterFinish'] = function() {
							this.showContact();
						}.bind(this)
						this.hide();			
					}
					else {
						var subtopic = $$('li.selected span span').first();
						var topic = $(subtopic).up('div.category');
						window.location = contact.href + '?form=' + this.emailform + '&topic=' + encodeURI(topic.innerHTML).replace(/\//g,'%2F').replace(/\&amp;/g,'%26') + '&subtopic=' + encodeURI(subtopic.innerHTML).replace(/\//g,'%2F').replace(/\&amp;/g,'%26');
					}
					this.trackClick(this.articleid, this.articletype, this.truncateTitle(this.title)+' - Contact', this.articleurl);
				}.bind(this));

				this.content = this.overlay.down('.content');
				this.createContent(this.articlelocale);
				this.hide();
			}.bind(this)
		});

		$(document.body).insert({ bottom: this.overlay });
	},

	createShadow: function() {
		if (!this.shadow) {
			var imageSrc = '/support/itunes/images/overlay_shadow.png';
			var image = new Element('img', { 'src':imageSrc });
			this.shadow = $('overlayshadow') || new Element('div', { id: 'overlayshadow', 'style':'display:none;' });
			this.shadow.appendChild(image);

			document.body.appendChild(this.shadow);
		}
	},
	
	createObstruction: function() {
		if (!this.obstruction) {
			this.obstruction = $('overlayobstruction') || new Element('div', { id:'overlayobstruction', 'style':'display:none;' });
			this.obstruction.style.height = (document.body.offsetHeight>document.viewport.getHeight()) ? document.body.offsetHeight+'px' : document.viewport.getHeight()+'px';

			// click on the page and close the overlay
			this.obstruction.observe('click', this.hide.bind(this));

			document.body.appendChild(this.obstruction);
		}
	},

	createContent: function(articlelocale) {
		this.content.addClassName('loading');
		this.content.innerHTML = '';

		var title = new Element('h2', { 'class':'title' });
		title.innerHTML = this.title;

		this.content.insert(title);

		// api call
		var locale = (articlelocale != undefined) ? articlelocale : this.defaultLocale;
		if (this.articletype == 'kb') {
			if (this.results[this.articleid] != undefined && this.results[this.articleid].url != undefined) {
				if (this.results[this.articleid].url.indexOf('viewlocale=') != -1) {
					this.requestKbArticle(this.articleid, locale);
				}
				else {
					this.requestKbArticle(this.articleid, 'en_US');
				}
			}
			else {
				this.requestKbArticle(this.articleid, 'en_US');
			}
		}
		else if (this.articletype == 'help'){
			this.requestHelpArticle(this.articleid, locale);
		}
		else {
			this.requestKbArticle(this.articleid, locale);
		}
	},

	show: function() {
		// verically and horizontally center
		var overlayMarginLeft = -(this.overlay.getWidth()/2);
		this.overlay.style.marginLeft = overlayMarginLeft + 'px';
		this.shadow.style.marginLeft = overlayMarginLeft - 13 + 'px';
		if (typeof document.body.style.maxHeight === 'undefined') {
			// if ie6
			var html = $$('html')[0];
			$(html).setStyle({
				overflow: 'hidden',
				height: '100%',
				width: '100%'
			});
			$(html.down('body')).setStyle({
				height: '100%',
				width: '100%'
			});
		} else {
			// other browsers
			var overlayMarginTop = -(this.overlay.getHeight()/2);
			this.overlay.style.marginTop = overlayMarginTop + 'px';
			this.shadow.style.marginTop = overlayMarginTop - 13 + 'px';		
		}

		new Effect.Parallel([
			Effect.Appear(this.overlay, { sync:true }),
			Effect.Appear(this.shadow, { sync:true }),
			Effect.Appear(this.obstruction, { to:.5, sync:true })
		], {
			duration:.5,
			beforeStart: this.options.show.beforeStart,
			afterFinish: this.options.show.afterFinish
		});
	},

	hide: function(type) {
		new Effect.Parallel([
			Effect.Fade(this.overlay, { sync:true }),
			Effect.Fade(this.shadow, { sync:true }),
			Effect.Fade(this.obstruction, { sync:true })
		], {
			duration:.5,
			beforeStart: this.options.hide.beforeStart,
			afterFinish: this.options.hide.afterFinish
		});
		if (typeof document.body.style.maxHeight === 'undefined') {
			// if ie6
			var html = $$('html')[0];
			$(html).setStyle({
				overflow: '',
				height: 'auto',
				width: 'auto'
			});
			$(html.down('body')).setStyle({
				height: 'auto',
				width: 'auto'
			});
		}
	},

	update: function(solution_key, emailform) {
		if (solution_key == undefined) { return false; }
		var result = this.results[solution_key];		
		if (result != undefined) {
			this.title = result.title;
			this.articletype = result.type;
			if (result.type == 'help') {
				this.articleid = this.getHelpPath(result.url);
			}
			else if (result.type == 'kb') {
				this.articleid = result.key;
			}
			this.articleurl = result.url;
		}
		else {
			this.title = '';
			this.articletype = '';
			this.articleid = solution_key;
			this.articleurl = '';
		}

		if (emailform != undefined) {
			this.emailform = emailform;
			this.emailonly = true;
		} else {
			this.emailform = '';
			this.emailonly = false;
		}

		//if (emailonly) {
		//	this.emailonly = true;
		//} else {
		//	this.emailonly = false;
		//}

		this.content = $('overlay').down('.content');
		this.createContent(this.getLocaleForKmLoader());

		this.show();
	},
	
	truncateTitle: function(title) {
		return (title != undefined) ? title.truncate(70) : title;
	},
	
	showMessage: function(div) {
		var div = $(div);

		// hide other messages
		this.removeSelected(div.parentNode.down('.swap.selected'))
		
		// show this message
		div.addClassName('selected');
	},

	reset: function() {		
		// close drawer, if drawer is open
		var liselected = $('issues').down('li.selected');
		if (liselected) {
			var categorydiv = liselected.up('.category');
			var drawer = categorydiv.down('.drawer');
			MenuSlider.Drawer.prototype.closeDrawer(categorydiv, drawer);
			if (categorydiv.hasClassName('secondary')) categorydiv.removeClassName('secondary');
		}

		// show default message
		this.showMessage('select-category');

	},

	removeSelected: function(selected) {
		if (selected) selected.removeClassName('selected');
	}
});


MenuSlider.Article = Class.create({
	articles: {},

	initialize: function(json, requestId) {
    
		// go through json record and parse results
		json.results.each(function(record, i) {
			if (record != null) {
				// create an id, based on the url
				var id;
				var type;
				var locale = 'en_US';
				if (record.url.indexOf('/kb/') != -1) {
					// sometimes record.url has a query like '?viewlocale=fr_FR' which should not be part of id 
					if (record.url.indexOf('?') != -1) {
						id = record.url.substring(record.url.indexOf('/kb/') + '/kb/'.length, record.url.indexOf('?'));
						// set locale of record 
						var params = record.url.toQueryParams();
						if (params.viewlocale != undefined) {
							locale = params.viewlocale;
						}
					}
					else {
						id = record.url.split('/kb/')[1];
					}
					type = "kbase";
				} 
				else if (record.url.indexOf('.html') != -1) {
					id = record.url.split('http://docs.info.apple.com/article.html?path=')[1];
					type = "help";
				}

				// build objects
				this.articles[id] = {
					title: record.title,
					url: record.url,
					excerpt: record.excerpt,
					type: type,
					locale: locale
				}
			}
		}.bind(this));
	},

	parseRecord: function(json, requestId) {
        
		// build elements from parsed content
		var parseddiv = new Element('div', { 'class':'parsed' });
		var documentid = '';
		var documenttype = '';
		var localecode = '';

		json.records.each(function(record, i) {
			record.each(function(parsed, i) {
				// skip over certain data
				var label = parsed[0];
				if (label == 'REVIEW_PRIORITY' || label == 'OLD_ARTICLE_NUMBER' || label == 'TITLE' || label == 'MASTERIDENTIFIER' || label == 'DISPLAY_PRIORITY' || label == 'REQUEST_FOR_LOCALIZATION' || label == 'LOCALIZED_GRAPHIC_NEEDED' || label == 'ADDITIONAL_AFFECTED_PRODUCT' || label == 'PRODUCT_CATEGORIES' || label == 'ARCHIVE' || label == 'LASTMODIFIED') return false;
				
				else if (label == 'DOCUMENTID') {
					documentid = parsed[1];
					documenttype = 'kbase';
					return false;
				}
				else if (label == 'PATH') {
					documentid = parsed[1];
					documenttype = 'help';
					return false;
				}
				else if (label == 'SHORT_TITLE') {
					// if overlay.update function was called with blank title, use the short title
					var overlaytitle = $('overlay').down('.title');
					if (overlaytitle != undefined && !overlaytitle.innerHTML) {
						overlaytitle.update(parsed[2]);
					}
					return false;
				}
				else if (label == 'LOCALECODE') {
					localecode = parsed[1];
					return false;
				}

				var title = parsed[1];
				if (title != 'Content') {
					var titleh3 = new Element('h3');
					titleh3.innerHTML = title;
				}

				var content = parsed[2];
				// set any links to open in new window
				content = this.customizeLinks(content);

				parseddiv.insert(titleh3);
				parseddiv.insert(content);
			}.bind(this));
		}.bind(this));
		
		// Add article source
		parseddiv.insert(this.addArticleSource(documentid, documenttype, localecode));

		// remove 'loading' class on content area
		var content = $('overlay').down('.content');
		content.removeClassName('loading');

		// insert content to overlay
		content.appendChild(parseddiv);
	},
	
	customizeLinks: function(htmlContent) { 		
		if(htmlContent) {
			var span = new Element('span').update(htmlContent);
			// parse links
			span.select('a').each(function(link) {
				var href = link.readAttribute('href');
				if (!href) {  }
				// open kbase links in overlay
				else if (href.search(/http:\/\/support.apple.com\/kb\/(HT\d{1,6}|TS\d{1,6})/) != -1) {
					var kbaseid = href.match(/http:\/\/support.apple.com\/kb\/(HT\d{1,6}|TS\d{1,6})/);
					link.writeAttribute({'onclick': 'window.overlay.update(\'' + kbaseid[1] + '\'); return false;'});
				}
				// open other links in separate window
				else {
					link.writeAttribute({'target': '_blank'});
				}
			});
			// parse images
			span.select('img').each(function(image) {
				var src = image.readAttribute('src');
				if (!src) {  }
				// make relative images absolute
				else if (src.search(/^\s*https?\:\/\//) == -1) {
					var host = 'http://km.support.apple.com';
					if (src.search(/^\s*[^\/]/) != -1) {
						host += '/';
					}
					image.writeAttribute({'src': host + src});
				}
			});
			// wrap content in <p> if needed
			if (!span.innerHTML.startsWith('<p>')) {
				span.innerHTML = '<p>' + span.innerHTML + '<'+'/p>';
			}
			return span.innerHTML;
		}
	},
	
	addArticleSource: function(documentid, documenttype, localecode) {
		if (documentid != undefined && documentid != '' && documenttype != '' && documenttype != undefined) {
			var documenturl = '';
			if (documenttype == 'kbase') { 
				documenturl = 'http://support.apple.com/kb/' + documentid;
				if (localecode != undefined && localecode != '' && localecode != 'en_US') {
					documenturl += '?viewlocale=' + localecode;
				}
			}
			else if (documenttype == 'help') { 
				documenturl = 'http://docs.info.apple.com/article.html?path=' + documentid; 
			}
			if (documenturl != '') {
				var article_source =  new Element('p').addClassName('article_source').update('Article source: <a href="' + documenturl + '" target="_blank">' + documenturl + '<'+'/a>');
				return article_source;
			}
			else { 
				return;
			}
		}
		else {
			return;
		}
	}
});

MenuSlider.Drawer = Class.create();
Object.extend(MenuSlider.Drawer.prototype, MenuSlider.prototype);
Object.extend(MenuSlider.Drawer.prototype, {
	initialize: function(categorydiv, drawer) {
		if (categorydiv.hasClassName('selected')) {
			this.closeDrawer(categorydiv, drawer);
		} else {
			this.openDrawer(categorydiv, drawer);
		}
	},
	
	openDrawer: function(categorydiv, drawer) {
		// close selected drawer first
		var selected = $('issues').down('.category.selected');
		if (selected) {
			var selectedDrawer = selected.down('.drawer');
			this.closeDrawer(selected, selectedDrawer);
		}

		// open drawer, set as selected
		categorydiv.addClassName('selected');
		var effect = new Effect.BlindDown(drawer, {duration:0.3});
	},

	closeDrawer: function(categorydiv, drawer) {
		if (!categorydiv) return false;
		categorydiv.removeClassName('selected');
		
		// unselect currently selected topic
		this.removeSelected(categorydiv.down('li.selected'));

		var effect = new Effect.BlindUp(drawer, {duration:0.3});
	},
	
	removeSelected: function(selected) {
		if (selected) selected.removeClassName('selected');
	}
});

document.observe('dom:loaded', function() {
	new MenuSlider($('issues'));
});
