$(function() {
	$('select#page').change(function() {
		var page_number = $(this).val();
		
		querystring = $.param({
			cid: G_cid,
			sessionid: G_sessionid,
			rows: G_rows,
			cols: G_cols,
			page: page_number
		})
		window.location = '/embed/?' + querystring;
	});

	$('select#date').change(function() {
		var datestring = $('select#date').val();
		
		querystring = $.param({
			cid: G_cid,
			sessionid: datestring,
			rows: G_rows,
			cols: G_cols,
			page: 1
		})
		window.location = '/embed/?' + querystring;
	});
	
	$('a.images').colorbox({
		rel: 'images',
		maxWidth: 800,
		maxHeight: 610,
		photo: true,
		opacity: 0.6,
		loop: false,
		onOpen: function () {
			$('#colorbox').append("<div class='buybox'><div><img src='http://www.picture-pal.co.uk/images/buy.jpg' /></div></div>");	
		}
	});
	
	$(document).delegate('div.buybox', 'click', function() {
		$('div.buybox').hide();
		
		element = $.colorbox.element();
		id = element.find('img').data('id');
		
		$.ajax({
			url: '/ajax/gallery/embed/',
			data: {id: id},
			dataType: 'json',
			type: 'post',
			success: function(data) {
				$.colorbox({
					html: data.html
				});
				$('#cboxLoadedContent').addClass('buy');
			}
		});
	});
});

