var ContentChanger = Class.create();
ContentChanger.prototype = {
    contentWindow: null,
    currentSelected: null,
	siteName: null,
	transitioning: null,
	loading: null,
	ajax: null,
    
    initialize: function(contentWindow, baseSiteName){
        this.contentWindow = 'contentWindow';
		ContentChanger.prototype.siteName = baseSiteName;
		this.changing = false;
    },
    
    change: function(newContent, queryString){
		if(this.loading) {
			setTimeout(function(){this.change(newContent, queryString)}.bind(this), 2000);
			return;
		} 

		this.loading = true;
        new Effect.Opacity(this.contentWindow, {
            duration: 0.1,
            transition: Effect.Transitions.linear,
            from: 1.0,
            to: 0.0
        });
		
		if(queryString == null) {
			queryString = this.examine("?");
		}
		
		setTimeout(function(){
	    	this.ajax = new Ajax.Updater(this.contentWindow, '/content/' + newContent + ".php?" + queryString, {
	            evalScripts: true,
	            onComplete: function(){
	                if (this.currentSelected) {
	                    this.currentSelected.removeClassName('selected');
	                } else {
						$('blog').removeClassName('selected');
					}
	                this.currentSelected = $(newContent);
	                if (this.currentSelected) {
	                    this.currentSelected.addClassName("selected");
	                }
					this.loading = false;
					this._showContent();
	            }.bind(this)
	        });
		}.bind(this), 100)
    },
	
	_showContent: function() {
		new Effect.Appear('contentWindow', {
			from: 0.0,
			to: 1.0,
			duration: 2.0
		});
	},
	
	changeTitle: function(newTitle) {
		document.title = ContentChanger.prototype.siteName + " | " + newTitle;
	},
	
	examine: function(character) {
		if (character == null) {
			character = '#';
		}
		var anchorPieces = document.location.href.split(character);
		if(anchorPieces.length > 1) {
			return anchorPieces[1];
		} else {
			return null;
		}
	}
}


