var ContentSwitcher = $.inherit(
	{
		__constructor: function(options){

			options = $.extend({}, this.self.selectors, options);

			this.switchType = options.switchType;

			this.jContent = $(options.content);
			this.jSwitcher = $(options.switcher);

			this.jShortContent = $(options.shortContent);
			this.jFullContent = $(options.fullContent);

			this.jAdditionalContent = $(options.additionalContent);
			
			if ("onhashchange" in window) {
				window.onhashchange = this.initHide.scope(this);
			}
			
		},

		init: function(){
			this.initHide();
			this.jSwitcher.click(this.switchContent.scope(this));
		},

		initHide: function(){
			if(this.jFullContent.length && this.jShortContent.length) {
				this.sSavedState = "#" + $.cookie(this.self.cookieName);
				
				if (window.location.hash == "#full" || window.location.hash == "#short") {
					this.sSavedState = window.location.hash;
				}
				
				if (this.sSavedState == "#full") {
					this.jFullContent.show();
					this.jShortContent.hide();
					this.jSwitcher.addClass("full");
				} else {
					this.jShortContent.show();
					this.jFullContent.hide();
					this.jSwitcher.removeClass("full");
					
					this.sSavedState = "#short"
				}
				
				$(document.documentElement).removeClass("content-state_short content-state_full");
				
				this.setHash();
				//disable repeated hash setting on cached page (if user hits back button)
				$('<iframe></iframe>').attr('src','/_back.html').css({'display':'none'}).appendTo('body');
			}
		},
		
		setHash: function(){
			if(window.location.hash != "#sitemap")
				this.setLocationHash(this.sSavedState);
		},
		
		setLocationHash: function(sHash){
			if (sHash.charAt(0) != "#") {
				sHash = "#" + sHash;
			}
			
			window.location.replace(window.location.href.replace(/#.*/, '') + sHash);
		},

		switchContent: function(){
			switch(this.switchType){
				/**
				 * один блок скрывается, второй показывается
				 */
				case "containers-toggle":
					this.toggleContainers();
					break;
				/**
				 * по-умолчанию: блок с дополнительным контентом выезжает и заезжает
				 */
				default: this.slideContent();
			}

			this.jSwitcher.toggleClass("full");
		},

		toggleContainers: function(){
			this.jShortContent.toggle();
			this.jFullContent.toggle();
			
			var sLocation = window.location.href.replace(/#.*/, '');

			//FIXME: this is just for convenience now. (dims)
			if (window.location.hash != "#full") {
				this.setLocationHash("#full");
				$.cookie(this.self.cookieName, "full", { path: '/', expires: 30 });
			} else {
				this.setLocationHash("#short");
				$.cookie(this.self.cookieName, "short", { path: '/', expires: 30 });
			}
		},

		slideContent: function(){
			this.jAdditionalContent.slideToggle(500);
		}
	},
	{
		selectors: {
			content: "#content",
			switcher: "#content-switcher, .switch-to-full, .switch-to-short",
			additionalContent: ".additional-content",
			shortContent: ".short-content",
			fullContent: ".full-content"
		},
		collapsedClass: "collapsed-content",
		cookieName: "content_state"
	}
);
