$(function() {
  $('.ui-link-button').button();
  $('a[href^="/movie"]').each(function() {
   	var id = $(this).attr('href').match(/\/([0-9]+)/);
	$(this).qtip({
		content: {
			text: "Loading movie information ..",
			ajax: {
				url: "/ajax/movietooltip.php",
				data: { movieid: id[1]},
				success: function(data) {
						this.set('content.text', data);
						return false;
					}
			},
			
		},
		
		position: {
			my: "bottom center",
			at: "top center"
		},
		show: {
			effect: "fade"
		},
		hide: {
			effect: "fade"
		},
		style: {
			tip: true,
			classes: "ui-tooltip-custom ui-tooltip-shadow"
		}
	}
	);
	 }); 
});

function OpenTrailer(movieid) {
	$('<div />').dialog({
		title: 'Viewing trailer!',
		bgiframe: true, 
		modal: true,
		resizable: false,
		width: 700,
		position: ['center',100],
		draggable: false,
		buttons: {}
	}).load('/ajax/loadtrailer.php?movieid='+ movieid);
}

function SaveRating(movieid, rating) {
	$.get('/ajax/saverating.php', {movieid: movieid, rating: rating});
	$('#giverating'+ movieid).hide();
/*	$('<div />').dialog({
		title: 'Thanks for rating!',
		bgiframe: true,
		modal: true,
		resizable: false,
		width: 512,
		position: ['center',200],
		draggable: false,
		buttons: {
			'Close': function() {
				$(this).dialog('close');
				}
		}
	}).load('/ajax/justrated.php?movieid='+ movieid +'&rating='+ rating);
*/
}

function SaveEditRating(movieid, rating) {
        $.get('/ajax/saveeditrating.php', {movieid: movieid, rating: rating});
}

function EditRating(movieid) {
	$('<div />').dialog({
		title: 'Edit your rating',
		bgiframe: true,
		modal: true,
		resizable: false,
		width: 512,
		position: ['center',200],
		draggable: false,
		buttons: {
			'Cancel': function() {
				$(this).dialog('close');
				}
		}
	}).load('/ui/editrating.php?movieid='+ movieid);
}

function DrawStars(total, count, callback) {
	
}

function ClearRating(movieid) {
	$.get('/ajax/clearrating.php', {movieid: movieid});
	$('#giverating'+ movieid).show();
	$('#myrating'+ movieid).hide();
	return false;
}

function ClearMeta(movieid) {
        $.get('/ajax/clearmeta.php', {movieid: movieid});
	return false;
}


function WantToSee(movieid) {
	$.get('/ajax/savemeta.php', {movieid: movieid, meta: 'wanttosee'});
	$('#metabar'+ movieid).hide();
	return false;
}

function DontRemember(movieid) {
	$.get('/ajax/savemeta.php', {movieid: movieid, meta: 'dontremember'});
	$('#metabar'+ movieid).hide();
	return false;
}

function NotInterested(movieid) {
	$.get('/ajax/savemeta.php', {movieid: movieid, meta: 'notinterested'});
	$('#metabar'+ movieid).hide();
	return false;
}

