/******************************************************************************
* Fischler.org
******************************************************************************/

/*** Plugin : Képátméretező v0.2 [Compressed] (Ver. 0.2) : Copyright (c) Burda Roland - 2009 július 10 - E-mail: qkac87@gmail.com : http://hirdet2.extra.hu/kepresize/ ***/
(function(a){a.fn.kepresize=function(b){var c={maxWidth:110,maxHeight:115};var b=a.extend(c,b);return this.each(function(){obj=a(this);var g=0;var d=0;var g=obj.width();var d=obj.height();var e=g/b.maxWidth;var f=d/b.maxHeight;if(f>e){new_height=Math.ceil(d*(1/f));new_width=Math.ceil(g*(1/f));obj.css("height",new_height);obj.css("width",new_width)}else{new_height=Math.ceil(d*(1/e));new_width=Math.ceil(g*(1/e));obj.css("height",new_height);obj.css("width",new_width)}})}})(jQuery);


/*** Plugin : Center Element [Compressed] (Ver. 1,0) : Copyright (c) Alexandre Magno : http://www.alexandremagno.net/jquery/plugins/center/ ***/
jQuery.fn.center=function(b){var a={vertical:true,horizontal:true};op=jQuery.extend(a,b);return this.each(function(){var m=jQuery(this);var c=m.width();var n=m.height();var o=parseInt(m.css("padding-top"));var d=parseInt(m.css("padding-bottom"));var e=parseInt(m.css("border-top-width"));var l=parseInt(m.css("border-bottom-width"));var h=(e+l)/2;var j=(o+d)/2;var i=m.parent().css("position");var g=(c/2)*(-1);var k=((n/2)*(-1))-j-h;var f={position:"absolute"};if(op.vertical){f.height=n;f.top="50%";f.marginTop=k}if(op.horizontal){f.width=c;f.left="50%";f.marginLeft=g}if(i=="static"){m.parent().css("position","relative")}m.css(f)})};


/*** Plugin : Logging : Copyright (c) Dominic Mitchell : http://happygiraffe.net/blog/2007/09/26/jquery-logging/ ***/
jQuery.fn.log = function (msg) { console.log("%s: %o", msg, this); return this; };


