jQuery(function(){ if ($('#carousel').length){ new isdr.Carousel(); } isdr.searchBox(); isdr.printTracking(); isdr.sharingTools(); isdr.privateSectorTooltips(); $('tr:odd').addClass('odd'); $('select.isdr-live-filter').live('change', function(){ var params = {p:0}; params[$(this).attr('name')] = $(this).val(); isdr.ajaxUpdate(isdr.updateQueryParams(params)); }); // when you press back in FF it doesn't return to original values $('select.isdr-live-filter').each(function(){ var val = $(this).find('option:selected').val(); if (val != null) $(this).val(val); else this.selectedIndex = 0; }); $('#main-menu > li').mouseenter(function(){ var div = $(this).children('div'); var showTimeout = setTimeout(function(){ div.css('display', 'block'); setTimeout(function(){ div.addClass('show') }, 10); }, 100); $(this).data('showTimeout', showTimeout); }).mouseleave(function(){ clearTimeout($(this).data('showTimeout')); $(this).children('div').css('display', 'none').removeClass('show'); }); }); var isdr = { getQueryParams: function(){ var pairs = window.location.search.slice(1).split('&'), d = function(s){ return decodeURIComponent(s.replace(/\+/g, " "));}, params = {}; for(var i = 0; i < pairs.length; i++) { var pair = pairs[i].split('='); params[d(pair[0])] = d(pair[1]); } return params; }, getQueryStr: function(){ return this._queryStr || window.location.search; }, setQueryStr: function(str){ str = str.replace(/[^?]*/, ''); this._queryStr = str; }, updateQueryParams: function(params){ var q = this.getQueryStr(), key, e = encodeURIComponent, r = function(m, p1){ return p1 + e(params[key]); }; for (var key in params){ var re = new RegExp('([?&]'+key+'=)[^&]*'); if (re.test(q)) q = q.replace(re, r); else q += (q.length?'&':'?') + key + '=' + e(params[key]); } return window.location.pathname + q; }, ajaxUpdate: function(url){ this.setQueryStr(url); document.location.hash = 'r=' + this._queryStr; $.ajax({ url: url + '&nolayout=true', success: function(response){ var response = $('
').append(response); $('.isdr-live').each(function(i, element){ $(element).html(response.find('.isdr-live').eq(i).html()); }); } }); }, searchBox: function(){ var placeholder = 'Search'; var box = $('#global-search input[name=q]'); if (box.val() == '') box.val(placeholder); box.focus(function(){ if (box.val() == placeholder) box.val(''); }).blur(function(){ if (box.val() == '') box.val(placeholder); }); }, printTracking: function(){ $(window).bind('beforeprint', function(){ _gaq.push(['_trackEvent', 'Print', window.location.pathname]); }); }, sharingTools: function(){ if (!$('.sidebar-share').length) return; var services = { 'twitter': 'http://twitter.com/share?via=unisdr&text=' + document.title + '&url=' +window.location.href, 'facebook': "http://facebook.com/sharer.php?u=" + window.location.href, 'linkedin': "http://www.linkedin.com/shareArticle?mini=true&url="+window.location.href+"&title="+document.title+"&summary="+document.title+"&source=UNISDR" }; for (var key in services){ this.createButton(key, services[key]); } }, createButton: function(service, url){ var button = $('.sidebar-share .'+service)[0]; button.href = url; $(button).click(function(e){ e.preventDefault(); window.open(this.href); _gaq.push(['_trackEvent', 'Share on '+service, window.location.pathname]); }); }, privateSectorTooltips: function(){ var tooltip = $('') .css({display: 'none'}) .appendTo('body'); $('.partners-list img').live('mouseenter', function(){ var image = $(this); var offset = image.offset(); tooltip .css({ display: 'block', position: 'absolute', top: offset.top - 10, left: offset.left - 10, zIndex: 10 }) .html(image.attr('data-tooltip')) .prepend(image.clone()); }); } }; /** * Carousel displayed on the homepage. */ isdr.Carousel = function(){ var self = this; this._init = function(){ // carousel this.carousel = $('#carousel'); // ul this.scrollArea = $('#carousel .thumbs').css('position', 'relative'); // currently shown on the main panel this.selected = 0; // how many images were scrolled this.scrolled = 0; // images shown in the sidebar at the same time this.shown = 3; // number of images shown this.total = this.scrollArea.children().length; self.prev = $('#carousel .scroll.prev'); self.prev.data('title', self.prev.attr('title')); self.next = $('#carousel .scroll.next'); self.next.data('title', self.next.attr('title')); if (jQuery.browser.msie && jQuery.browser.version == '7.0'){ self.dimmers = $(); } else { self.dimmers = $('#carousel .dim-top, #carousel .dim-bottom'); } this.scrolling = false; // mouse in scrolling area this.inScrollArea = false; self.scrollArea.parent().mouseenter(function(e){ self.resetTimeout(); self.inScrollArea = true; self.dimmers.css('display', 'block'); }).mouseleave(function(){ self.resetTimeout(); self.inScrollArea = false; self.dimmers.css('display', 'none'); }); if (this.total >= 3){ // setup scrolling // double for infinite scroll self.scrollArea[0].innerHTML = self.scrollArea[0].innerHTML + self.scrollArea[0].innerHTML + self.scrollArea[0].innerHTML; self.prev.click(function(e){ e.preventDefault(); self.scroll(- 3); self.resetTimeout(); }); self.next.click(function(e){ e.preventDefault(); self.scroll(+ 3); self.resetTimeout(); }); self.check(); } else { self.prev.add(self.next).css('visibility', 'hidden'); } self.changing = false; this.activateThumbnail(self.scrollArea.children().eq(this.scrolled).find('a')); this.resetTimeout(); this.scrollArea.delegate('a', 'click', function(e){ if ($(this).hasClass('selected')) return; e.preventDefault(); self.resetTimeout(); if (self.changing) return; var data = self.getMetaData(this); self.activateThumbnail(this); self.changeImage(data); }); }; this.changeImage = function(data){ var busyTimeout = setTimeout(function(){ self.carousel.find('.loading').show(); }, 300); self.changing = true; // set title $('#carousel .spotlight-title').text(data.title); // set region $('#carousel .spotlight-region').text(data.region); // set url $('#carousel .spotlight-image-link, #carousel .spotlight-text').attr('href', data.href); // set credit link var creditLink = $('#carousel .spotlight-attribution').attr('href', data.photoCredit); // hide link if no credit record if (!data.photoCredit) creditLink.css('display', 'none'); else creditLink.css('display', 'block'); // apply image change animation var image = $('#carousel .spotlight-image'); var clone = image.clone(); clone.load(function(){ clearInterval(busyTimeout); self.carousel.find('.loading').hide(); self.resetTimeout(); clone.animate({opacity:1},{ duration:400, easing:'swing', complete: function(){ if (jQuery.browser.msie) this.style.filter = ""; $('#carousel .spotlight-image').not(this).remove(); self.changing = false; } }); }) .css('opacity', 0) .attr('src', data.image) .insertAfter(image); }; this.activateThumbnail = function(a){ this.selected = $(a).parent().index(); // reset all $(a).closest('ul').find('a') .attr('title', '') .removeClass('selected') .each(function(){ $(this).find('img').attr('src', self.getMetaData(this).thumbnail); }); var current = $(a).find('img').attr('src'); var metadata = self.getMetaData(a); $(a).closest('ul').find('img').each(function(){ if (this.parentNode.getAttribute('data-id') == metadata.id){ this.src = metadata.thumbnailSelected; $(this).closest('a').addClass('selected').attr('title', 'Click again to read.'); } }); }; this.getMetaData = function(element){ return $.parseJSON($(element).attr('data-meta')); }; this.rotate = function(parent){ if (this.selected < this.scrolled) this.selected = this.scrolled - 1; this.scrollArea.children().eq(this.selected).next().find('a').click(); if (this.selected >= this.scrolled + this.shown) self.scroll(+ 3); }; this.resetTimeout = function(){ clearTimeout(this.timeout); this.timeout = setTimeout(function(){ self.rotate(); }, 9999); }; this.check = function(){ if (self.scrolled < self.shown){ self.to(self.scrolled + self.total); self.selected += self.total; } else if (self.scrolled >= 3*self.total - 2*self.shown + 1){ self.to(self.scrolled - self.total); self.selected -= self.total; } }; this.to = function(where){ self.scrolled = where; self.scrollArea.scrollTop(self.scrollArea.children()[where].offsetTop + 1); }; this.scroll = function(dir){ if (self.scrolling) return; scrolling = true; self.dimmers.css('display', 'block'); self.scrolled += dir; var target = self.scrollArea.children()[self.scrolled].offsetTop + 1; self.scrollArea.animate({scrollTop: target},{ duration: 533, easing:'easeInOutQuad', complete: function(){ self.scrolling = false; if (!self.inScrollArea) self.dimmers.css('display', 'none'); self.check(); } }); }; this._init(); }; /* Adding easeInOutQuad easing to jQuery animations. */ $.extend($.easing, { easeInOutQuad: function (x, t, b, c, d){ if ((t/=d/2) < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; } }); /* Modernizr 2.0.4 (Custom Build) | MIT & BSD * Contains: csscolumns | cssclasses | testprop | testallprops | domprefixes */ ;window.Modernizr=function(a,b,c){function A(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+n.join(c+" ")+c).split(" ");return z(d,b)}function z(a,b){for(var d in a)if(k[a[d]]!==c)return b=="pfx"?a[d]:!0;return!1}function y(a,b){return!!~(""+a).indexOf(b)}function x(a,b){return typeof a===b}function w(a,b){return v(prefixes.join(a+";")+(b||""))}function v(a){k.cssText=a}var d="2.0.4",e={},f=!0,g=b.documentElement,h=b.head||b.getElementsByTagName("head")[0],i="modernizr",j=b.createElement(i),k=j.style,l,m=Object.prototype.toString,n="Webkit Moz O ms Khtml".split(" "),o={},p={},q={},r=[],s,t={}.hasOwnProperty,u;!x(t,c)&&!x(t.call,c)?u=function(a,b){return t.call(a,b)}:u=function(a,b){return b in a&&x(a.constructor.prototype[b],c)},o.csscolumns=function(){return A("columnCount")};for(var B in o)u(o,B)&&(s=B.toLowerCase(),e[s]=o[B](),r.push((e[s]?"":"no-")+s));v(""),j=l=null,e._version=d,e._domPrefixes=n,e.testProp=function(a){return z([a])},e.testAllProps=A,g.className=g.className.replace(/\bno-js\b/,"")+(f?" js "+r.join(" "):"");return e}(this,this.document); // Sidebar Rotator Script Added by Vincent // JavaScript Document FOR SIDEBAR DOCUMENTS function theRotator() { //Set the opacity of all images to 0 $('div.rotator ul li').css({opacity: 0.0}); //Get the first image and display it (gets set to full opacity) $('div.rotator ul li:first').css({opacity: 1.0}).addClass('show'); //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds setInterval(rotate,6000); } function rotate() { //Get the first image var current = ($('div.rotator ul li.show')? $('div.rotator ul li.show') : $('div.rotator ul li:first')); if ( current.length == 0 ) current = $('div.rotator ul li:first'); //Get next image, when it reaches the end, rotate it back to the first image var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first')); //Un-comment the 3 lines below to get the images in random order //var sibs = current.siblings(); //var rndNum = Math.floor(Math.random() * sibs.length ); //var next = $( sibs[ rndNum ] ); //Set the fade in effect for the next image, the show class has higher z-index next.css({opacity: 0.0}) .addClass('show') .animate({opacity: 1.0}, 1000); //Hide the current image current.animate({opacity: 0.0}, 1000) .removeClass('show'); }; $(document).ready(function() { //Load the slideshow theRotator(); $('div.rotator').fadeIn(1000); $('div.rotator ul li').fadeIn(1000); // tweek for IE }); // JavaScript Document FOR SIDEBAR PHOTOS function theRotator_photo() { //Set the opacity of all images to 0 $('div.rotator_photo ul li').css({opacity: 0.0}); //Get the first image and display it (gets set to full opacity) $('div.rotator_photo').find('ul li:first').css({opacity: 1.0}).addClass('show'); //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds var selfRotatePhoto = function () { $('div.rotator_photo ul').each(function () { console.log($(this)); rotate_photo($(this)); }); }; setInterval(selfRotatePhoto,10000); } function rotate_photo(carrousel_selector) { //Get the first image var current = (carrousel_selector.find('li.show')? carrousel_selector.find('li.show') : carrousel_selector.find('li:first')); if (current.length == 0 ) current = carrousel_selector.find('li:first'); //Get next image, when it reaches the end, rotate it back to the first image var next = ((current.next().length) ? ((current.next().hasClass('show')) ? carrousel_selector.find('li:first') :current.next()) : carrousel_selector.find('li:first')); //Un-comment the 3 lines below to get the images in random order //var sibs = current.siblings(); //var rndNum = Math.floor(Math.random() * sibs.length ); //var next = $( sibs[ rndNum ] ); //Set the fade in effect for the next image, the show class has higher z-index next.css({opacity: 0.0}) .addClass('show') .animate({opacity: 1.0}, 1000); //Hide the current image current.animate({opacity: 0.0}, 1000) .removeClass('show'); }; $(document).ready(function() { //Load the slideshow theRotator_photo(); $('div.rotator_photo').fadeIn(1000); $('div.rotator_photo ul li').fadeIn(1000); // tweek for IE }); jQuery(function($){ if ($('.bxslider').length){ $('.bxslider').bxSlider({ adaptiveHeight: true, mode: 'fade', auto: true, autoStart: true, autoDelay: 2000, pause:9000, captions: true }); } })