$(window).load( function () { // ON PAGE LOAD (gfx, css, etc..):
 
 /* Handlers for swapping value with empty string and vice versa
    a.k.a. "click-to-clear effect" */
 $('.blackInput').live('focus', function () {
  if( $(this).val() === $(this).attr('title') ) {
    $(this).val('');
   }
 });
 $('.blackInput').live('blur', function () {
  if( $(this).val() === '' ) {
   $(this).val( $(this).attr('title') );
  }
 });
 
 $(".fBox").fancybox();
 // ^ Generic lightbox
 
 // Lightbox with scroll area and scrolling effect:
 $('.pBox').fancybox( {
  'onComplete': function () {
   $prav = $('#boxScroll');
   $prav.show();
   $prav.jScrollPane({scrollbarWidth:7, scrollbarMargin:12, showArrows:true});
   $para = $(this).attr('title');
   if($para) {
    $prav[0].scrollTo($para);
   }
  }
 } );
 
 // Forgot Password dialog handler:
 $('#forgot', $('.header')).click( function () {
  $.fancybox.showActivity();
  // ^ indicate background process
  $.get('/inc/box.forgot.php', function (data) {
   $.fancybox.hideActivity();
   var dlgSkin = $('#fancybox-inner');
   // ^ cache the skin object
   $.fancybox( data, {
    'onStart': function () {
     dlgSkin.addClass('dialog');
     // ^ style the lightbox like a dialog box
    }, 
    'onComplete': function () {
     var txt = $(':text', $('#dlgForgot'));
     // ^ cache the input field
     txt.focus();
     // ^ highlight the input field
     txt.change( function () {
     // ^ if the user does input something..
      var mail = $(this).val();
      mail = $.trim(mail);
      if(mail.length > 0) {
      // ^ ..and it isn't just spaces
       $('a', $('#dlgForgot')).click( function () {
       // ^ handle the input..
        $.fancybox.showActivity();
        $.get('/reminder.php', { mail: mail }, function (data) {
         $.fancybox.hideActivity();
         $.fancybox(data);
        });
       });
      }
     });
    },
    'onClosed': function () {
     dlgSkin.removeClass('dialog');
     // ^ clear dialog styling
    }
   } );
  });
 });
 
 // Search Products handler:
 $(':text', $('#srch')).live('keydown', function (event){
  var code = event.keyCode || event.which;
  if(code == 13) { // if [Enter] pressed
   var term = $.trim($(this).val());
   // ^ remove whitespaces and cache search term
   if(term.length > 2) { // min. 3 characters
    $(location).attr('href', 'http://www.himtexcompany.com/katalog.php#name=srch&term=' + encodeURI(term));
    // ^ change to http://localhost/katalog.php#name=srch&term=
   }
  }
 });
 
 // MailTo handler:
 $('a[href^="mailto"]').click( function (event) {
  event.preventDefault(); // prevent default Email client from firing
  var mailTo = $(this).attr('href');
  mailTo = mailTo.substr(7); // strip 'mailto:'
  $.fancybox( { 'href': '/inc/box.mailto.php', 'hideOnOverlayClick': false, 'onComplete': function () {
    $('em', $('#dlgMailTo')).html( mailTo );
    $('#inIme', $('#dlgMailTo')).focus();
   }
  } );
 });
 
});

