$(function(){

$(window).bind('resize', function(){
	setSidebarContentHeight();
});
setSidebarContentHeight();
function setSidebarContentHeight(){
	var newHeight = $(window).height() - $('header').height() - $('footer').height();
	$(".sidebar .content").css('height', newHeight);
}

$(".sidebar .content").mCustomScrollbar({
	advanced:{
	    updateOnContentResize: true
	}
});

$('a.more').bind('click', function(e){
	e.preventDefault();
	var target = $(this).attr('href');
	if($(target).hasClass('less')){
		$(target).removeClass('less');
		$(this).addClass('less');
	}else{
		$(target).addClass('less');
		$(this).removeClass('less');
	}	
});// a.more



//-- API allocine

//-- movie
var urlMovie = 'http://api.allocine.fr/rest/v3/movie?partner=B00015838755&code='+ idMovie;
$.getJSON(urlMovie, function(data) {
	var movie = data.movie;

	//-- title
	var titleMovie = movie.title;
	$('.renkan .wrap-top h2').text(titleMovie);

	//-- stars
	var castMember = movie.castMember;

	$.each(castMember, function(k, v){
		var name =	v.person.name;
		var codeActor = v.person.code;
		var urlPicture;
		if(v.picture !== undefined) {
			urlPicture = v.picture.href;
		}else{
			urlPicture = 'http://fr.web.img3.acsta.net/c_160_213/b_1_d6d6d6/commons/emptymedia/empty_star.jpg';
		}	
		var urlFichePersonne = 'http://www.allocine.fr/personne/fichepersonne_gen_cpersonne='+codeActor+'.html';
		var itemStar = 
			'<li><a target="_blank" href="'+ urlFichePersonne +'" title="'+ name +'">'+
				'<img src="'+ urlPicture +'" alt="'+ name +'" />'+
			'</a></li>';
		$('#stars-more').append(itemStar);
	});	

	/* Initializing Renkan */
	
	setRenkanPoster({
		title: movie.title,
		image: movie.poster.href,
		uri: _(movie.link).find(function(l) { return l.rel === "aco:web" }).href
	});


});

//-- picture
var urlPicture = 'http://api.allocine.fr/rest/v3/picturelist?partner=B00015838755&subject=movie:135082';
$.getJSON(urlPicture, function(data) {
	var media = data.feed.media;
	$.each(media, function(k, v){
		var urlThumb = v.thumbnail.href;
		var itemImagess = 
			'<li>'+
				'<img src="'+ urlThumb +'" alt="" />'+
			'</li>';
		$('#images-more').append(itemImagess);
	});
});

});