/*** Plugin : Facebox [Compressed] (Ver. 1.2) : Copyright (c) 2007, 2008 Chris Wanstrath : http://famspam.com/facebox/ ***/
(function(f){f.facebox=function(m,l){f.facebox.loading();if(m.ajax){g(m.ajax)}else{if(m.image){c(m.image)}else{if(m.div){j(m.div)}else{if(f.isFunction(m)){m.call(f)}else{f.facebox.reveal(m,l)}}}}};f.extend(f.facebox,{settings:{opacity:0,overlay:true,loadingImage:"../img/loading.gif",closeImage:"../img/closelabel.gif",imageTypes:["png","jpg","jpeg","gif"],faceboxHtml:'<div id="facebox" style="display:none;"><b class="overlay"></b><div class="popup"><table><tbody><tr><td class="tl"/><td class="b"/><td class="tr"/></tr><tr><td class="b"/><td class="body"><div class="content"></div><div class="footer"><a href="#" class="close">Close</a></div></td><td class="b"/></tr><tr><td class="bl"/><td class="b"/><td class="br"/></tr></tbody></table></div></div>'},loading:function(){k();if(f("#facebox .loading").length==1){return true}e();f("#facebox .content").empty();f("#facebox .body").children().hide().end().append('<div class="loading"><img src="'+f.facebox.settings.loadingImage+'"/></div>');f("#facebox").css({top:h()[1]+(i()/10),left:385.5}).show();f(document).bind("keydown.facebox",function(l){if(l.keyCode==27){f.facebox.close()}return true});f(document).trigger("loading.facebox")},reveal:function(m,l){f(document).trigger("beforeReveal.facebox");if(l){f("#facebox .content").addClass(l)}f("#facebox .content").append(m);f("#facebox .loading").remove();f("#facebox .body").children().fadeIn("normal");f("#facebox").css("left",f(window).width()/2-(f("#facebox table").width()/2));f(document).trigger("reveal.facebox").trigger("afterReveal.facebox")},close:function(){f(document).trigger("close.facebox");return false}});f.fn.facebox=function(l){k(l);function m(){f.facebox.loading(true);var n=this.rel.match(/facebox\[?\.(\w+)\]?/);if(n){n=n[1]}j(this.href,n);return false}return this.click(m)};function k(n){if(f.facebox.settings.inited){return true}else{f.facebox.settings.inited=true}f(document).trigger("init.facebox");d();var l=f.facebox.settings.imageTypes.join("|");f.facebox.settings.imageTypesRegexp=new RegExp("."+l+"$","i");if(n){f.extend(f.facebox.settings,n)}f("body").append(f.facebox.settings.faceboxHtml);var m=[new Image(),new Image()];m[0].src=f.facebox.settings.closeImage;m[1].src=f.facebox.settings.loadingImage;f("#facebox").find(".b:first, .bl, .br, .tl, .tr").each(function(){m.push(new Image());m.slice(-1).src=f(this).css("background-image").replace(/url\((.+)\)/,"$1")});f("#facebox .close").click(f.facebox.close);f("#facebox .close_image").attr("src",f.facebox.settings.closeImage)}function h(){var m,l;if(self.pageYOffset){l=self.pageYOffset;m=self.pageXOffset}else{if(document.documentElement&&document.documentElement.scrollTop){l=document.documentElement.scrollTop;m=document.documentElement.scrollLeft}else{if(document.body){l=document.body.scrollTop;m=document.body.scrollLeft}}}return new Array(m,l)}function i(){var l;if(self.innerHeight){l=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){l=document.documentElement.clientHeight}else{if(document.body){l=document.body.clientHeight}}}return l}function d(){var l=f.facebox.settings;l.loadingImage=l.loading_image||l.loadingImage;l.closeImage=l.close_image||l.closeImage;l.imageTypes=l.image_types||l.imageTypes;l.faceboxHtml=l.facebox_html||l.faceboxHtml}function j(m,l){if(m.match(/#/)){var n=window.location.href.split("#")[0];var o=m.replace(n,"");f.facebox.reveal(f(o).clone().show(),l)}else{if(m.match(f.facebox.settings.imageTypesRegexp)){c(m,l)}else{g(m,l)}}}function c(m,l){var n=new Image();n.onload=function(){f.facebox.reveal('<div class="image"><img src="'+n.src+'" /></div>',l)};n.src=m}function g(m,l){f.get(m,function(n){f.facebox.reveal(n,l)})}function b(){return f.facebox.settings.overlay==false||f.facebox.settings.opacity===null}function e(){if(b()){return}if(f("facebox_overlay").length==0){f("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')}f("#facebox_overlay").hide().addClass("facebox_overlayBG").css("opacity",f.facebox.settings.opacity).click(function(){f(document).trigger("close.facebox")}).fadeIn(200);return false}function a(){if(b()){return}f("#facebox_overlay").fadeOut(200,function(){f("#facebox_overlay").removeClass("facebox_overlayBG");f("#facebox_overlay").addClass("facebox_hide");f("#facebox_overlay").remove()});return false}f(document).bind("close.facebox",function(){f(document).unbind("keydown.facebox");f("#facebox").fadeOut(function(){f("#facebox .content").removeClass().addClass("content");a();f("#facebox .loading").remove()})})})(jQuery);


/*** Plugin : Cookie [Compressed] (Ver. 1.0) : Copyright (c) 2006 Klaus Hartl : http://plugins.jquery.com/project/cookie ***/
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};


/*** Plugin : Tipsy : http://onehackoranother.com/projects/jquery/tipsy/ ***/
(function($) {
    $.fn.tipsy = function(options) {

        options = $.extend({}, $.fn.tipsy.defaults, options);
        
        return this.each(function() {
            
            var opts = $.fn.tipsy.elementOptions(this, options);
            
            $(this).hover(function() {

                $.data(this, 'cancel.tipsy', true);

                var tip = $.data(this, 'active.tipsy');
                if (!tip) {
                    tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
                    tip.css({position: 'absolute', zIndex: 100000});
                    $.data(this, 'active.tipsy', tip);
                }

                if ($(this).attr('title') || typeof($(this).attr('original-title')) != 'string') {
                    $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
                }

                var title;
                if (typeof opts.title == 'string') {
                    title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title);
                } else if (typeof opts.title == 'function') {
                    title = opts.title.call(this);
                }

                tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);

                var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
                tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
                tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
                var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
                var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;

                switch (gravity.charAt(0)) {
                    case 'n':
                        tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
                        break;
                    case 's':
                        tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
                        break;
                    case 'e':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
                        break;
                    case 'w':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
                        break;
                }

                if (opts.fade) {
                    tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.8});
                } else {
                    tip.css({visibility: 'visible'});
                }

            }, function() {
                $.data(this, 'cancel.tipsy', false);
                var self = this;
                setTimeout(function() {
                    if ($.data(this, 'cancel.tipsy')) return;
                    var tip = $.data(self, 'active.tipsy');
                    if (opts.fade) {
                        tip.stop().fadeOut(function() { $(this).remove(); });
                    } else {
                        tip.remove();
                    }
                }, 100);

            });
            
        });
        
    };
    
    // Overwrite this method to provide options on a per-element basis.
    // For example, you could store the gravity in a 'tipsy-gravity' attribute:
    // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
    // (remember - do not modify 'options' in place!)
    $.fn.tipsy.elementOptions = function(ele, options) {
        return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
    };
    
    $.fn.tipsy.defaults = {
        fade: false,
        fallback: '',
        gravity: 'n',
        html: false,
        title: 'title'
    };
    
    $.fn.tipsy.autoNS = function() {
        return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
    };
    
    $.fn.tipsy.autoWE = function() {
        return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
    };
    
})(jQuery);


