$(document).ready(function() {
  
  
  
  
  
  $('.jumpMenu').change(function() {
    
    var url=$(this).val();
    
    if(url=='') {
      $(this).find('option:first').attr('selected','selected');
      return false;
    }
    
    window.location=url;
    
  });
  
  
  $('.dropdown').hover(function() {
    $(this).stop(false,false);
  }, function() {
    
    $(this).animate({ opacity: '1' }, 300, function() {
      $(this).hide();
    });
    
  });
  
  $('.submenu li a').hover(function() {
    
    $(this).animate({ "padding-left": '40px'} , 100);
    
  }, function() {
    
    $(this).animate({ "padding-left": '35px'} , 100);
    
  });
  
  
  // H1 Image Replacement
  $('h1').each(function() {
    
    var text=$(this).html();
    
    var imageurl='/index.php?mode=imageText&fontsize=22&foreground=800000&background=ededed&text=' + urlencode(text);
    
    $(this).before('<img src="' + imageurl + '" border="0" />').remove();
    
  });
  
  // Submenu highlighting
  $('ul.submenu li a[href$="' + shorturl + '"]').addClass('selected').parents('li').addClass('selected');

  if(parentmenu != '') {
    $('#menu a[href^="' + parentmenu + '"]').addClass('selected');
  }
  
  
  
  $('.imagegallery').each(function() {
  
    $(this).find('.slides').cycle({
      
      fx:       'scrollRight',
      timeout:   6000,
      after:     function() {
          $(this).parents('.imagegallery').find('.caption').html(this.alt);
      }
    
    });

  });
  
  
  
  // Expander
  $('.expander').each(function() {
    
    var html=$(this).html();
    html+= '<p><a href="#" class="expander_close">Close</a></p>';
    
    $(this).html(html);
    
    $(this).before('<p><a href="#" class="expander_open">Read more</a></p>');
    $(this).hide();
    
  });
  
  $('.expander_open').live('click',function(e) {
    
    e.preventDefault();

    $(this).parent().next().show();
    
    $(this).hide();
    
  });
  
  $('.expander_close').live('click',function(e) {
    
    e.preventDefault();

    $(this).parent().parent().hide();
    $(this).parent().parent().prev().find('.expander_open').show();
  });
  
  
  
  
  
  
  $('.facebox').facebox();
  
  
  
  // Text size changer
  
  // Initial load
  if(fontsize == 2) $('.column-middle').css('font-size','1.2em');
  if(fontsize == 3) $('.column-middle').css('font-size','1.5em');
  
  // Change links
  $('#textsize1').click(function(e) {
    e.preventDefault();
    $('.column-middle').css('font-size','1em');
    $.get('/index.php?mode=fontsize&fontsize=1');
  });
  
  $('#textsize2').click(function(e) {
    e.preventDefault();
    $('.column-middle').css('font-size','1.2em');
    $.get('/index.php?mode=fontsize&fontsize=2');
  });
  
  $('#textsize3').click(function(e) {
    e.preventDefault();
    $('.column-middle').css('font-size','1.5em');
    $.get('/index.php?mode=fontsize&fontsize=3');
  });
  
  
  // Emptyblank
  $('input[type="text"].emptyblank').each(function() {
    
    if($(this).val() == '') $(this).attr('value',$(this).attr('title')); // initially on load
    
    $(this).focus(function() {
      if($(this).val() == $(this).attr('title')) {
        $(this).attr('value','');
      }
    });
    
    $(this).blur(function() {
      if($(this).val() == '') {
        $(this).attr('value',$(this).attr('title'));
      }
    })
    
  });
  
  $('marquee').marquee().mouseover(function() {
    
    $(this).trigger('stop');
    
  }).mouseout(function() {
    
    $(this).trigger('start');
    
  });
  
  
});


function urlencode (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

    str = (str+'').toString();
    
    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
