wpRed = {

	isLoggedIn: 0,

	submitComment: function(postID){

		var comment = document.getElementById('commentMessage');

		$.post(
			"wp-comments-post.php",
			{
				comment: comment.value,
				comment_post_ID: postID,
				no_redirect: 1

			},
			function(data){
				if (data == 'ok'){
					comment.value = '';
					RCJS.page('','',0,'Loading');
					wpRed.showCommentForm(false);
				}else{
					alert('Error, please try again.');
				}
			}

		);

	},

	showCommentForm: function(show){
		var c = document.getElementById('newComment');
		if (show){
			c.style.display = 'block';
		}else{
			c.style.display = 'none';
		}
	},

	isLoggedIn: function(){
		return true;
	},

	showLoginRegisterForm: function(show){
		var loginDiv = document.getElementById('loginRegister');
		//var ifr = document.getElementById('loginRegisterIframe');
		//ifr.src = 'wp-login.php?wpRed=true';

		if (show){
			loginDiv.style.display = 'block';
		}else{
			loginDiv.style.display = 'none';
		}
	},

	doLogOut: function(){
		var ifr = document.getElementById('loginRegisterIframe');
		ifr.src = 'wp-login.php?wpRed=true&action=logout';
		this.showLoginRegisterForm(true);
	},

	handleLoginLogout: function(mode){
		if (mode == 'loggedin'){
			this.showLoginRegisterForm(false);
			this.isLoggedIn = true;
			window.location='/';
		}else if (mode == 'loggedout'){
			this.showLoginRegisterForm(false);
			this.isLoggedIn = false;
			window.location='/';
		}
	},

	showProfileEditor: function(show){
		var d = document.getElementById('profileWrapper');
		if (!d) return;
		if (show){
			d.style.display = 'block';
		}else{
			d.style.display = 'none';
		}
	},

	showEmailForm: function(show){
		var d = document.getElementById('emailForm');
		if (!d) return;
		if (show){
			d.style.display = 'block';
		}else{
			d.style.display = 'none';
		}
	},

	changeLocale: function(loc){
		var bg = 'bg.jpg';
		switch (loc){
			case 'it':
				bg = 'bg_it.jpg';
				break;
			case 'ch':
				bg = 'bg_ch.jpg';
				break;
			default:
				bg = 'bg.jpg';
		}
		//console.log(bg);
		var b = document.getElementById('contentWrapper');
		b.style.background = 'url(images/' + bg + ')';

	},
	
	loadEpisode: function(episodeNum){
		var videoWidth = '460';
		var videoHeight = '295';
		var episodeName = 'episode' + episodeNum;
		var v = document.getElementById('videoArea');
		var videoCode = '<object width="' + videoWidth + '" height="' + videoHeight + '" wmode="transparent">';
		videoCode += '<param name="movie" value="' + episodeVideo[episodeName] + '"></param>';
		videoCode += '<param name="allowFullScreen" value="true"></param>';
		videoCode += '<param name="allowscriptaccess" value="always"></param>';
		videoCode += '<embed src="' + episodeVideo[episodeName] + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + videoWidth + '" height="' + videoHeight + '" wmode="transparent"></embed>';
		videoCode += '</object>';
		v.innerHTML = videoCode;
		
		var images = document.getElementById('images');
		images.innerHTML = '';
		var imgHTML = '<ul id="imagesUL">';
		for (var i = 2; i <= 7; i++){
			imgHTML += '<li><a class="thickbox" href="images/' + episodeName + '/' + i + '.jpg"><img border="0" src="images/' + episodeName + '/' + i + '_t.jpg" onmouseover="this.src=\'images/' + episodeName + '/' + i + '_tm.jpg\';" onmouseout="this.src=\'images/' + episodeName + '/' + i + '_t.jpg\';" /></a></li>';
		}
		imgHTML += '</ul>';

		images.innerHTML = imgHTML;
		
		tb_init('a.thickbox, area.thickbox, input.thickbox');

	},

	scrollToEmailForm: function(show){
		window.scroll(0,0);
		this.showEmailForm(true);
	}

}
