// JavaScript Document // This script requires the jquery library to run var speakerList = "http://www.gov2summit.com/public/content/report/speakers_xml"; $(document).ready(function () { var itemsToLoad = new Array(); var priorityArray = new Array(); var perSet = 4; var curSet = 0; var setShowing = 0; var sliding = false; //Load the speakers $.ajax({ type: "GET", url: speakerList, dataType: "xml", success: loadSet }); function loadSet(xml) { $(xml).find('speaker').each(function(i) { itemsToLoad[i] = new Array(); itemsToLoad[i][0] = $(this).attr('firstname'); itemsToLoad[i][1] = $(this).attr('lastname'); itemsToLoad[i][2] = $(this).attr('org'); itemsToLoad[i][3] = $(this).attr('img'); itemsToLoad[i][4] = $(this).attr('url'); itemsToLoad[i][5] = $(this).attr('priority'); itemsToLoad[i][6] = false; //Set to true when the image is loaded }); //Put the priority speakers in a separate array for (var i = 0; i < itemsToLoad.length; i++) { if (itemsToLoad[i][5] == 'true') { priorityArray = priorityArray.concat(itemsToLoad.splice(i, 1)); i --; } } priorityArray.sort(function randOrd(){return (Math.round(Math.random())-0.5); }); //randomize the priority array itemsToLoad.sort(function randOrd(){return (Math.round(Math.random())-0.5); }); //randomize the items array itemsToLoad = priorityArray.concat(itemsToLoad); //add the two arrays back together //Calculate the number of speaker sets var numSets = Math.ceil(itemsToLoad.length / perSet); //Create and display the container for the speaker sets if (numSets > 0) { var speakerRow = ''; speakerRow += '
'; speakerRow += ''; $('#speaker_photos').append(speakerRow); } //Make room for the speakers $("#en_main").find("h1").each(function(i) { if (i == 0) { $(this).css("paddingTop", "85px"); } }); //Create and display the containers for each speaker for (var i = 0; i < itemsToLoad.length; i++) { if (i % perSet == 0) { curSet = Math.ceil(i / perSet); var speakerSet = $('
'); $(speakerSet).css('left', curSet * 348); $('#speaker_row').append(speakerSet); } var speaker = $('
'); $('#speaker_set' + curSet).append(speaker); } //Load the first set of speaker photos loadImage(0, perSet); $('#speaker_photos > .right_btn > a').css('opacity', 0.8).hover(function() { $(this).stop(true, false); $(this).fadeTo(150, 1); }, function() { $(this).stop(true, false); $(this).fadeTo(150, .8); }).click(function(e) { e.preventDefault(); if (!sliding) { slideRight(e); } }); $('#speaker_photos > .left_btn > a').css('opacity', 0.8).hover(function() { $(this).stop(true, false); $(this).fadeTo(150, 1); }, function() { $(this).stop(true, false); $(this).fadeTo(150, .8); }).click(function(e) { e.preventDefault(); if (!sliding) { slideLeft(e); } }); } function slideRight(btn) { if (!sliding) { sliding = true; $('#speaker_set' + setShowing).animate({left: -348}, 500, 'swing'); if (setShowing < Math.ceil(itemsToLoad.length / perSet) - 1) { setShowing ++; } else { setShowing = 0; } $('#speaker_set' + setShowing).css('left', 348); $('#speaker_set' + setShowing).animate({left: 0}, 500, 'swing', function() { sliding = false; }); loadImage(setShowing * perSet, setShowing * perSet + perSet); } } function slideLeft(btn) { if (!sliding) { sliding = true; $('#speaker_set' + setShowing).animate({left: 348}, 500, 'swing'); if (setShowing == 0) { setShowing = Math.ceil(itemsToLoad.length / perSet) - 1; } else { setShowing --; } $('#speaker_set' + setShowing).css('left', -348); $('#speaker_set' + setShowing).animate({left: 0}, 500, 'swing', function() { sliding = false; }); loadImage(setShowing * perSet, setShowing * perSet + perSet); } } function loadImage(curImage, lastImage) { if (curImage < lastImage) { if (itemsToLoad[curImage] != undefined) { if (itemsToLoad[curImage][6] == false) { var img = new Image(); //image onload $(img).load(function() { $(this).css('display', 'none'); var aBlock = $('').attr('href', itemsToLoad[curImage][4]); var sBlock = $('').attr('class', 'photo'); $('#speaker' + curImage).append(aBlock); $('#speaker' + curImage + '> a').append(sBlock); $('#speaker' + curImage + '> a > .photo').append(this); $('#speaker' + curImage + '> a').append("" + itemsToLoad[curImage][0] + " " + itemsToLoad[curImage][1] + "
" + itemsToLoad[curImage][2]); $(this).show(); itemsToLoad[curImage][6] = true; $('#speaker' + curImage + '> a').hover(function() { $(this).find('img').stop(true, false); $(this).find('img').fadeTo(200, .85); }, function() { $(this).find('img').stop(true, false); $(this).find('img').fadeTo(200, 1); }) // once the current loaded, trigger the next image loadImage(curImage + 1, lastImage); }).error(function () { // on error remove current $('#speaker' + curImage).remove(); itemsToLoad[curImage][6] = true; // trigger the next image loadImage(curImage + 1, lastImage); }).attr({ src: itemsToLoad[curImage][3], alt: itemsToLoad[curImage][0] + " " + itemsToLoad[curImage][1] }); } else { loadImage(curImage + 1, lastImage); } } } } });