jQuery(document).ready(function() {

	jQuery.each(
		jQuery('.frontpage .com-item'), function() {
			jQuery(this).height(jQuery(this).height());
		}
	);
	
	jQuery("a.thickbox").fancybox();
	
	/* Hover for featurefilm internasjonal poster */
	jQuery('.img_hover img').hover(function(){
		if(!jQuery(this).data('org_src')) {
			jQuery(this).data('org_src', jQuery(this).attr('src'));
		}
		jQuery(this).attr('src', jQuery(this).next().attr('src'));
	}, 
	function(){
		jQuery(this).attr('src', jQuery(this).data('org_src'));
	});
	
	/* Getting rights for one movie based upon country*/
	jQuery('.CountryListMovie').change(function() {
		var me = jQuery(this);
		var target = jQuery('#holder-'+me.attr('title'));
		var formfields = {
			'Country': me.val(),
			'MovieID': me.attr('title')
		};
		//loader.show('fast');
		target.fadeOut('fast', function() {
			target.addClass('holder-filled');
			jQuery.ajax({
				  type: 'post', 
				  url: '/rights/film_by_country/pdx',
				  data: formfields,
				  success: function (data) {
					//target.hide();
					target.html(data).fadeIn('slow');
				} 
			});
		});
		
	});
	var loader = jQuery('#loader');
	jQuery('.MovieListCountry').change(function() {
		var me = jQuery(this);
		var formfields = {
			'Country': me.val()
		};
		var target = jQuery(me.attr('title'));
		loader.fadeIn('fast', function() {
			jQuery.ajax({
				  type: 'post', 
				  url: '/pdx/rights/film_list_by_country/pdx',
				  data: formfields,
				  success: function(data) {
					target.hide('fast', function() {
						loader.fadeOut('fast', function(){
							target.html(data).slideDown();
						});
					});
					
				}
				});
		})
		
		
	});	
});
function relative_time(time_value) {
    var parsed_date = Date.parse(time_value);
    var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
    var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
    var pluralize = function (singular, n) {
      return '' + n + ' ' + singular + (n == 1 ? '' : 's');
    };
    if(delta < 60) {
    return 'less than a minute ago';
    } else if(delta < (45*60)) {
    return 'about ' + pluralize("minute", parseInt(delta / 60)) + ' ago';
    } else if(delta < (24*60*60)) {
    return 'about ' + pluralize("hour", parseInt(delta / 3600)) + ' ago';
    } else {
    return 'about ' + pluralize("day", parseInt(delta / 86400)) + ' ago';
    }
  }

