/* Add class blank to pdf, doc and external links, and open class blank in a new window */
$(function() {
 $('a[href$=\\.pdf]').add('a[href$=\\.doc]').add('a[href^=http\\:]').add('a[href^=https\\:]').addClass('blank');
 $('a[href^=http\\:\\/\\/e1\\.simplecdn\\.net]').add('a[href^=http\\:\\/\\/videos\\.serif\\.com]').add('a[href^=http\\:\\/\\/www\\.serifwebresources\\.com]').removeClass('blank');
 $('a.blank').click(function(){ window.open(this.href); return false; });
});

/* Set jQuery LocalScroll */
$(function($) {
 $.localScroll({
  duration: 1000,
  hash: false });
 });

/* Show and hide 'back to top' link based on distance from the top */
 $("#back-top").hide();
 $(function () {
  $(window).scroll(function () {
   if ($(this).scrollTop() > 800) {
    $('#back-top').fadeIn();
   } else {
    $('#back-top').fadeOut();
   }
  });
 });

/* FancyBox */
$(document).ready(function () {
 $("a.fancybox").fancybox();
 $('a.fancybox-iframe').each(function () {
  if ($(this).attr('href').match(/width=[0-9]+/i))
   { var dWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=', '')); }
  else
   { var dWidth = 550; }
  if ($(this).attr('href').match(/height=[0-9]+/i)) { var dHeight = parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=', '')); }
  else
   { var dHeight = 350; }
   $(this).fancybox({ 'width': dWidth, 'height': dHeight, 'type': 'iframe', 'scrolling': 'auto' });
  });
 $("a.fancybox-video").fancybox({ 'type': 'iframe', 'width': 768, 'height': 480, 'scrolling': 'no' });
});

/* jQuery Hoverintent Drowndown Menu */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}
if(p==this){return false;}
var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}
if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

$(function(){$('ul#nav > li').hoverIntent({sensitivity:7,interval:50,over:showMenu,timeout:300,out:hideMenu})});function showMenu(){$(this).addClass('active'); $(this).find('.sub').fadeIn(100)};function hideMenu(){$(this).removeClass('active'); $(this).find('.sub').fadeOut(100)};

/* Email/Password Fields */
$(function () {
 $('#password').hide(); $('#password-clear').show(); $('#password-clear').focus(function () { $('#password-clear').hide(); $('#password').show(); $('#password').focus() }); $('#password').blur(function () { if ($('#password').val() == '') { $('#password-clear').show(); $('#password').hide() } }); $('#email').focus(function () {
  if (($('#email').val() == 'Email Address') || ($('#email').val() == 'E-Mail-Adresse') || ($('#email').val() == 'Adresse e-mail')) {
  $(this).val("")}});$('#email').blur(function(){if($('#email').val()==''){$(this).val("Email Address")
  }
});

/* Locale change jQuery drowndown menu */
$(document).ready(function(){var url=location.href;if(url.indexOf('checkout')==-1){enableLocaleMenu()}});function enableLocaleMenu(){$("#swaplocale").click(showLocaleMenu)}function showLocaleMenu(){$("#localeList").fadeIn(200);$("#localeList").bind("mouseleave",hideLocaleMenu)}function hideLocaleMenu(){$("#localeList").fadeOut(500)}

/* Country Drop Down styling */
$(function(){ $("select.isoLocationDdl").uniform(); $("#uniform-FIsoCountry").hover (function () {$(".isoLocationDdl").css({visibility:"visible"});})});
$(function(){ $("select.isoLanguageDdl").uniform(); $("#uniform-FLanguage").hover (function () {$(".isoLanguageDdl").css({visibility:"visible"});})});

/* jQuery mini basket */
$(document).ready(function(){var url=location.href;if((url.indexOf('AddToCart')>-1)&&(url.indexOf('shoppingbasket')==-1)){$("#basketSummaryMenu").fadeIn(500).fadeTo(2000,1).fadeOut(1000)}if(url.toLowerCase().indexOf('shoppingbasket')==-1){enableMiniBasket()}});function enableMiniBasket(){$("#cartMessage").bind("mouseenter",showMiniBasket);$("#cartMessage").bind("mouseleave",hideMiniBasket)}function showMiniBasket(){$("#basketSummaryMenu").fadeIn(200);$("#basketSummaryMenu").bind("mouseleave",hideMiniBasket)}function hideMiniBasket(){$("#basketSummaryMenu").fadeOut(200)}})

/* ISO code change via DropDown list */
 function onIsoCountryChanged(t_currentLocation, t_queryString) {
  var SelectedVal = $("#FIsoCountry").val();
  parent.location.href = t_currentLocation + '?isoCode=' + SelectedVal + t_queryString;
}

 function onLanguageChanged(t_currentLocation, t_queryString)
 {
  var SelectedVal = $("#FLanguage").val();
  window.location.href = t_currentLocation + '?displayLanguage=' + SelectedVal + t_queryString;
 }

 /* Sticky Footer background image fix */
 $(function () {
     var newHeight
     newHeight = ($(window).height()) - (($('#headerNav').height()) + ($('#topnav').height()) + ($('.footer').height()) + ($('#footer-links').height()));
     $('.page-bg').css({ 'min-height': (newHeight - 25) + 'px' });
 }
)

 /* International message hide on click. */
 $('.close').click(function () {
     $("#locale-message").slideUp();
 })

