/*
 * jGFeed 1.0 - Google Feed API abstraction plugin for jQuery
 *
 * Copyright (c) 2009 jQuery HowTo
 *
 * Licensed under the GPL license:
 *   http://www.gnu.org/licenses/gpl.html
 *
 * URL:
 *   http://jquery-howto.blogspot.com
 *
 * Author URL:
 *   http://me.boo.uz
 *
 */
(function($){$.extend({jGFeed:function(url,fnk,num,key){if(url==null){return false;}var gurl="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url;if(num!=null){gurl+="&num="+num;}if(key!=null){gurl+="&key="+key;}$.getJSON(gurl,function(data){if(typeof fnk=="function"){fnk.call(this,data.responseData.feed);}else{return false;}});}});})(jQuery);;
/*
 * jYoutube 1.0 - YouTube video image getter plugin for jQuery
 *
 * Copyright (c) 2009 jQuery Howto
 *
 * Licensed under the GPL license:
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Plugin home & Author URL:
 *   http://jquery-howto.blogspot.com
 *
 */
(function(d){d.extend({jYoutube:function(a,b){if(a===null)return"";b=b===null?"big":b;var c;c=a.match("[\\?&]v=([^&#]*)");a=c===null?a:c[1];return b=="small"?"http://img.youtube.com/vi/"+a+"/2.jpg":"http://img.youtube.com/vi/"+a+"/0.jpg"}})})(jQuery);;
// JavaScript Document

jQuery(document).ready(function() {
	jQuery.jGFeed('http://gdata.youtube.com/feeds/base/videos?author=paceandpartners&orderby=rating',
                function(feeds){
                    // Check for errors
                    if(!feeds){
                        // there was an error
						alert("error");
                        return false;
                    }

                    var html = '';

                    // do whatever you want with feeds here
                    for(var i=0; i<feeds.entries.length; i++){
                        var entry = feeds.entries[i];
                        html += '<a href="' + entry.link + '" title="' + entry.title + '"><img src="' + jQuery.jYoutube(entry.link, 'medium') + '" class="thumb left"></a>';
                    }

                    jQuery('#youtube-holder').html(html);
                }, 3);
            });

;
// JavaScript Document
jQuery(document).ready(function() {

	jQuery('a#facebookLink').click(function() {
		jQuery('#facebook').show();
		jQuery(this).addClass("selected");
		jQuery("#twitterLink").removeClass("selected")
		jQuery('a#facebookLink img').attr("src", "/sites/default/files/facebook-logo.png");
		jQuery('a#twitterLink img').attr("src", "/sites/default/files/twitter_logo_screen.png");
	});
	
	jQuery('a#twitterLink').click(function() {
		jQuery('#facebook').hide();
		jQuery(this).addClass("selected");
		jQuery("a#facebookLink").removeClass("selected");
		jQuery('a#facebookLink img').attr("src", "/sites/default/files/facebook_logo_screen.png");
		jQuery('a#twitterLink img').attr("src", "/sites/default/files/twitter_logo.png");
	});

});;
function diagram_image(image){
  //alert(image);
  var path ="/sites/default/files/itmp-images/";
  jQuery('#diagram img').attr("src",path+image+".jpg");
}

jQuery(document).ready(function(){
  
  jQuery('area').mouseover(function() {
    //alert(jQuery(this).attr('class'));
    diagram_image(jQuery(this).attr('class'));
  }).mouseout(function(){
    diagram_image('PaceCapabilities');
  });
  
  jQuery('area').click(function(){
    var id_to_find = jQuery(this).attr('class');
    jQuery('#diagramText div').hide(); //hide all items     
    jQuery('#'+id_to_find).show(); //show just the one clicked
  });
  
  jQuery('#diagramText .default_hide').hide();
  
});;
//CALLED WHEN CLICKING TO SWITCH BETWEEN CAMPAIGNS
function ps_click_link(pos)
{
    jQuery('.campaign-display').html('');
	jQuery('.campaign').hide();
	jQuery('.campaign').eq(pos).fadeIn();
	jQuery('#pace_showcase_nav_links ul li').removeClass('pace_showcase_link_active');
	jQuery('#pace_showcase_nav_links ul li').addClass('pace_showcase_link_inactive');
	jQuery('#pace_showcase_nav_links ul li').eq(pos).addClass('pace_showcase_link_active');
	selectThumbnail(jQuery('.campaign').eq(pos).find('.views-row-1 .views-field-title'));        //Select 1st thumbnail	
	set_campaigns(pos+1,jQuery('#pace_showcase_nav_links ul li').length);
	
	if(jQuery('.campaign').eq(pos).find('.views-row').length <= 6){
		jQuery('.campaign').eq(pos).find('.campaign-slider-left img').hide();
		jQuery('.campaign').eq(pos).find('.campaign-slider-right img').hide();
	}
}

function set_campaigns(num,length){
	jQuery('#pace_showcase_text_position').html((num)+' OF '+ length +' CAMPAIGNS      ');
}

//CALLED TO SHOW the media associated with the thumbnail item.
function selectThumbnail(t){
    //alert(jQuery(t).html());
	jQuery('.slideshow_active_thumbnail').removeClass('slideshow_active_thumbnail');
	jQuery(t).addClass('slideshow_active_thumbnail');
	campaign_display = jQuery(t).parents('.campaign').children('.campaign-display');
	jQuery('.campaign-display').html(''); //clear all (not awesome performance)

	
	var item_to_show = jQuery(t).closest('.views-row'); //original div with sub items of different media types, title etc.
	var item_to_show_clone = jQuery(item_to_show).clone(); //copy the items to put in the primary display area
    campaign_display.html(item_to_show_clone); //put items into the main detail area

	campaign_display.find('.views-row').children().show();   //show all the story,media,image items
	campaign_display.find('.views-row .views-field-title').hide();	//hide the thumbnail & title 	
}
function setDefaultCampaign(){
	if(window.location.hash) {
      var hash = window.location.hash.substring(1);
      ps_click_link(hash*1-1);
  } else {
      ps_click_link(0);
  }
}


(function($){
 $.fn.pace_showcase = function() {
    return this.each(function() {						

    			$(this).prepend('<div id="pace_showcase_content"></div><div id="pace_showcase_nav"><div id="pace_showcase_text_container"><div id="pace_showcase_text_position"></div></div><div id="pace_showcase_nav_links"><ul></ul></div></div>');
					var position=0;
					var pos_class = "";
          $pace_showcase_content = $("#pace_showcase_content");
					$pace_showcase_links = $('#pace_showcase_nav_links ul');
   				$('.campaign').each(function(counter){
							item_title = $(this).find('h2').html();
							$pace_showcase_links.append('<li class="pace_showcase_link_inactive"><a href="javascript:void(0)" title="'+item_title+'" onclick="ps_click_link('+counter+')" class="twipsy_it" data-placement="below" rel="twipsy"><img alt="'+item_title+'" src="/sites/default/files/circle.png"/></a></li>');
							$(this).find('.campaign-details').after('<div class="campaign-display"></div><div style="clear:both"></div><div class="campaign-slider-left"><a href="javascript:void(0)"><img src="/sites/default/files/mini-left-arrow.gif" border="0"/></a></div><div class="campaign-slider"><div class="campaign-thumbnails"></div></div><div class="campaign-slider-right"><a href="javascript:void(0)"><img src="/sites/default/files/mini-right-arrow.gif" border="0"/></a></div><div style="clear:both"></div>');
							$pace_showcase_content.append(this).append("<div style='clear:both'></div>");
							campaign_thumbnails = $(this).find('.campaign-thumbnails');
							$(this).find('.views-row').each(function(j){
								campaign_thumbnails.append($(this));
							});
					});
			
					jQuery('.view-our-work .views-field-title').click(function(){		
						selectThumbnail(this);				
						});
			   jQuery('.campaign-slider-left').click(function(){		
					   slider = jQuery(this).siblings('.campaign-slider');
					   slider.animate({scrollLeft: slider.scrollLeft() - 200}, 1000);  
					});
					jQuery('.campaign-slider-right').click(function(){		
				   slider = jQuery(this).siblings('.campaign-slider');
				   slider.animate({scrollLeft: (slider.scrollLeft() + 200)}, 1000);  
					});   
									
					jQuery('.pace_showcase_nav_links ul').fadeIn();
					if ( $.browser.msie ) {
						jQuery('#pace_showcase_text_position').hide();
					} 
				
				// jQuery('a.colorbox').removeClass().addClass('custom-modal').attr('href','#'); //TEMP disable colorbox since not working
				 setDefaultCampaign();
					
    });
 };
})(jQuery);



jQuery().ready(function(){
  jQuery('.view-our-work').pace_showcase();
  jQuery('.twipsy_it').twipsy();
	//jQuery('img').colorbox();
});

;
/* ==========================================================
 * bootstrap-twipsy.js v1.4.0
 * http://twitter.github.com/bootstrap/javascript.html#twipsy
 * Adapted from the original jQuery.tipsy by Jason Frame
 * ==========================================================
 * Copyright 2011 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */


!function( $ ) {

  "use strict"

 /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
  * ======================================================= */

  var transitionEnd

  $(document).ready(function () {

    $.support.transition = (function () {
      var thisBody = document.body || document.documentElement
        , thisStyle = thisBody.style
        , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
      return support
    })()

    // set CSS transition event type
    if ( $.support.transition ) {
      transitionEnd = "TransitionEnd"
      if ( $.browser.webkit ) {
      	transitionEnd = "webkitTransitionEnd"
      } else if ( $.browser.mozilla ) {
      	transitionEnd = "transitionend"
      } else if ( $.browser.opera ) {
      	transitionEnd = "oTransitionEnd"
      }
    }

  })


 /* TWIPSY PUBLIC CLASS DEFINITION
  * ============================== */

  var Twipsy = function ( element, options ) {
    this.$element = $(element)
    this.options = options
    this.enabled = true
    this.fixTitle()
  }

  Twipsy.prototype = {

    show: function() {
      var pos
        , actualWidth
        , actualHeight
        , placement
        , $tip
        , tp

      if (this.hasContent() && this.enabled) {
        $tip = this.tip()
        this.setContent()

        if (this.options.animate) {
          $tip.addClass('fade')
        }

        $tip
          .remove()
          .css({ top: 0, left: 0, display: 'block' })
          .prependTo(document.body)

        pos = $.extend({}, this.$element.offset(), {
          width: this.$element[0].offsetWidth
        , height: this.$element[0].offsetHeight
        })

        actualWidth = $tip[0].offsetWidth
        actualHeight = $tip[0].offsetHeight

        placement = maybeCall(this.options.placement, this, [ $tip[0], this.$element[0] ])

        switch (placement) {
          case 'below':
            tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
            break
          case 'above':
            tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
            break
          case 'left':
            tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}
            break
          case 'right':
            tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}
            break
        }

        $tip
          .css(tp)
          .addClass(placement)
          .addClass('in')
      }
    }

  , setContent: function () {
      var $tip = this.tip()
      $tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle())
      $tip[0].className = 'twipsy'
    }

  , hide: function() {
      var that = this
        , $tip = this.tip()

      $tip.removeClass('in')

      function removeElement () {
        $tip.remove()
      }

      $.support.transition && this.$tip.hasClass('fade') ?
        $tip.bind(transitionEnd, removeElement) :
        removeElement()
    }

  , fixTitle: function() {
      var $e = this.$element
      if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
        $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
      }
    }

  , hasContent: function () {
      return this.getTitle()
    }

  , getTitle: function() {
      var title
        , $e = this.$element
        , o = this.options

        this.fixTitle()

        if (typeof o.title == 'string') {
          title = $e.attr(o.title == 'title' ? 'data-original-title' : o.title)
        } else if (typeof o.title == 'function') {
          title = o.title.call($e[0])
        }

        title = ('' + title).replace(/(^\s*|\s*$)/, "")

        return title || o.fallback
    }

  , tip: function() {
      return this.$tip = this.$tip || $('<div class="twipsy" />').html(this.options.template)
    }

  , validate: function() {
      if (!this.$element[0].parentNode) {
        this.hide()
        this.$element = null
        this.options = null
      }
    }

  , enable: function() {
      this.enabled = true
    }

  , disable: function() {
      this.enabled = false
    }

  , toggleEnabled: function() {
      this.enabled = !this.enabled
    }

  , toggle: function () {
      this[this.tip().hasClass('in') ? 'hide' : 'show']()
    }

  }


 /* TWIPSY PRIVATE METHODS
  * ====================== */

   function maybeCall ( thing, ctx, args ) {
     return typeof thing == 'function' ? thing.apply(ctx, args) : thing
   }

 /* TWIPSY PLUGIN DEFINITION
  * ======================== */

  $.fn.twipsy = function (options) {
    $.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy')
    return this
  }

  $.fn.twipsy.initWith = function (options, Constructor, name) {
    var twipsy
      , binder
      , eventIn
      , eventOut

    if (options === true) {
      return this.data(name)
    } else if (typeof options == 'string') {
      twipsy = this.data(name)
      if (twipsy) {
        twipsy[options]()
      }
      return this
    }

    options = $.extend({}, $.fn[name].defaults, options)

    function get(ele) {
      var twipsy = $.data(ele, name)

      if (!twipsy) {
        twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options))
        $.data(ele, name, twipsy)
      }

      return twipsy
    }

    function enter() {
      var twipsy = get(this)
      twipsy.hoverState = 'in'

      if (options.delayIn == 0) {
        twipsy.show()
      } else {
        twipsy.fixTitle()
        setTimeout(function() {
          if (twipsy.hoverState == 'in') {
            twipsy.show()
          }
        }, options.delayIn)
      }
    }

    function leave() {
      var twipsy = get(this)
      twipsy.hoverState = 'out'
      if (options.delayOut == 0) {
        twipsy.hide()
      } else {
        setTimeout(function() {
          if (twipsy.hoverState == 'out') {
            twipsy.hide()
          }
        }, options.delayOut)
      }
    }

    if (!options.live) {
      this.each(function() {
        get(this)
      })
    }

    if (options.trigger != 'manual') {
      binder   = options.live ? 'live' : 'bind'
      eventIn  = options.trigger == 'hover' ? 'mouseenter' : 'focus'
      eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'
      this[binder](eventIn, enter)[binder](eventOut, leave)
    }

    return this
  }

  $.fn.twipsy.Twipsy = Twipsy

  $.fn.twipsy.defaults = {
    animate: true
  , delayIn: 0
  , delayOut: 0
  , fallback: ''
  , placement: 'above'
  , html: false
  , live: false
  , offset: 0
  , title: 'title'
  , trigger: 'hover'
  , template: '<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>'
  }

  $.fn.twipsy.rejectAttrOptions = [ 'title' ]

  $.fn.twipsy.elementOptions = function(ele, options) {
    var data = $(ele).data()
      , rejects = $.fn.twipsy.rejectAttrOptions
      , i = rejects.length

    while (i--) {
      delete data[rejects[i]]
    }

    return $.extend({}, options, data)
  }

}( window.jQuery || window.ender );;

