/********
NOTE: CHANGES TO THIS FILE WILL AFFECT THIS SMS SITE AND OTHERS.
This determines the scripted behavior for the entire class. Do not change this file unless
you know that you want these changes to be reflected across this entire SMS site
and every other SMS site that uses this class.
These behaviors can be overridden in your template's javascript files.
********/

$(document).ready(function(){
	$(".embed")
		.children("label[for$=_embed], input[name$=_embed]")
			.click(function(){
				$(this).next("input[name$=_embed]").andSelf().select();
			})
			.end()
		.children("form")
			.children(".button").hide().end()
			.children("select")
				.change(function(){
					var selVideoEmbed = $(this).val(), embed = $(this).parent().prev("input"), embed_code = embed.val();
	
					embed_code = embed_code.replace(/width="\w+"/g, "width=\"" + selVideoEmbed.split("x")[0] + "\"");
					embed_code = embed_code.replace(/height="\w+"/g, "height=\"" + selVideoEmbed.split("x")[1] + "\"");
					
					embed.val(embed_code);
				});
	
	$(".ratingBlock")
		.find(".star")
			.click(function(){
				var that = $(this), form = that.parents('form'), videolibraryid = form.find('[name=hidVideoLibraryId]').val();

				$.post(
					"/classlibrary/com/videolibrary/Public.cfc?method=ajaxVideoRating&returnFormat=plain",
					$('#frmVideoRating_' + videolibraryid).serialize(),
					function (d, s, x) {
						if (d.substr(0,4) === "true") {
							form.siblings('.hide').removeClass('hide');
						} else {
							form.siblings('.hide').text('There was a problem.').removeClass('hide');
						}
					});
			});
});

