/*----------------------------------------------------------------------
[Global JavaScript ] 
Desc: site wide javascript

Copyright:		Great Fridays 2010
Client:			Emma Watson
Project:		Emma Watson official
Created by:		Adam Foster
Last Updated:	04 - 03 - 10			
-----------------------------------------------------------------------*/

var $j=jQuery.noConflict();var browser="unknown";$j(document).ready(function(){addBodyClass();hideArtwork();checkForBubbles();handleLandingPages();equalHeightHeadings();addArticleCaps();externalLinks();initializeTracking()});function initializeTracking(){var h=(("https:"==document.location.protocol)?"https://ssl.":"http://www.");$j.getScript(h+"google-analytics.com/ga.js",function(){var f=_gat._getTracker("UA-12122969-3");f._trackPageview();var g=/\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|mp4|flv|wmv|mov)$/i;$j(document.body).delegate('a','click',function(){var a=$j(this).attr('href');if((a.match(/^https?\:/i))&&(!a.match(document.domain))){var b=a.replace(new RegExp("^https?\:\/\/","i"),'');f._trackEvent('External','Click',b)}else if(a.match(/^mailto\:/i)){var c=a.replace(new RegeExp('^mailto\:','i'),'');f._trackEvent('Email','Click',c)}else if(a.match(g)){var d=(/[.]/.exec(a))?/[^.]+$/.exec(a):undefined;var e=a.replace(new RegExp("^https?\:\/\/(www.)emmawatson\.com\/","i"),'');f._trackEvent('Download','Click - '+d,e)}})})}function addBodyClass(){var a=navigator.userAgent.toLowerCase();if($j.browser.msie){browser="isIE"};if($j.browser.safari){browser="isWebKit"};if($j.browser.mozilla){browser="isMozilla"};if($j.browser.opera){browser="isOpera"};$j('body').addClass('js '+browser)};function checkForBubbles(){$j('a.bubble').each(function(i){var c=$j(this);c.closest('li').bind('click',function(a){var b=c.attr('href');if(b.substring(0,7)=='http://'){window.open(b)}else{document.location=b}return false})})};function handleLandingPages(){$j('.landingBlocks ul li ').each(function(){var o=new imgRollovers($j(this))});function imgRollovers(e){if(browser!="isIE"){var o={init:function(){o.listItem=$j(e);o.mask=o.listItem.find('.mask');o.img=o.listItem.find('img');o.animate()},animate:function(){o.listItem.hover(function(){o.listItem.css('height',o.listItem.parent().innerHeight());o.mask.stop().animate({width:'120%',marginTop:'-11%',marginBottom:'-10%',marginLeft:'-20px'},150)},function(){o.mask.stop().animate({width:'100%',marginTop:0,marginBottom:0,marginLeft:0},150,function(){o.listItem.css('height','auto')})})}};o.init()}}};function hideArtwork(){$j('#emma .artworkOverlay').each(function(){var o=new hideShowArtwork($j(this))});function hideShowArtwork(e){var o={init:function(){o.vector=$j(e);o.container=$j('#mainContent');o.width=o.container.width();o.maxWidth=1160;o.setMaxWidth();o.showOnLoad();o.container.resize(function(){o.monitor()})},setMaxWidth:function(){var b=0;if(o.container.find('.row').length){var c=$j('> [class*="col"]',o.container.find('.row'));c.each(function(){var a=$j(this);b+=(a.outerWidth()+parseInt(a.css('marginLeft'))+parseInt(a.css('marginRight')))});o.maxWidth=(b+o.vector.width())}},showOnLoad:function(){o.width=o.container.width();if(o.width>o.maxWidth){o.vector.css('display','block')}},monitor:function(){o.width=o.container.width();if(o.width>o.maxWidth){if(browser=='isIE'){o.vector.css('display','block')}else{o.vector.fadeIn()}}else{if(browser=='isIE'){o.vector.css('display','none')}else{o.vector.fadeOut()}}}};o.init()}};function equalHeightHeadings(){$j('.doubleHeightHeadings').each(function(){tThis=$j(this);fixHeight(tThis,'equalHeight');fixHeight(tThis,'equalSubHeight');fixHeight(tThis,'colContentBody');fixHeight(tThis,'newsList')});function fixHeight(e,a){var b=0;e.find('.'+a).each(function(i){if($j(this).height()>b){b=$j(this).height()}}).css({'min-height':b})}};function fullScreenPage(){$j('#emma').each(function(){var o=new fullScreenPage($j(this))});function fullScreenPage(e){var o={init:function(){o.wrapper=$j(e);o.window=$j(window);o.ratio=1150/800;o.window.resize(function(){o.test()}).trigger('resize')},test:function(){o.windowRatio=o.window.width()/o.window.height();if(o.windowRatio>o.ratio){o.wrapper.css({'width':Math.floor(o.window.height()*o.ratio)})}else{o.wrapper.css({'width':"100%"})}}};o.init()}};function addArticleCaps(){var c=$j('.article.dropCapContent p:first');var d=$j('.flatContentTemplate .row > div.dropCapContent > h2:first-child').siblings('p:first');c.add(d).each(function(){var a=$j(this);a.parent('div').addClass('clearfix');var b=a.html();if(b.charAt(0)=="<"){b=a.children(":first-child").html();a=a.children(":first-child")};a.html(b.replace(/^([A-Za-z0-9])/g,'<span class="caps c$1">$1</span>'))})};function newsScroller(){$j('#newsScroller').each(function(){var o=new setupScroller($j(this))});function setupScroller(e){var o={init:function(){o.wrapper=$j(e);o.controls=o.wrapper.next('.newsListPag');o.items=o.wrapper.children('li');o.total=o.items.length;if(o.total>4)o.setUpScroller()},setUpScroller:function(){o.controls.show();o.up=o.controls.find('.upLink');o.down=o.controls.find('.downLink');o.wrapper.wrap("<div id='mask'></div>");o.selected=o.wrapper.children('.selected');o.controls.find('.newsListInfo span:last-child').html(Math.ceil(o.total/4));o.maxHeight=0;o.getMaxHeight();o.move=o.maxHeight*4;o.step=Math.ceil((o.items.index(o.selected)+1)/4);o.controls.find('.newsListInfo span:first-child').html(o.step);o.position=-(o.step-1)*o.move;o.mask=$j('#mask').css('height',o.move);o.wrapper.css('top',o.position);if(o.step==1){o.up.addClass('disabled')}else if(o.step==Math.ceil(o.total/4)){o.down.addClass('disabled')};o.down.click(function(e){if(!$j(this).hasClass('disabled'))o.scrollDown()});o.up.click(function(e){if(!$j(this).hasClass('disabled'))o.scrollUp()})},getMaxHeight:function(){o.items.each(function(){var a=$j(this);if(a.outerHeight()+parseInt(a.css('paddingBottom'))>o.maxHeight){o.maxHeight=a.height()+parseInt(a.css('paddingBottom'))}}).css({height:o.maxHeight,'paddingBottom':0})},scrollDown:function(){if(o.up.hasClass('disabled'))o.up.removeClass('disabled');o.position=o.position-o.move;o.wrapper.animate({top:o.position},500,'easeInOutQuad');o.step++;o.controls.find('.newsListInfo span:first-child').html(o.step);if(o.step==Math.ceil(o.total/4))o.down.addClass('disabled')},scrollUp:function(){if(o.down.hasClass('disabled'))o.down.removeClass('disabled');o.position=o.position+o.move;o.wrapper.animate({top:o.position},500,'easeInOutQuad');o.step--;o.controls.find('.newsListInfo span:first-child').html(o.step);if(o.step==1)o.up.addClass('disabled')}};o.init()}};function externalLinks(){$j('a[rel="external"]').attr("target","_blank")};function eventsAccordion(){$j('.eventsTemplate').each(function(){var o=new setupAccordion($j(this))});function setupAccordion(e){var c=$j(e);c.find('.eventRowContent:not(:first)').hide();$j('.eventRow',c).each(function(i){var b=$j(this);b.find('h2').wrapInner("<a href='javascript:void(0);'></a>").children('a').bind('click',function(a){b.find('.eventRowContent').stop().toggle()})})}};$j.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};

/* Global > resize plugin  -------------------------------------------*/

/*
 * jQuery resize event - v1.0 - 2/10/2010
 * http://benalman.com/projects/jquery-resize-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);l.data(d,{width:l.width(),height:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=q.data(d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=n.data(d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});i=h[k](g,e[b])}})(jQuery,this);