$(document).ready(function() {
var timer, tittel, filmData = $("#filmdata");
var title;
var runtime;
$('#tittel').on('keyup', function() {
if (this.value==tittel) { return false; }
tittel=this.value;
clearTimeout(timer);
timer = setTimeout(function() {
$.ajax({
type: 'GET',
beforeSend: function () {
$('#error').empty();
if (!filmData.is(':visible')) {
filmData.slideDown(400);
}
else {
$("#loader").show();
$('.result').empty();
$("#poster").hide();
}
},
url: 'http://www.imdbapi.com/?t='+tittel
})
.done(function(data) {
data = $.parseJSON(data);
var cats = filmData.children('li');
title = data.Title;
runtime = data.Runtime;
$('.result', cats.eq(1)).text(data.Title);
$('.result', cats.eq(2)).text(data.Runtime);
$('.result', cats.eq(3)).text(data.imdbRating);
$('.result', cats.eq(4)).text(data.Genre);
$('.result', cats.eq(5)).text(data.Actors);
$('.result', cats.eq(6)).text(data.Released);
$('.result', cats.eq(7)).text(data.Director);
$('.result', cats.eq(8)).text(data.Writer);
$('.result', cats.eq(9)).text(data.Plot);
$('.result', cats.eq(10)).html('<a href="http://www.imdb.com/title/'+data.imdbID+'">Link til IMDB</a>');
$.getJSON("http://api.themoviedb.org/2.1/Movie.search/en/json/23afca60ebf72f8d88cdcae2c4f31866/ " + data.Title + "?callback=?", function(json) {
if (json != "Nothing found.") {
$('#poster').prop('src', json[0].posters[0].image.url).show();
$("#loader").hide();
}
else {
cats.eq(0).find('img').hide();
$("#loader").hide();
}
});
})
.fail(function() {
$("#filmdata").slideUp(400);
$('#error').append('<br><br>Det oppsto en feil !');
});
}, 700);
});
$("form#submit").submit(function() {
var post = "done";
$.ajax({
type: "POST",
url: "/customers/rajohan.net/rajohan.net/httpd.www/test2.php",
data: "post="+post+"&title="+title+"&runtime="+runtime,
success: function(){
$('div.succses').show();
}
});
return false;
});
});