/* Author:  rheinschafe.de
 * Created: 12-2010
 */

window.log = function(){
 log.history = log.history || []; 
 log.history.push(arguments);
 if(this.console){
   console.log( Array.prototype.slice.call(arguments) );
 }
};

jQuery.noConflict();
jQuery(document).ready(function($){
  
  var scrollables = $('.mod-slideshow');
  scrollables.each( function(){
    var el = $(this),
        slider = el.find('.scrollable'),
        items = el.find('.item').unwrap(),
        nav = $('<div>', {'class': 'navigation'}).html('<a class="browse prev">Zur&uuml;ck</a><a class="browse next">Vor</a>').appendTo(el);
        
    el.find('.name').each(function(){
      var name = $(this);
      if(name.text().length > 50) { name.parent().parent().addClass('name-long') };
    });
    
    var api = slider.scrollable({circular:true, easing:'easeInOutExpo', speed:600, api:true});
    
  });
  
  
  var mainmenuitems = $('#mainmenu').children('ul').children(),
      last_mainmenuitem = mainmenuitems.filter('.act');
  
  mainmenuitems.each(function(){
    var el = $(this);
    if(el.children('ul').length){
      el.addClass('with-submenu');
      el.hoverIntent({
       over: function(){
           last_mainmenuitem.removeClass('act');
           $(this).addClass('act');
         },
       out: function(){
          $(this).removeClass('act');
          last_mainmenuitem.addClass('act');
        },
       timeout: 150
      })
    }
  });
  
  var widgets_flickr = $('.widget-flickr').each(function(){
    var el = $(this);
      $.getJSON("http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&user_id=56458633@N04&api_key=519541eb5d61b94323bdaf2c35b497e4&per_page=9&page=1&format=json&jsoncallback=?",
        function(data){
          if(data.photos.total > 0){
            var images = '';
            $.each(data.photos.photo, function(i,x){
              images += '<li><a title="'+x.title+'" href="http://www.flickr.com/photos/'+x.owner+'/'+x.id+'/" target="_blank"><img src="http://farm'+x.farm+'.static.flickr.com/'+x.server+'/'+x.id+'_'+x.secret+'_s.jpg" /></a></li>';
            });
            el.html(images);
            el.find('a').slimbox({}, function(el) {
              return [el.firstChild.src.replace(/_[mts]\.(\w+)$/, ".$1"),
                     '<a href="' + el.href + '">Auf Flickr ansehen</a>'];
            });
          }
      });
  });
  
    
  var url = encodeURIComponent(document.location.href);
  var title = encodeURIComponent(document.title);  
  var socialsharing = $('.socialsharing').html('\
    <iframe frameborder="0" scrolling="no" class="twitter-share-button twitter-count-horizontal" tabindex="0" allowtransparency="true" src="http://platform0.twitter.com/widgets/tweet_button.html?count=horizontal&amp;lang=de&amp;text='+title+'&amp;url='+url+'" style="width: 110px; height: 20px;"></iframe>\
    \
    <iframe src="http://www.facebook.com/plugins/like.php?href='+url+'&amp;layout=button_count&amp;show_faces=false&amp;width=140&amp;action=like&amp;colorscheme=light&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:20px;" allowTransparency="true"></iframe>\
    \
    <div class="g-plusone" data-size="medium" data-annotation="inline" data-width="200"></div>\
    ');
    
    window.___gcfg = {lang: 'de'};

    (function() {
      var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
      po.src = 'https://apis.google.com/js/plusone.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
  
});

//56458633@N04
//http://api.flickr.com/services/rest/?method=flickr.photos.search
//&api_key=519541eb5d61b94323bdaf2c35b497e4&tags=cat&per_page=10&page=1&format=json&jsoncallback=?
