// Create Bookmark Link
function CreateBookmarkLink(){title=(document.title);url=(document.URL);if(window.sidebar){window.sidebar.addPanel(title,url,"");}else if(window.external){window.external.AddFavorite(url,title);}else if(window.opera&&window.print){return true;}}

// IE Button-Bug Fix (ieFixButtons)
;jQuery.fn.ieFixButtons=function(){return/MSIE[567]\./i.test(window.navigator.userAgent)?this.find('button[type=submit]').click(function(){jQuery(this.form).bind('submit',{button:jQuery(this)},function(event){var $button=event.data.button;var m=$button.get(0).outerHTML.match(/value\s*=\s*['"]([^'"]*)['"]/);var val=(m?m[1]:'');var $input=jQuery('<input type="hidden" '+
($button.attr('name')?'name="'+$button.attr('name')+'" ':'')+'" value="'+val+'" />');jQuery(this).append($input);jQuery.each(jQuery(this).find('button'),function(){jQuery(this).attr('name','');});});}).end():this;};

// IE Overflow-Bug Fix (fixOverflow)
;(function($){$.fixOverflow=function(padding){if(!$.browser.msie){return this;}else{return this.each(function(){if(this.scrollWidth>this.offsetWidth){$(this).css({'overflow-y':'hidden','padding-bottom':padding+'px'});}});}};})(jQuery);

//
// jQuery DOM-load

