var pops = new Array();
var toggle = 0;
var p = 0;
var currentImage = 1;
var iArray = new Array();
var nextImage = 0;
var toId = 0;

function submitComment(f) {
	var episode_id = $("#episode_id").val();
	var comment = $("#comment").val();
	var commenttype = $("#commenttype").val();
	var r = $.ajax( {
		'type' : 'POST',
		'url'  : '/ajax/submitcomment' ,
		'data' : { 'episode_id': episode_id , 'comment' : comment  , 'type' : commenttype },
		'dataType' : 'json',
		'async' : false,
		'success' : function(msg) {
			if (msg.success == 1) {
				$("#cbox").html(msg.output);
				addComment(msg.data);
			}
			else {
				$("#cError").html(msg.output);
			}
		}
	});
	return false;
}

function addComment(data) {
	var newC = jQuery(document.createElement('li'));
	newC.html(data);
	newC.css( { 'display' : 'none' } );
	$("#cList").prepend(newC);
	newC.slideDown('slow');
}

function submitRating() {
	var e = $("#e").val();
	var v = $("#v").val();
	var t = $("#t").val();
	var r = $.ajax( {
		'type' : 'POST',
		'url'  : '/ajax/submitrating' ,
		'data' : { 'episode_id': e , 'value' : v  , 'type' : t },
		'dataType' : 'json',
		'async' : false,
		'success' : function(msg) {
			$("#rating").html(msg.output);
		}
	});
	return false;
}
function saveRatingOld() {
	var e = $("#e").val();
	var v = $("#v").val();
	var t = $("#t").val();
	var r = $.ajax( {
		'type' : 'POST',
		'url'  : '/ajax/saverating' ,
		'data' : { 'episode_id': e , 'value' : v  , 'type' : t },
		'dataType' : 'json',
		'async' : false,
		'success' : function(msg) {
			$("#rate_data").html(msg.newRating / 10);
			$("#rating").html(msg.output);
			$("#amount").css({
				"color" : 'green'
				});
			$("#r").html('saved');
			$("#r").css({
				"color": 'green'
				});
		}
	});
	return false;
}
function saveRating(e , t , v) {
	var r = $.ajax( {
		'type' : 'POST',
		'url'  : '/ajax/saverating' ,
		'data' : { 'episode_id': e , 'value' : v  , 'type' : t },
		'dataType' : 'json',
		'async' : false,
		'success' : function(msg) {
			if (msg.success == 1) {
			$("#rate_data").html(msg.newRating / 10);
			$("#rcount").html(msg.votes + ' ratings');
			$("#ratetext").html('saved');
			$("#ratetext,#amount").css({
				"color": 'green'
				});
			$("#ratetext").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);
			}
			else {
				caption = "Login to Rate";
				imageGroup = "";
				tb_show(caption, '/ajax/login?width=660&height=200', imageGroup)
			}
		}
	});
	return false;
}

function doaction ( inParams ) {
	var u;
	switch(inParams.action) {
		case 'addfavorite':
			u = '/ajax/addfavorite/' + inParams.type + '/' + inParams.episode_id;
			break;
	}
	var r = $.ajax({
		'type' : 'GET',
		'url'  : u,
		'dataType' : 'html',
		'async' : false,
		'success' : function(msg) {
				$("#loginContainer").html(msg);
			}
		});
}


function doLogin(loginForm) {
	var u = $("#username").val();
	var p = $("#password").val();
	var e = $("#episode_id").val();
	var t = $("#type").val();
	var a = $("#action").val();
	var r = $.ajax( {
		'type' : 'POST',
		'url'  : '/login/ajax' ,
		'data' : { 'username': u , 'password' : p  , 'episode_id' : e , 'type' : t , 'action' : a},
		'dataType' : 'json',
		'async' : false,
		'success' : function(msg) {
			if (!msg.success) {
				$("#errors").html(msg.notvalid);
				$("#errors").slideDown('slow');
				$("#errors").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);
			}
			else {
				showSuccess(msg);
			}
		}
	});
	return false;
}

function showSuccess(msg) {
	window.location.href = window.location.href;
	return false;
}

$(document).ready(function() {
	/* $("#categories .cat-item a").cluetip({splitTitle: '|'}); */

	$("#b").click(function() {
		if (toggle == 1) {
			$("#b").fadeOut('slow');
			for (i = 0 ; i < pops.length ; i++) {
				$("#" + pops[i]).fadeOut('slow');
			}
			toggle = 0;
		}
	});
});


/* motm stuff */


$(document).ready(function(){

//Larger thumbnail preview 

$("#motm ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'});
	$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '-113px', 
			marginLeft: '-113px', 
			top: '50%', 
			left: '50%', 
			width: '200px', 
			height: '300px',
			padding: '20px' 
		}, 200);
	
	} , function() {
	$(this).css({'z-index' : '0'});
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '113px', 
			height: '170px', 
			padding: '5px'
		}, 400);
});

//Swap Image on Click
/*
	$("#motm ul.thumb li a").click(function() {
		var mainImage = $(this).attr("href"); //Find Image Name
		alert('');
		$("#main_view img").attr({ src: mainImage });
		modelid = $(this).attr('id');
		modelUrl = '/models/view/' + modelid;
		$("#modellink").attr( { 'href' : modelUrl } );
		
		return false;		
	});
*/
});


/* end motm stuff */

