/* Author: Roman
 * Usage:
 *   jQuery(document).ready(function($){
 *       $('body').links_rot();
 *   });
 */
(function($){
 function rot13(c){
    return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
 }

 $.fn.links_rot = function(text){
    var schemes = 'znvygb:,uggcf://,uggc://,sgc://,sgcf://,fsgc://';
    this.find('a[href^="'+schemes.replace(/,/g, '"],a[href^="')+'"]').each(function(){
        if(text)$(this).html($(this).html().replace(/%[0-9a-f]{2}/ig, decodeURIComponent).replace(/[a-z]/ig, rot13));
        $(this).attr('href', $(this).attr('href').replace(/%[0-9a-f]{2}/ig, decodeURIComponent).replace(/[a-z]/ig, rot13));
    });
    return this
 }
})(jQuery);

function setupcycle(name){
  $('.'+name).cycle();
  var next = new Function("$('."+name+"').cycle('next'); return false"), prev = new Function("$('."+name+"').cycle('prev'); return false");
  $('.'+name+'-next').click(next);
  $('.'+name+'-prev').click(prev);
}
jQuery(document).ready(function($) {
    $('.slider-link').click(function() {
        var previous = $('.slider:visible'), next = $('#slide-' + $(this).attr('href').substr(1));
        if(next.is(':visible')) return false;
        $('.slideinfo .slider-link').removeClass('active').removeClass('active');
        $(this).parents('.slideinfo').find('.slider-link').addClass('active');
        if(previous.is(':visible'))
            previous.toggle("slide", {direction: "right"}, 500, function(){
                next.toggle("slide", {direction: "right"}, 500)
            });
        else
            next.toggle("slide", {direction: "right"}, 500);
        return false;
   });
   if($.fn.cycle) {
    setupcycle('slideshow-cycle');
   }
   if(typeof Boxy!='undefined'){
     Boxy.DEFAULTS.title = 'Portfolio';
     $('.portfolio-list a').click(function(){
       Boxy.load(this.href, {
        x: 200,
        y: 200,
        afterShow: function(){
            setupcycle('slideshow-cycle');
            $(document).bind('keyup.escape', function(e){
                if(27 == e.which) {
                    Boxy.get($('#portfolio-item').get()).hide();
                    Boxy.get($('#portfolio-item').get()).getInner().remove();
                    $(document).unbind('keyup.escape');
                }
            });
        }
       });
       return false;
     });
   }
   $('script').remove();
   $('body').links_rot(1);
   $('.slider-link[href="'+location.hash+'"]').click();
  });

