var global_url = '/status.php'; var global_seconds = 10; var global_users = { 'girlfriendxp1': { name: 'girlfriendxp1', img: 'dude2.png'},'girlfriendxp2': { name: 'girlfriendxp2', img: 'girl2.png'},'girlfriendxp3': { name: 'girlfriendxp3', img: 'girl1.png'},'girlfriendxp4': { name: 'girlfriendxp4', img: 'dude1.png'} } $( document ).ready( start_me_up ); function start_me_up() { all_status(); setInterval( all_status, global_seconds * 1000 ); $("img").click(characterclick); $("a.avatar").href("#"); } function all_status() { for ( var i in global_users ) { get_status( i ); } } function get_status( i ) { var params = global_users[i]; jQuery.get( global_url, params, function ( status ) { got_status( i, status ); } ); } function got_status( i, status ) { $( '#status_' + i ).html( status ); $( '#imgstatus_' + i).src('images/avatars_' + (status == 'free' ? 'a' : 'u') + '/' + global_users[i].img); global_users[i].status = status; } function characterclick(){ var i = $(this).id().split('_')[1]; //alert("i: " + i); jQuery.get(global_url, global_users[i], function (status){ got_status_clicked(i, status) } ); } function got_status_clicked(i, status){ if (status != global_users[i].status) // Status changed.. if (!do_handle_status_changed(global_users[i].status, status)) return; // Handle normally from here. got_status(i, status); // Handle the click. var status = global_users[i].status; if (status == "free") do_open_skype(i); else if (status == "busy") alert("This person is already busy"); else if (status == "offline") alert("This person is currently not online.\n\nPlease go to http://girlfriend.mediamatic.net/ for the schedule."); } function do_handle_status_changed(oldstatus, newstatus){ if (newstatus == "free") return 1; if (oldstatus == "free") if (newstatus == "busy") alert("Unfortunately, this person is already busy (someone else was faster)."); else if (newstatus == "offline") alert("Unfortunately, this person has gone offline.\n\nOpening hours are:\nWednesday through Friday, from 10 in the morning to 7 in the evening."); return 0; } function do_open_skype(name){ //alert("Pretending to open skype and call " + name); document.location = "skype:" + name; //, "skypewindow", "alwaysLowered=true,height=1,width=1,location=false,menubar=false,scrollbars=false,status=false"); }