/*** Plugin : Tweet [Compressed] : http://tweet.seaofclouds.com/ ***/
(function($) {
 
  $.fn.tweet = function(o){
    var s = {
      username: ["ajfischler"],              // [string]   required, unless you want to display our tweets. :) it can be an array, just do ["username1","username2","etc"]
      avatar_size: null,                      // [integer]  height and width of avatar if displayed (48px max)
      count: 3,                               // [integer]  how many tweets to display?
      intro_text: null,                       // [string]   do you want text BEFORE your your tweets?
      outro_text: null,                       // [string]   do you want text AFTER your tweets?
      join_text:  null,                       // [string]   optional text in between date and tweet, try setting to "auto"
      auto_join_text_default: "i said,",      // [string]   auto text for non verb: "i said" bullocks
      auto_join_text_ed: "i",                 // [string]   auto text for past tense: "i" surfed
      auto_join_text_ing: "i am",             // [string]   auto tense for present tense: "i was" surfing
      auto_join_text_reply: "i replied to",   // [string]   auto tense for replies: "i replied to" @someone "with"
      auto_join_text_url: "i was looking at", // [string]   auto tense for urls: "i was looking at" http:...
      loading_text: null,                     // [string]   optional loading text, displayed while tweets load
      query: null                             // [string]   optional search query
    };
    
    if(o) $.extend(s, o);
    
    $.fn.extend({
      linkUrl: function() {
        var returning = [];
        var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a href=\"$1\">$1</a>"))
        });
        return $(returning);
      },
      linkUser: function() {
        var returning = [];
        var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a href=\"http://twitter.com/$1\">@$1</a>"))
        });
        return $(returning);
      },
      linkHash: function() {
        var returning = [];
        var regexp = / [\#]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all&from='+s.username.join("%2BOR%2B")+'">#$1</a>'))
        });
        return $(returning);
      },
      capAwesome: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/(a|A)wesome/gi, 'AWESOME'))
        });
        return $(returning);
      },
      capEpic: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/(e|E)pic/gi, 'EPIC'))
        });
        return $(returning);
      },
      makeHeart: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/(&lt;)+[3]/gi, "<tt class='heart'>&#x2665;</tt>"))
        });
        return $(returning);
      }
    });
 
    function relative_time(time_value) {
      var parsed_date = Date.parse(time_value);
      var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
      var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
      if(delta < 60) {
      return 'less than a minute ago';
      } else if(delta < 120) {
      return 'about a minute ago';
      } else if(delta < (45*60)) {
      return (parseInt(delta / 60)).toString() + ' minutes ago';
      } else if(delta < (90*60)) {
      return 'about an hour ago';
      } else if(delta < (24*60*60)) {
      return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
      } else if(delta < (48*60*60)) {
      return '1 day ago';
      } else {
      return (parseInt(delta / 86400)).toString() + ' days ago';
      }
    }
 
    return this.each(function(){
      var list = $('<ul class="tweet_list">').appendTo(this);
      var intro = '<p class="tweet_intro">'+s.intro_text+'</p>'
      var outro = '<p class="tweet_outro">'+s.outro_text+'</p>'
      var loading = $('<p class="loading">'+s.loading_text+'</p>');
      if(typeof(s.username) == "string"){
        s.username = [s.username];
      }
      var query = '';
      if(s.query) {
        query += 'q='+s.query;
      }
      query += '&q=from:'+s.username.join('%20OR%20from:');
      var url = 'http://search.twitter.com/search.json?&'+query+'&rpp='+s.count+'&callback=?';
      if (s.loading_text) $(this).append(loading);
      $.getJSON(url, function(data){
        if (s.loading_text) loading.remove();
        if (s.intro_text) list.before(intro);
        $.each(data.results, function(i,item){
          // auto join text based on verb tense and content
          if (s.join_text == "auto") {
            if (item.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
              var join_text = s.auto_join_text_reply;
            } else if (item.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)) {
              var join_text = s.auto_join_text_url;
            } else if (item.text.match(/^((\w+ed)|just) .*/im)) {
              var join_text = s.auto_join_text_ed;
            } else if (item.text.match(/^(\w*ing) .*/i)) {
              var join_text = s.auto_join_text_ing;
            } else {
              var join_text = s.auto_join_text_default;
            }
          } else {
            var join_text = s.join_text;
          };
 
          var join_template = '<span class="tweet_join"> '+join_text+' </span>';
          var join = ((s.join_text) ? join_template : ' ')
          var avatar_template = '<a class="tweet_avatar" href="http://twitter.com/'+ item.from_user+'"><img src="'+item.profile_image_url+'" height="'+s.avatar_size+'" width="'+s.avatar_size+'" alt="'+item.from_user+'\'s avatar" title="'+item.from_user+'\'s avatar" border="0"/></a>';
          var avatar = (s.avatar_size ? avatar_template : '')
          var date = '<a href="http://twitter.com/'+item.from_user+'/statuses/'+item.id+'" title="view tweet on twitter">'+relative_time(item.created_at)+'</a>';
          var text = '<span class="tweet_text">' +$([item.text]).linkUrl().linkUser().linkHash().makeHeart().capAwesome().capEpic()[0]+ '</span>';
          
          // until we create a template option, arrange the items below to alter a tweet's display.
          list.append('<li>' + avatar + date + join + text + '</li>');
 
          list.children('li:first').addClass('tweet_first');
          list.children('li:odd').addClass('tweet_even');
          list.children('li:even').addClass('tweet_odd');
        });
        if (s.outro_text) list.after(outro);
      });
 
    });
  };
})(jQuery);