$(function(){

	$('body').ieFixButtons();
	$('pre').fixOverflow();

// 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
  });

  $(".nav-main ul").superfish({hoverClass:'sfhover',pathClass:'sfactive',pathLevels:2,delay:700,animation:{height:'show',opacity:'show'},speed:'normal',autoArrows:false,dropShadows:false,disableHI:false});
  $(".nav-main 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});

// Input Title-Hint
  //$('input:text').hint();
  $('input.hint[title!=""]').hint();

// Link List Collapser/Expander
  $('.linklist > li > a + ul').add('.listcollapse > li > a + ul').each(function() {
    $(this).parent().addClass('parent');
  });
  $(".linklist > li.parent > a + ul").add('.listcollapse > li.parent > a + ul').slideUp("fast");
  $(".linklist > li.parent > a").add('.listcollapse > li.parent > a').click(function() {
    $(this).find("+ ul").slideToggle("fast");
    $(this).toggleClass("closeit");
    return false;
  });

// Collapsible/Expandable
  $('.collapse > h3').add('.collapse > h4').each(function() {
    $(this).addClass('parent');
  });
  $(".collapse > h3.parent + div").add(".collapse > h4.parent + div").slideUp("fast");
  $(".collapse > h3.parent").add(".collapse > h4.parent").wrapInner("<a href=\"#\"></a>");
  $(".collapse > h3.parent > a").add(".collapse > h4.parent > a").click(function() {
    $(this).parent().find("+ div").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
  $('.pngfix').pngFix();

// Tool Tip
  $('.ceetip').ceetip();

// Box Preview
	$(".lightbox").ceebox();
	$(".lightbox-dark").ceebox({boxColor:"#333"});

// jQ - Tabs
  $("ul.jtabs").tabs("div.panes > div");

// jQ - Accordion
  $('.sb-box .itemlist').pager('li', {
    navId: 'nav3',
    navAttach: 'prepend',
    navClass: 'pagination-pager'
    //prevText: 'Previous',
    //nextText: 'Next'
  });
  $("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});
	
	jQuery(function($) {
		$("img.reflect").reflect({height:0.15, opacity:0.25});
	});
	
	$('#productbuttons li > a').hover(function() {
		$(this).stop().animate({ backgroundColor : "#222" , paddingLeft: "52px" }, 150);            
  }, function() {
    $(this).stop().animate({ backgroundColor : "#444" , paddingLeft: "50px" }, 150);
	});
  
	$("#shippingregion").click(function (){ 
		$().ceebox();
		var shippingpopup = "<a href='/js/ajax/shipregion_ceebox_content.php' title=''></a>"
		$.fn.ceebox.overlay();
		$.fn.ceebox.popup(shippingpopup,{htmlWidth:550,htmlHeight:335,titles:false,fadeIn:100,fadeOut:100,margin:125});
		return false;
  });
  
  $(".tooltip").tooltip({ effect: 'slide'});
  
	// News feeds
	var $nf = $('.newsfeed');
	if ($nf.length) {
		var limit, feed
		$nf.each(function() {
			var $self = $(this);
			limit = $self.attr('data-rssfeed-item-limit');
			feed = $self.find('a').attr('href');
			$(this).rssfeed(feed, { limit: limit ? limit : 10 });
		});
	}
  
});

//
// jQuery Validation - Additional Methods

jQuery.validator.addMethod("maxWords", function(value, element, params) {
    return this.optional(element) || value.match(/\b\w+\b/g).length < params;
}, jQuery.format("Please enter {0} words or less."));
jQuery.validator.addMethod("minWords", function(value, element, params) {
    return this.optional(element) || value.match(/\b\w+\b/g).length >= params;
}, jQuery.format("Please enter at least {0} words."));
jQuery.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];
}, jQuery.format("Please enter between {0} and {1} words."));
jQuery.validator.addMethod("alphanumeric", function(value, element) {
  return this.optional(element) || /^\w+$/i.test(value);
}, "Letters, numbers, spaces or underscores only please.");  
jQuery.validator.addMethod("lettersonly", function(value, element) {
  return this.optional(element) || /^[a-z]+$/i.test(value);
}, "Letters only please."); 
jQuery.validator.addMethod("nowhitespace", function(value, element) {
  return this.optional(element) || /^\S+$/i.test(value);
}, "No white space please.");
jQuery.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)."); 
jQuery.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)."); 
jQuery.validator.addMethod("dateUS", function(value, element) {
  return this.optional(element) || /^(([0-9]{2})+\-([0-9]{2})+\-([0-9]{4}))$/i.test(value);
}, "Please format the date properly (07-23-2009)."); 
jQuery.validator.addMethod("dateUSREAL", function(value, element) {
  return this.optional(element) || /^((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)\-([12]{1})([019]{1})([0-9]{1})([0-9]{1}))$/i.test(value);
}, "Please enter a valid date (07-23-2009)."); 
jQuery.validator.addMethod("dateUS2", function(value, element) {
  return this.optional(element) || /^(([0-9]{2})+\/([0-9]{2})+\/([0-9]{4}))$/i.test(value);
}, "Please format the date properly (07/23/2009).");
jQuery.validator.addMethod("dateUS2REAL", function(value, element) {
  return this.optional(element) || /^((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)\/([12]{1})([019]{1})([0-9]{1})([0-9]{1}))$/i.test(value);
}, "Please enter a valid date (07/23/2009).");
jQuery.validator.addMethod("isbn", function(value, element) {
  return this.optional(element) || /^[0-9Xx\-]+$/i.test(value);
}, "Please format ISBN properly."); 
jQuery.validator.addMethod("cleaninput", function(value, element) {
  return this.optional(element) || /^[\w\s\!\@\#\$\%\&\*\(\)\-\[\]\:\;\u0022\u0027\,\.\?\/]+$/i.test(value);
}, "Letters, numbers, spaces or common punctuation only please.");
jQuery.validator.addMethod("cleanname", function(value, element) {
  return this.optional(element) || /^[\w\s\-\.]+$/i.test(value);
}, "Letters, numbers, spaces, hyphens or periods only please.");
jQuery.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>");
jQuery.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"
);
jQuery.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); 
}, jQuery.validator.messages.email);
jQuery.validator.addMethod("password", function(value, element) {
  return this.optional(element) || /^[a-zA-Z0-9\@\#\$\%\&]+$/i.test(value);
}, "Only alphanumeric and the following characters are allowed - @,#,$,%,&");

jQuery.validator.addMethod("firstname", function(value, element) {
  return this.optional(element) || /^[a-zA-Z]+(([\.\-\s\'][a-zA-Z])?[a-zA-Z]*)*$/i.test(value);
}, "This format is now allowed. Please revise.");

jQuery.validator.addMethod("lastname", function(value, element) {
  return this.optional(element) || /^[a-zA-Z]+(([\,\.\-\s\'][a-zA-Z])?[a-zA-Z]*)+[\.]*$/i.test(value);
}, "This format is now allowed. Please revise.");

