/* ---------------------------------------------------------------- 
  safety plugin
---------------------------------------------------------------- */
jQuery(function($) {
  
  $.fn.safety = function(options) {
    var opts = $.extend({}, $.fn.safety.defaults, options);
    return this.each(function() {
      var self = $(this);
      var divs = self.children('div');
      // init
      $('img', divs).wrap('<div class="fotogalery-singl" />').after('<a href="#" class="arrow-left"><span></span></a><a href="#" class="arrow-right"><span></span></a>');
      
      var links = $('.fotogalery-singl > a', divs);
      
      divs.hide().filter(':first').show();
      
      links.click(function () {
        
        if ($(this).hasClass('arrow-right') == true) { // next
          divs.hide();
          if ($(this).parent().parent().is('div:last-child') == false) { // normal
            $(this).parent().parent().next('div').show();
          }
          else { // last
            self.children('div:first').show();
          }
        }
        else { // prev
          divs.hide();
          if ($(this).parent().parent().is(':first-child') == false) { // normal
            $(this).parent().parent().prev('div').show();
          }
          else { // first
            self.children('div:last').show();
          }
        }
        
        return false;
      });
    });
  };
  // safety defaults
  $.fn.safety.defaults = {
    
  };
  
});