//
// jQuery DOM-load

$(function(){

// Navigation Drop-Menus
  $("#nav-account ul").add("#nav-menu ul").superfish({ 
    hoverClass:    'sfhover',          // the class applied to hovered list items 
    pathClass:     'sfactive',         // the class you have applied to list items that lead to the current page 
    pathLevels:    2,                  // the number of levels of submenus that remain open or are restored using pathClass 
    delay:         700,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
    animation:     {height:'show',opacity:'show'},    // an object equivalent to first parameter of jQueryâ€™s .animate() method 
    speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQueryâ€™s .animate() method 
    autoArrows:    false,              // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
    dropShadows:   false,              // completely disable drop shadows by setting this to false 
    disableHI:     false               // set to true to disable hoverIntent detection 
  });
  
  $("#nav-menu ul ul").superfish({ 
    hoverClass:'sfhover',pathClass:'sfactive',pathLevels:1,delay:700,animation:{width:'show',height:'show',opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false,disableHI:false
  });

  $(".nav-default ul").add(".nav-menu2 ul").add(".nav-dropmenu ul").superfish({ 
    hoverClass:'sfHover',pathClass:'sfActive',pathLevels:2,delay:700,animation:{height:'show',opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false
  });
  $(".nav-default ul").add(".nav-menu2 ul").add(".nav-dropmenu ul").superfish({ 
    hoverClass:'sfHover',pathClass:'sfActive',pathLevels:1,delay:700,animation:{width:'show',height:'show',opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false,disableHI:false
  });
  $(".nav-default ul").add(".nav-menu2 ul").add(".nav-dropmenu ul").superfish({ 
    hoverClass:'sfHover',pathClass:'sfActive',pathLevels:2,delay:700,animation:{height:'show',opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false,disableHI:false
  });

$("p").animate({
      "opacity": "show"
    }, "slow", "easein");

// Input Title-Hint
  //$('input:text').hint();

// Link List Collapser/Expander
  $('.linklist > li > a + ul').each(function() {
    $(this).parent().addClass('parent');
  });
  $(".linklist > li.parent > a + ul").slideUp("fast");
  $(".linklist > li.parent > a").click(function() {
    $(this).find("+ ul").slideToggle("fast");
    $(this).toggleClass("closeit");
    return false;
  });

// Pullquote Creator
  $('span.pullquote').each(function() {
    text = $(this).text();
    text=text.replace( /\((.*)\)/gi, " " );
    if ($(this).is(".right")) 
      $(this).parent().before('<blockquote class="pullquote right"><p>'+ text +'</p></blockquote>');
    else
      $(this).parent().before('<blockquote class="pullquote"><p>'+ text +'</p></blockquote>');
  });

// pngFix
  $(document).pngFix();

// Box Preview
  $(".boxpreview").fancybox({ 'zoomSpeedIn': 5, 'zoomSpeedOut': 5, 'overlayShow': true });

});



//
// jQuery Validation - Additional Methods

$.validator.addMethod("maxWords", function(value, element, params) {
    return this.optional(element) || value.match(/\b\w+\b/g).length < params;
}, "Please enter {0} words or less.");
$.validator.addMethod("minWords", function(value, element, params) {
    return this.optional(element) || value.match(/\b\w+\b/g).length >= params;
}, "Please enter at least {0} words.");
$.validator.addMethod("rangeWords", function(value, element, params) {
    return this.optional(element) || value.match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1];
}, "Please enter between {0} and {1} words.");
$.validator.addMethod("alphanumeric", function(value, element) {
  return this.optional(element) || /^\w+$/i.test(value);
}, "Letters, numbers, spaces or underscores only please.");  
$.validator.addMethod("lettersonly", function(value, element) {
  return this.optional(element) || /^[a-z]+$/i.test(value);
}, "Letters only please."); 
$.validator.addMethod("nowhitespace", function(value, element) {
  return this.optional(element) || /^\S+$/i.test(value);
}, "No white space please.");
$.validator.addMethod("dateW3C", function(value, element) {
  return this.optional(element) || /^(([0-9]{4})+\-([0-9]{2})+\-([0-9]{2}))$/i.test(value);
}, "Please format the date properly (2009-07-23)."); 
$.validator.addMethod("dateREAL", function(value, element) {
  return this.optional(element) || /^(([12]{1})([019]{1})([0-9]{1})([0-9]{1})\-(01|02|03|04|05|06|07|08|09|10|11|12)\-(01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))$/i.test(value);
}, "Please enter a valid date (2009-07-23)."); 
$.validator.addMethod("isbn", function(value, element) {
  return this.optional(element) || /^[0-9Xx\-]+$/i.test(value);
}, "Please format ISBN properly."); 
$.validator.addMethod("cleaninput", function(value, element) {
  return this.optional(element) || /^[\w\!\@\#\$\%\&\*\(\)\-\[\]\:\;\"\'\,\.\?\/]+$/i.test(value);
}, "Letters, numbers, spaces or common punctuation only please.");  
$.validator.addMethod("phonenumber", function(value, element) {
  return this.optional(element) || /^[\d\s\-\.\+\(\)\#\*]+$/i.test(value);
}, "Numbers, spaces and the following punctuation only please: <code>-.+()#*</code>");  
$.validator.addMethod(
  "dateITA",
  function(value, element) {
    var check = false;
    var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
    if( re.test(value)){
      var adata = value.split('/');
      var gg = parseInt(adata[0],10);
      var mm = parseInt(adata[1],10);
      var aaaa = parseInt(adata[2],10);
      var xdata = new Date(aaaa,mm-1,gg);
      if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
        check = true;
      else
        check = false;
    } else
      check = false;
    return this.optional(element) || check;
  }, 
  "Please enter a correct date"
);
$.validator.addMethod("email2", function(value, element, param) {
  return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value); 
}, $.validator.messages.email);

