// usage: log('inside coolFunc', this, arguments);
window.log = function(){
log.history = log.history || [];   // store logs to an array for reference
log.history.push(arguments);
if(this.console) {
arguments.callee = arguments.callee.caller;
console.log( Array.prototype.slice.call(arguments) );
}
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


/*
 * Metadata - jQuery plugin for parsing metadata from elements
 *
 * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.metadata.js 3620 2007-10-10 20:55:38Z pmclanahan $
 *
 */
(function($){$.extend({metadata:{defaults:{type:'class',name:'metadata',cre:/({.*})/,single:'metadata'},setType:function(type,name){this.defaults.type=type;this.defaults.name=name;},get:function(elem,opts){var settings=$.extend({},this.defaults,opts);if(!settings.single.length)settings.single='metadata';var data=$.data(elem,settings.single);if(data)return data;data="{}";if(settings.type=="class"){var m=settings.cre.exec(elem.className);if(m)data=m[1];}else if(settings.type=="elem"){if(!elem.getElementsByTagName)return;var e=elem.getElementsByTagName(settings.name);if(e.length)data=$.trim(e[0].innerHTML);}else if(elem.getAttribute!=undefined){var attr=elem.getAttribute(settings.name);if(attr)data=attr;}if(data.indexOf('{')<0)data="{"+data+"}";data=eval("("+data+")");$.data(elem,settings.single,data);return data;}}});$.fn.metadata=function(opts){return $.metadata.get(this[0],opts);};})(jQuery);


/**
 * swapImage - jQuery plugin for swapping image
 *
 * Copyright (c) 2010 tszming (tszming@gmail.com)
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
(function(a){a.swapImage=function(c,b,e,f,d){a.swapImage.files={};a.swapImage.data={};a.swapImage.uuid=0;a.swapImage.init=function(){var h=++a.swapImage.uuid;a(this).attr("swapImageId",h);var g=a(this).metadata();a.swapImage.data[h]=a.swapImage.data[h]||{};if(typeof g.src!="undefined"){a.swapImage.data[h]["src"]=g.src;a.swapImage.files[g.src]=false}a.each(a.grep([[g.sin,"sin"],[g.sout,"sout"]],function(i){return(typeof i[0]!="undefined"&&i[0].length>0)}),function(){var k=this[0];var o=this[1];for(var m=0;m<k.length;m++){var j=g[o][m].indexOf(":");var n=g[o][m].substring(0,j);var l=g[o][m].substring(j+1);a.swapImage.data[h][o]=a.swapImage.data[h][o]||[];if(j>1){a.swapImage.data[h][o].push([n,l]);a.swapImage.files[l]=false}else{a.swapImage.data[h][o].push([l])}}})};a.swapImage.preload=function(){a.each(a.swapImage.files,function(i,h){if(h==false){a.swapImage.files[i]=true;var g=new Image();g.src=i}})};a.swapImage.swapIn=function(){a.swapImage.swap(this,"sin")};a.swapImage.swapOut=function(){a.swapImage.swap(this,"sout")};a.swapImage.swap=function(j,g){var k=a(j).attr("swapImageId");if(typeof a.swapImage.data[k][g]!="undefined"){for(var h=0;h<a.swapImage.data[k][g].length;h++){if(a.swapImage.data[k][g][h].length>1){a(a.swapImage.data[k][g][h][0]).attr("src",a.swapImage.data[k][g][h][1])}else{a(a.swapImage.data[k][g][h][0]).each(a.swapImage._swap)}}}else{a.swapImage._swap.call(j)}};a.swapImage._swap=function(i){var j=a(this).attr("swapImageId");var h=a.swapImage.data[j];if(typeof h.src!="undefined"){var g=h.src;h.src=this.src;this.src=g}};a(document).ready(function(){if(typeof e=="undefined"){e=true}if(typeof b=="undefined"){b=true}a(c).each(a.swapImage.init);if(typeof f=="undefined"&&typeof f=="undefined"){f="mouseenter";d="mouseleave"}if(e){if(typeof d!="undefined"){a(c).bind(f,a.swapImage.swapIn).bind(d,a.swapImage.swapOut)}else{a(c).bind(f,a.swapImage.swapIn)}}else{a(c).one(f,a.swapImage.swapIn)}if(b){a(c).each(a.swapImage.preload)}})}})(jQuery);


/**
 *  jquery-instagram
 *  http://potomak.github.com/jquery-instagram/
 */

(function($){
  $.fn.instagram = function(options) {
    var that = this,
        apiEndpoint = "https://api.instagram.com/v1",
        settings = {
            hash: null
          , search: null
          , accessToken: null
          , clientId: null
          , show: null
          , onLoad: null
          , onComplete: null
          , maxId: null
          , minId: null
          , next_url: null
        };
        
    options && $.extend(settings, options);
    
    function createPhotoElement(photo) {
      return $('<div>')
        .addClass('instagram-placeholder')
        .attr('id', photo.id)
        .append(
          $('<a>')
            .attr('target', '_blank')
            .attr('href', photo.link)
            .append(
              $('<img>')
                .addClass('instagram-image')
                .attr('src', photo.images.thumbnail.url)
            )
        );
    }
    
    function composeRequestURL() {

      var url = apiEndpoint,
          params = {};
      
      if (settings.next_url != null)
      	return settings.next_url

      if(settings.hash != null) {
        url += "/tags/" + settings.hash + "/media/recent";
      }
      else if(settings.search != null) {
        url += "/media/search";
        params.lat = settings.search.lat;
        params.lng = settings.search.lng;
        settings.search.max_timestamp != null && (params.max_timestamp = settings.search.max_timestamp);
        settings.search.min_timestamp != null && (params.min_timestamp = settings.search.min_timestamp);
        settings.search.distance != null && (params.distance = settings.search.distance);
      }
      else {
        url += "/media/popular";
      }
      
      settings.accessToken != null && (params.access_token = settings.accessToken);
      settings.clientId != null && (params.client_id = settings.clientId);
      settings.minId != null && (params.min_id = settings.minId);
      settings.maxId != null && (params.max_id = settings.maxId);

      url += "?" + $.param(params)
      
      return url;
    }
    
    settings.onLoad != null && typeof settings.onLoad == 'function' && settings.onLoad();
    
    $.ajax({
      type: "GET",
      dataType: "jsonp",
      cache: false,
      url: composeRequestURL(),
      success: function(res) {
        
        var limit = settings.show == null ? res.data.length : settings.show;
        
        for(var i = 0; i < limit; i++) {
          that.append(createPhotoElement(res.data[i]));
        }

        settings.onComplete != null && typeof settings.onComplete == 'function' && settings.onComplete(res.data, res);
      }
    });
    
    return this;
  };
})(jQuery);


