var rateajaxpage = 'addchannelrating.php';
var ratingitem = 'channel';

function toggleads() {
	//$("#showads").slideToggle("slow");
	$("#hideads").slideToggle("slow");
	$(".ad").slideToggle("slow");
	$(".boxcontainer").animate({height: "785px"}, 500);
}

var type = 'channel';

function updateembedsize(changed) {
	if (changed == 'width') $("#height").val(Math.round($("#width").val() / aspectratio));
	if (changed == 'height') $("#width").val(Math.round($("#height").val() * aspectratio));
	
	var width = Number($("#width").val());
	var height = Number($("#height").val());
	
	$("#embedtext").val("<iframe style='overflow: hidden; border: 0; width: " + width + "px; height: " + (height + 56) + "px' src='http://stagevu.com/embed?width=" + width + "&amp;height=" + height + "&amp;uid=" + videouid + "' scrolling='no'></iframe>");
}

var curplaying = '';

// Override of updateuserstatus in divxplayer.js
function updateuserstatus(playerid) {
	var uid = parseuid(url[playerid]);
	$.get(webpath + '/ajax/status.php', {action: 'viewchannel', uid: uid, chanid: objectid}, done, 'json');
	lastreport[playerid] = new Date().getTime();
}

function toggleads() {
	$("#hideads").slideToggle("slow");
	$("#topad").slideToggle("slow");
	$(".ad").slideToggle("slow");
	$("#related").css('margin-top', 0);
	$("#related").animate({height: "830px"}, 500);
	$(".boxcontainer").animate({height: "785px"}, 500);
}

function getlink(videouid, boxid) {
	if (curplaying == videouid) location.href = webpath + '/video/' + videouid;
	curplaying = videouid;
	function done(data) {
		if (data.success === true) {
			var plugin = divxplayer(1);
			var arr = data.text.split(',');
			url[1] = arr[0];
			var width = arr[1];
			var height = arr[2];
			plugin.Open(url[1]);
			plugin.Resize(640, Math.round(height / width * 640) + 26);
			$("#object1, #embed1, #cont1").width(640).height(Math.round(height / width * 640) + 26);
			aspectratio = width / height;
			updateembedsize(width);
			notice(data.message, '#090');
		} else {
			notice(data.message, '#900');
		}
		loading();
	}
	loading();
	$('.boxes1, .boxes2').removeClass('selectedbox');
	$("#box" + boxid).addClass('selectedbox');
	$.post(webpath + "/ajax/getsymlink.php", {uid: videouid, time: time, str: hashstr}, done, "json");
}

function subscribe() {
	function done(data) {
		if (data.message.length > 0) {
			if (data.success === true) {
				notice(data.message, '#090');
			} else {
				notice(data.message, '#900');
			}
		}
		loading();
	}
	loading();
	$.post(webpath + "/ajax/subscribe.php", {chanid: objectid}, done, "json");
}

$(document).ready(function() {
	$('.boxes1:first').addClass('selectedbox');
	
	checkformlen("comment", maxcommentlen);
	
	$('#commentform').ajaxForm({
		beforeSubmit: function() { return checkform('comment', maxcommentlen); },
		dataType: 'json',
		success: addcomment
	});
	
	updateembedsize('width');
});