/*** jQuery : Facebox : http://famspam.com/facebox/ ***/
$(document).ready(function() {
  $("a[rel*=facebox]").facebox()
});


/*** jQuery : Link Type Icons : http://cool-javascripts.com/jquery/add-icons-to-your-links-automatically-using-jquery-css.html ***/
$(document).ready(function() {
  // $(".main a[href^='/photo/']").addClass("photo").prepend("<b class=\"type\">(Photo)</b>");
});


/*** jQuery : Flickr ***/
// $(document).ready(function() {
//   // $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
//   $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=36521983538@N01&lang=en-us&format=json",
//     function(data){
//       $.each(data.items, function(i,item){
//         $("<img/>").attr("src", item.media.m).appendTo("#plug-flickr");
//       if ( i == 3 ) return false;
//     });
//   });
// });
//
//
// $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=36521983538@N01&lang=en-us&format=json&jsoncallback=?", function(data){
//   $.each(data.items, function(i,item){
//     $("<img/>").attr("src", item.media.m).appendTo("#plug-flickr")
//       .wrap("<a href='" + item.link + "'></a>");
//   });
// });

// http://www.viget.com/inspire/pulling-your-flickr-feed-with-jquery/
// $(document).ready(function() {
//   $.getJSON("http://api.flickr.com/services/feeds/groups_pool .gne?id=675729@N22&lang=en-us&format=json&jsoncallback=?", function(data){
//     $.each(data.items, function(i,item){
//       $("<img/>").attr("src", item.media.m).appendTo("#plug-flickr")
//         .wrap("<a href='" + item.link + "'></a>");
//     });
// 
//     // $("#title").html(data.title);
//     // $("#description").html(data.description);
//     // $("#link").html("<a href='"+data.link+"' target=\"_blank\">Visit the Viget Inspiration Pool!</a>");
//       //Notice that the object here is "data" because that information sits outside of "items" in the JSON feed
// 
//     // $('#images').cycle({
//     //   fx:     'fade',
//     //   speed:    'normal',
//     //   timeout:  0,
//     //   next:   '#next',
//     //   prev:   '#prev'
//     // });
//   });
// });


/*** jQuery : Tweet settings ***/
$(document).ready(function(){
  $("#plug-tweet").tweet({
    username: "ajfischler",
    join_text: "",
    // avatar_size: 32,
    count: 5,
    auto_join_text_default: "I said,", 
    auto_join_text_ed: "I",
    auto_join_text_ing: "I was",
    auto_join_text_reply: "I replied to",
    auto_join_text_url: "I was checking out",
    loading_text: "Loading tweets..."
  });
});


/*** jQuery : Tipsy Settings ***/
// $('#example-delay').tipsy({ delayIn: 0.5, delayOut: 1 });

// $(function() {
//   $('a[rel=tipsy]').tipsy({fade: true, gravity: 'n'});
// });
$(function() {
  // $('a[rel=tipsy]').tipsy({fade: true, gravity: 'n'});
  $('a span.show-tip').tipsy({ delayIn: 0.5, delayOut: 1 });
});
// $.fn.tipsy.defaults = {
//     delayIn: 0,
//     delayOut: 0.1,
//     fade: false,
//     fallback: '',
//     gravity: 'n',
//     html: false,
//     opacity: 0.8,
//     title: 'title'
// };


