/*
 * This plugin is a modified version of jQuery 'onImagesLoaded' plugin v1.1.0
 *
 * Copyright (c) Cirkuit Networks, Inc. (http://www.cirkuit.net), 2008.
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *   */

(function($){
  $.fn.onImagesLoad = function(options){
    if (this.length > 1) { // assumption: if only one image it's the default'
      var self = this;
      self.opts = $.extend({}, $.fn.onImagesLoad.defaults, options);
      self.bindEvents = function($imgs, container, callback){
        if ($imgs.length === 0){ //no images were in selection. callback based on options
          if (self.opts.callbackIfNoImagesExist && callback){
            callback(container);
          }
        }
        else {
          var loadedImages = [];
          if (!$imgs.mnjQuery){
            $imgs = $($imgs);
          }
          $imgs.each(function(i){
            var orgSrc = this.src;
            if (!$.browser.msie) {
              this.src = ""; //ie will do funky things if this is here (show the image as an X, only show half of the image, etc)
            }
            $(this).bind('load error', function(e){
              if (e.type == 'error'){
                $(this).addClass('mn_brokeImg')
              }
              if (mnjQuery.inArray(i, loadedImages) < 0){ //don't double count images
                loadedImages.push(i); //keep a record of images we've seen
                if (loadedImages.length == $imgs.length){
                  if (callback){
                    callback(container);
                  }
                }
              }
            });
            if (!$.browser.msie) {
              this.src = orgSrc; //needed for potential cached images
            }
            else if (this.complete || this.complete === undefined){
              this.src = orgSrc;
            }
            //failsafe to trigger callback if load/error doesn't fire on every image
            setTimeout(function(){
              if (mnjQuery.inArray(i, loadedImages) < 0){
                loadedImages.push(i);
                if (loadedImages.length == $imgs.length){
                  if (callback){
                    callback(container);
                  }
                }
              }
            },15000)
          });
        }
      };

      var imgAry = []; //only used if self.opts.selectorCallback exists
      self.each(function(){
        if (self.opts.itemCallback){
          var $imgs;
          if (this.tagName == "IMG"){
            $imgs = this;
          } //is an image
          else {
            $imgs = $('img', this);
          } //contains image(s)
          self.bindEvents($imgs, this, self.opts.itemCallback);
        }
        if (self.opts.selectorCallback){
          if (this.tagName == "IMG"){
            imgAry.push(this);
          } //is an image
          else { //contains image(s)
            $('img', this).each(function(){
              imgAry.push(this);
            });
          }
        }
      });
      if (self.opts.selectorCallback){
        self.bindEvents(imgAry, this, self.opts.selectorCallback);
      }
      return self.each(function(){}); //dont break the chain
    }
  };

  //DEFAULT OPTIONS
  $.fn.onImagesLoad.defaults = {
    selectorCallback: null,        //the function to invoke when all images that $(yourSelector) encapsulates have loaded (invoked only once per selector. see documentation)
    itemCallback: null,            //the function to invoke when each item that $(yourSelector) encapsulates has loaded (invoked one or more times depending on selector. see documentation)
    callbackIfNoImagesExist: false //if true, the callbacks will be invoked even if no images exist within $(yourSelector).
  //if false, the callbacks will not be invoked if no images exist within $(yourSelector).
  };
})(mnjQuery);




var Verify =
{
  init: function(thisImg)
  {
    if (thisImg.className != 'mn_checkSmall'){
      $(thisImg).removeClass('mn_check');
      $(thisImg).css({
        'width': 100,
        'height': 100
      });
    }
    var defaultImg = new Image();
    if (window.location.protocol == "https:")
    {
      defaultImg.src = 'https://a248.e.akamai.net/f/248/35975/5d/i.mallnetworks.com/images/global/mn/default.gif';
    }
    else
    {
      defaultImg.src = 'http://a786.g.akamai.net/f/786/35975/5d/i.mallnetworks.com/images/global/mn/default.gif';
    }

    var oldImg = new Image();
    oldImg.src = thisImg.src;

    thisImg.src = defaultImg.src;
        
  // if (thisImg.className != 'mn_checkSmall'){
  //     $(thisImg).removeClass('mn_check');
  //     $(thisImg).css({'width': 100, 'height': 100});
  //  }
  }

};

////////////////////


// removes last border image from search results feature deals if only 1 deal
var FeatHideLast =
{
  init: function() {
    if ($(".mn_featureStoreA li").length) {
      var lastLi = $(".mn_featureStoreA li:last").get(0).firstChild;
      $(lastLi).hide();
    }
  }
};


// image swapper - PD, PC pages
var ImageSwap =
{
  init: function() {
    if ($('.mn_checkBig').length > 1){
      mnjQuery('.mn_prdDetlImg').cycle({
        fx:     'scrollDown',
        speed:  'fast',
        timeout: 0,
        pager:  '.mn_prdDetlThumb',
        width: 150,
        pagerAnchorBuilder: function(idx, slide) {
          // return sel string for existing anchor
          return '.mn_prdDetlThumb li:eq(' + (idx) + ') a';
        }
      });
    }
  }
};


/****/


// sorting menus on search page
var MenuSort =
{
  init: function() {
    $('.mn_sortButton').hide();
   
    $('.mn_sortMenu, .mn_showMenu').change(function() {
      
      var goSort = '';
      var myParent = this.parentNode;
      $(myParent).children('input').each(function(i){
        if ($(this).attr('type') == 'hidden'){
          var myName = $(this).attr('name');
          var myValue = $(this).attr('value');
          goSort = goSort + '&' + myName + '=' + myValue;
        }
      });
      goSort = goSort.slice(1);
        
        
      if (myParent.id == 'mn_sortDown'){
        location.href = '?' + goSort + '&sort=' + this.options[this.selectedIndex].value;
      }
      else {
        location.href = '?' + goSort + '&rows=' + this.options[this.selectedIndex].value;
      }
    });
  }
};

    
/****/
    
    
// firefox facet word wrap fix
var Wordwrap =
{
  init: function()
  {
    var facet = Core.getElementsByClass("mn_opq");
    for (var i=0; i < facet.length; i++)
    {
      var howLong = facet[i].lastChild.nodeValue;
      if (howLong.length > 18 && howLong.match(" ") == null)
      {
        var splitIt = howLong.split("");
        splitIt.splice(24,0," ");
        facet[i].lastChild.nodeValue = splitIt.join("");
      }
    }
  }
		
};

    
/****/

    
// top feature store container, search page 
var Resize =
{
  init: function()
  {
    var feature = Core.getElementsByClass("mn_featureStore");
    for (var i=0; i < feature.length; i++)
    {
      if (feature.length == 2)
      {
        feature[i].style.width = "48%";
      }
      if (feature.length == 3)
      {
        feature[i].style.width = "33%";
      }
      else if (feature.length == 4)
      {
        feature[i].style.width = "24.5%";
      }
      else if (feature.length == 5)
      {
        feature[i].style.width = "19.5%";
      }
      else if (feature.length == 6)
      {
        feature[i].style.width = "16.5%";
      }
    }
  }
  
};
        
    
/****/
    
    
// show hide facets
var Accordion =
{
  init: function()
  {
    var accordions = Core.getElementsByClass("mn_accordion");
    var foldLinks = Core.getElementsByClass("mn_moreLinks");
    for (var n = 0; n < foldLinks.length; n++)
    {
      Core.addEventListener(foldLinks[n], "click", Accordion.clickListener);
    }
  },

  collapse: function(fold)
  {
    Core.removeClass(fold, "mn_expanded");
    Core.addClass(fold, "mn_collapsed");
  },

  expand: function(fold)
  {
    Core.removeClass(fold, "mn_collapsed");
    Core.addClass(fold, "mn_expanded");
  },
  
  clickListener: function(event)
  {
    var open = this.parentNode.parentNode;
    var fold = open.firstChild;
    var showing = $('.mn_merchDisplay','.'+open.className);
    while (fold != null)
    {
      if (fold.nodeType == 1 && (fold.className == "mn_collapsed" || fold.className == "mn_merchDisplay"))
      {
        if (fold.className == "mn_merchDisplay" && open.className == "mn_facetIdMerch"){
          $(showing).hide();
        }
        else if (fold.className == "mn_merchDisplay" && open.className == "mn_facetId343"){
          $(showing).hide();
        }
        else {
          Accordion.expand(fold);
          this.lastChild.nodeValue = "Less...";
        }
      }
      else if (fold.nodeType == 1 && fold.className == "mn_expanded")
      {
        $(showing).show();
        Accordion.collapse(fold);
        this.lastChild.nodeValue = "More...";
      }
      fold = fold.nextSibling;
    }
    Core.preventDefault(event);
  }
};


// show/hide additional facet categories
var MoreFacets =
{
  init: function()
  {
    var facets = Core.getElementsByClass("mn_moreFacets");
    for (var i = 0; i < facets.length; i++)
    {
      var folds = facets[i].childNodes;
      var items = facets[i].getElementsByTagName("li");
      for (var k = 0; k < items.length; k++)
      {
        var foldLinks = items[k].getElementsByTagName("a");
        var foldTitleLink = foldLinks[0];
        Core.addEventListener(foldTitleLink, "click", MoreFacets.clickListener);
      }
    }
  },

  collapse: function(fold)
  {
    Core.removeClass(fold, "mn_show");
    Core.addClass(fold, "mn_hide");
  },

  expand: function(fold)
  {
    Core.removeClass(fold, "mn_hide");
    Core.addClass(fold, "mn_show");
  },
  
  clickListener: function(event)
  {
    var open = this.parentNode.parentNode.parentNode;
    var fold = open.firstChild;
    while (fold != null)
    {
      if (fold.nodeType == 1 && fold.className == "mn_hide" && fold.id == this.className)
      {
        MoreFacets.expand(fold);
        linkText = this.lastChild.nodeValue;
        this.lastChild.nodeValue = "Close " + linkText; //if value length changes, change substr below
      }
      else if (fold.nodeType == 1 && fold.className == "mn_show" && fold.id == this.className)
      {
        MoreFacets.collapse(fold);
        linkTextClose = this.lastChild.nodeValue;
        this.lastChild.nodeValue = linkTextClose.substr(5);
      }
      fold = fold.nextSibling;
    }
    Core.preventDefault(event);
  }
};

/* 'floatCenter' mnjQuery plugin
 * @author Michael ORourke
 * @description Evenly centers groups of floated elements
 * @usage Specify container of floats and the floats themselves. Default width
 *        of floats should be defined in CSS. 
 *        Example:
 *        mnjQuery(document).ready(function($){
                $.fn.floatCenter({
                    sectionContainer: $('.mn_featProdCatContent'),
                    itemContainer: $('.mn_featProdCatItem')
                })
            }); 
 * @version 1.0 9/15/2009
 */
(function($){
  $.fn.floatCenter = function(options) {
    var options = $.extend(options);
    var gridWidth = $(options.sectionContainer).width();
    var boxWidth = $(options.itemContainer).outerWidth();
    var calc = gridWidth / boxWidth;
    calc = Math.floor(calc);
    var newWidth = gridWidth / calc;
    newWidth = Number(newWidth.toFixed(1));
    $(options.itemContainer).width(newWidth - .1);
  };
})(mnjQuery);

(function($){
  $.fn.gridWidthAdjust = function(options) {
    var defaults = {
      gridMax: 150,
      gridContain: '',
      gridItem: ''
    };
    var options = $.extend(defaults, options);
    // adjust box width based on container width
    var gridWidth = $(options.gridContain).outerWidth();
    var boxWidth = $(options.gridItem).outerWidth();
    var gridOffset = dimension(options.gridContain);
    var boxOffset = dimension(options.gridItem);
    var calc = gridWidth / boxWidth;
    calc = Math.floor(calc);
    var newWidth = (gridWidth - gridOffset) / calc - .1; //-.1 fixes rounding issue
    newWidth = Math.floor(newWidth - boxOffset);
    $(options.gridItem).width(newWidth);
        
    function dimension(theDim){
      var diff = $(theDim).outerWidth(true) - $(theDim).width();
            
      return diff;
    };
  };
})(mnjQuery);
 
(function($){
  $.fn.equalBoxHeight = function(options) {
    var defaults = {
      boxContain: '',
      boxItems: '',
      columns: null
    };
        
    var options = $.extend(defaults, options);
    $.each(options.boxContain, function(i,e){
      var newClassName = 'mn_boxResizer'+i;
      $(e).addClass(newClassName);
      var itemSet = $('.'+newClassName+' .'+options.boxItems);

      //find how many items in each row
      var boxContainer = $(e).outerWidth();
      var boxWidth = $(itemSet).outerWidth();
      var calc = boxContainer / boxWidth;
      calc = Math.floor(calc);

      boxHeight(itemSet, calc || options.columns);
      $(e).removeClass(newClassName);
    });
   
    function boxHeight(boxes, theCount){
      var oldCount = -1;
      var addCount = theCount;
      var theRow = boxes;
      while (theRow.length > 1){
        theRow = mnjQuery.grep(boxes, function(n, i){
          return (n  && i < theCount && i > oldCount );
        });
        oldCount = theCount - 1;
        theCount = theCount + addCount;
    
        var rowBox = $(theRow).map(function(){
          return $(this).height();
        });
        var getHeight = height(rowBox);
        if (getHeight != 0){
          $(theRow).css('height',getHeight+'px');
        }
        else {
          $(theRow).css('display', 'none');
        }
      }
    };
    
    function height(boxHeight){
      var newHeight = 0;
      $(boxHeight).each(function(i){
        if (newHeight == 0 || this > newHeight) {
          newHeight = this;
        }
      })
      return newHeight;
    };
    
  };
})(mnjQuery); 
    


/****/


/*
 * jQuery Cycle Plugin (with Transition Definitions)
 * Examples and documentation at: http://mnjquery.malsup.com/cycle/
 * Copyright (c) 2007-2010 M. Alsup
 * Version: 2.88 (08-JUN-2010)
 * Dual licensed under the MIT and GPL licenses.
 * http://mnjquery.malsup.com/license.html
 * Requires: jQuery v1.2.6 or later
 */
(function($){
  var ver="2.88";
  if($.support==undefined){
    $.support={
      opacity:!($.browser.msie)
    };

  }
  function debug(s){
    if($.fn.cycle.debug){
      log(s);
    }
  }
  function log(){
    if(window.console&&window.console.log){
      window.console.log("[cycle] "+Array.prototype.join.call(arguments," "));
    }
  }
  $.fn.cycle=function(options,arg2){
    var o={
      s:this.selector,
      c:this.context
    };

    if(this.length===0&&options!="stop"){
      if(!$.isReady&&o.s){
        log("DOM not ready, queuing slideshow");
        $(function(){
          $(o.s,o.c).cycle(options,arg2);
        });
        return this;
      }
      log("terminating; zero elements found by selector"+($.isReady?"":" (DOM not ready)"));
      return this;
    }
    return this.each(function(){
      var opts=handleArguments(this,options,arg2);
      if(opts===false){
        return;
      }
      opts.updateActivePagerLink=opts.updateActivePagerLink||$.fn.cycle.updateActivePagerLink;
      if(this.cycleTimeout){
        clearTimeout(this.cycleTimeout);
      }
      this.cycleTimeout=this.cyclePause=0;
      var $cont=$(this);
      var $slides=opts.slideExpr?$(opts.slideExpr,this):$cont.children();
      var els=$slides.get();
      if(els.length<2){
        log("terminating; too few slides: "+els.length);
        return;
      }
      var opts2=buildOptions($cont,$slides,els,opts,o);
      if(opts2===false){
        return;
      }
      var startTime=opts2.continuous?10:getTimeout(els[opts2.currSlide],els[opts2.nextSlide],opts2,!opts2.rev);
      if(startTime){
        startTime+=(opts2.delay||0);
        if(startTime<10){
          startTime=10;
        }
        debug("first timeout: "+startTime);
        this.cycleTimeout=setTimeout(function(){
          go(els,opts2,0,(!opts2.rev&&!opts.backwards));
        },startTime);
      }
    });
  };

  function handleArguments(cont,options,arg2){
    if(cont.cycleStop==undefined){
      cont.cycleStop=0;
    }
    if(options===undefined||options===null){
      options={};

    }
    if(options.constructor==String){
      switch(options){
        case"destroy":case"stop":
          var opts=$(cont).data("cycle.opts");
          if(!opts){
            return false;
          }
          cont.cycleStop++;
          if(cont.cycleTimeout){
            clearTimeout(cont.cycleTimeout);
          }
          cont.cycleTimeout=0;
          $(cont).removeData("cycle.opts");
          if(options=="destroy"){
            destroy(opts);
          }
          return false;
        case"toggle":
          cont.cyclePause=(cont.cyclePause===1)?0:1;
          checkInstantResume(cont.cyclePause,arg2,cont);
          return false;
        case"pause":
          cont.cyclePause=1;
          return false;
        case"resume":
          cont.cyclePause=0;
          checkInstantResume(false,arg2,cont);
          return false;
        case"prev":case"next":
          var opts=$(cont).data("cycle.opts");
          if(!opts){
            log('options not found, "prev/next" ignored');
            return false;
          }
          $.fn.cycle[options](opts);
          return false;
        default:
          options={
            fx:options
          };

      }
      return options;
    }else{
      if(options.constructor==Number){
        var num=options;
        options=$(cont).data("cycle.opts");
        if(!options){
          log("options not found, can not advance slide");
          return false;
        }
        if(num<0||num>=options.elements.length){
          log("invalid slide index: "+num);
          return false;
        }
        options.nextSlide=num;
        if(cont.cycleTimeout){
          clearTimeout(cont.cycleTimeout);
          cont.cycleTimeout=0;
        }
        if(typeof arg2=="string"){
          options.oneTimeFx=arg2;
        }
        go(options.elements,options,1,num>=options.currSlide);
        return false;
      }
    }
    return options;
    function checkInstantResume(isPaused,arg2,cont){
      if(!isPaused&&arg2===true){
        var options=$(cont).data("cycle.opts");
        if(!options){
          log("options not found, can not resume");
          return false;
        }
        if(cont.cycleTimeout){
          clearTimeout(cont.cycleTimeout);
          cont.cycleTimeout=0;
        }
        go(options.elements,options,1,(!opts.rev&&!opts.backwards));
      }
    }
  }
  function removeFilter(el,opts){
    if(!$.support.opacity&&opts.cleartype&&el.style.filter){
      try{
        el.style.removeAttribute("filter");
      }catch(smother){}
    }
  }
  function destroy(opts){
    if(opts.next){
      $(opts.next).unbind(opts.prevNextEvent);
    }
    if(opts.prev){
      $(opts.prev).unbind(opts.prevNextEvent);
    }
    if(opts.pager||opts.pagerAnchorBuilder){
      $.each(opts.pagerAnchors||[],function(){
        this.unbind().remove();
      });
    }
    opts.pagerAnchors=null;
    if(opts.destroy){
      opts.destroy(opts);
    }
  }
  function buildOptions($cont,$slides,els,options,o){
    var opts=$.extend({},$.fn.cycle.defaults,options||{},$.metadata?$cont.metadata():$.meta?$cont.data():{});
    if(opts.autostop){
      opts.countdown=opts.autostopCount||els.length;
    }
    var cont=$cont[0];
    $cont.data("cycle.opts",opts);
    opts.$cont=$cont;
    opts.stopCount=cont.cycleStop;
    opts.elements=els;
    opts.before=opts.before?[opts.before]:[];
    opts.after=opts.after?[opts.after]:[];
    opts.after.unshift(function(){
      opts.busy=0;
    });
    if(!$.support.opacity&&opts.cleartype){
      opts.after.push(function(){
        removeFilter(this,opts);
      });
    }
    if(opts.continuous){
      opts.after.push(function(){
        go(els,opts,0,(!opts.rev&&!opts.backwards));
      });
    }
    saveOriginalOpts(opts);
    if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){
      clearTypeFix($slides);
    }
    if($cont.css("position")=="static"){
      $cont.css("position","relative");
    }
    if(opts.width){
      $cont.width(opts.width);
    }
    if(opts.height&&opts.height!="auto"){
      $cont.height(opts.height);
    }
    if(opts.startingSlide){
      opts.startingSlide=parseInt(opts.startingSlide);
    }else{
      if(opts.backwards){
        opts.startingSlide=els.length-1;
      }
    }
    if(opts.random){
      opts.randomMap=[];
      for(var i=0;i<els.length;i++){
        opts.randomMap.push(i);
      }
      opts.randomMap.sort(function(a,b){
        return Math.random()-0.5;
      });
      opts.randomIndex=1;
      opts.startingSlide=opts.randomMap[1];
    }else{
      if(opts.startingSlide>=els.length){
        opts.startingSlide=0;
      }
    }
    opts.currSlide=opts.startingSlide||0;
    var first=opts.startingSlide;
    $slides.css({
      position:"absolute",
      top:0,
      left:0
    }).hide().each(function(i){
      var z;
      if(opts.backwards){
        z=first?i<=first?els.length+(i-first):first-i:els.length-i;
      }else{
        z=first?i>=first?els.length-(i-first):first-i:els.length-i;
      }
      $(this).css("z-index",z);
    });
    $(els[first]).css("opacity",1).show();
    removeFilter(els[first],opts);
    if(opts.fit&&opts.width){
      $slides.width(opts.width);
    }
    if(opts.fit&&opts.height&&opts.height!="auto"){
      $slides.height(opts.height);
    }
    var reshape=opts.containerResize&&!$cont.innerHeight();
    if(reshape){
      var maxw=0,maxh=0;
      for(var j=0;j<els.length;j++){
        var $e=$(els[j]),e=$e[0],w=$e.outerWidth(),h=$e.outerHeight();
        if(!w){
          w=e.offsetWidth||e.width||$e.attr("width");
        }
        if(!h){
          h=e.offsetHeight||e.height||$e.attr("height");
        }
        maxw=w>maxw?w:maxw;
        maxh=h>maxh?h:maxh;
      }
      if(maxw>0&&maxh>0){
        $cont.css({
          width:maxw+"px",
          height:maxh+"px"
        });
      }
    }
    if(opts.pause){
      $cont.hover(function(){
        this.cyclePause++;
      },function(){
        this.cyclePause--;
      });
    }
    if(supportMultiTransitions(opts)===false){
      return false;
    }
    var requeue=false;
    options.requeueAttempts=options.requeueAttempts||0;
    $slides.each(function(){
      var $el=$(this);
      this.cycleH=(opts.fit&&opts.height)?opts.height:($el.height()||this.offsetHeight||this.height||$el.attr("height")||0);
      this.cycleW=(opts.fit&&opts.width)?opts.width:($el.width()||this.offsetWidth||this.width||$el.attr("width")||0);
      if($el.is("img")){
        var loadingIE=($.browser.msie&&this.cycleW==28&&this.cycleH==30&&!this.complete);
        var loadingFF=($.browser.mozilla&&this.cycleW==34&&this.cycleH==19&&!this.complete);
        var loadingOp=($.browser.opera&&((this.cycleW==42&&this.cycleH==19)||(this.cycleW==37&&this.cycleH==17))&&!this.complete);
        var loadingOther=(this.cycleH==0&&this.cycleW==0&&!this.complete);
        if(loadingIE||loadingFF||loadingOp||loadingOther){
          if(o.s&&opts.requeueOnImageNotLoaded&&++options.requeueAttempts<100){
            log(options.requeueAttempts," - img slide not loaded, requeuing slideshow: ",this.src,this.cycleW,this.cycleH);
            setTimeout(function(){
              $(o.s,o.c).cycle(options);
            },opts.requeueTimeout);
            requeue=true;
            return false;
          }else{
            log("could not determine size of image: "+this.src,this.cycleW,this.cycleH);
          }
        }
      }
      return true;
    });
    if(requeue){
      return false;
    }
    opts.cssBefore=opts.cssBefore||{};

    opts.animIn=opts.animIn||{};

    opts.animOut=opts.animOut||{};

    $slides.not(":eq("+first+")").css(opts.cssBefore);
    if(opts.cssFirst){
      $($slides[first]).css(opts.cssFirst);
    }
    if(opts.timeout){
      opts.timeout=parseInt(opts.timeout);
      if(opts.speed.constructor==String){
        opts.speed=$.fx.speeds[opts.speed]||parseInt(opts.speed);
      }
      if(!opts.sync){
        opts.speed=opts.speed/2;
      }
      var buffer=opts.fx=="shuffle"?500:250;
      while((opts.timeout-opts.speed)<buffer){
        opts.timeout+=opts.speed;
      }
    }
    if(opts.easing){
      opts.easeIn=opts.easeOut=opts.easing;
    }
    if(!opts.speedIn){
      opts.speedIn=opts.speed;
    }
    if(!opts.speedOut){
      opts.speedOut=opts.speed;
    }
    opts.slideCount=els.length;
    opts.currSlide=opts.lastSlide=first;
    if(opts.random){
      if(++opts.randomIndex==els.length){
        opts.randomIndex=0;
      }
      opts.nextSlide=opts.randomMap[opts.randomIndex];
    }else{
      if(opts.backwards){
        opts.nextSlide=opts.startingSlide==0?(els.length-1):opts.startingSlide-1;
      }else{
        opts.nextSlide=opts.startingSlide>=(els.length-1)?0:opts.startingSlide+1;
      }
    }
    if(!opts.multiFx){
      var init=$.fn.cycle.transitions[opts.fx];
      if($.isFunction(init)){
        init($cont,$slides,opts);
      }else{
        if(opts.fx!="custom"&&!opts.multiFx){
          log("unknown transition: "+opts.fx,"; slideshow terminating");
          return false;
        }
      }
    }
    var e0=$slides[first];
    if(opts.before.length){
      opts.before[0].apply(e0,[e0,e0,opts,true]);
    }
    if(opts.after.length>1){
      opts.after[1].apply(e0,[e0,e0,opts,true]);
    }
    if(opts.next){
      $(opts.next).bind(opts.prevNextEvent,function(){
        return advance(opts,opts.rev?-1:1);
      });
    }
    if(opts.prev){
      $(opts.prev).bind(opts.prevNextEvent,function(){
        return advance(opts,opts.rev?1:-1);
      });
    }
    if(opts.pager||opts.pagerAnchorBuilder){
      buildPager(els,opts);
    }
    exposeAddSlide(opts,els);
    return opts;
  }
  function saveOriginalOpts(opts){
    opts.original={
      before:[],
      after:[]
    };

    opts.original.cssBefore=$.extend({},opts.cssBefore);
    opts.original.cssAfter=$.extend({},opts.cssAfter);
    opts.original.animIn=$.extend({},opts.animIn);
    opts.original.animOut=$.extend({},opts.animOut);
    $.each(opts.before,function(){
      opts.original.before.push(this);
    });
    $.each(opts.after,function(){
      opts.original.after.push(this);
    });
  }
  function supportMultiTransitions(opts){
    var i,tx,txs=$.fn.cycle.transitions;
    if(opts.fx.indexOf(",")>0){
      opts.multiFx=true;
      opts.fxs=opts.fx.replace(/\s*/g,"").split(",");
      for(i=0;i<opts.fxs.length;i++){
        var fx=opts.fxs[i];
        tx=txs[fx];
        if(!tx||!txs.hasOwnProperty(fx)||!$.isFunction(tx)){
          log("discarding unknown transition: ",fx);
          opts.fxs.splice(i,1);
          i--;
        }
      }
      if(!opts.fxs.length){
        log("No valid transitions named; slideshow terminating.");
        return false;
      }
    }else{
      if(opts.fx=="all"){
        opts.multiFx=true;
        opts.fxs=[];
        for(p in txs){
          tx=txs[p];
          if(txs.hasOwnProperty(p)&&$.isFunction(tx)){
            opts.fxs.push(p);
          }
        }
      }
    }
    if(opts.multiFx&&opts.randomizeEffects){
      var r1=Math.floor(Math.random()*20)+30;
      for(i=0;i<r1;i++){
        var r2=Math.floor(Math.random()*opts.fxs.length);
        opts.fxs.push(opts.fxs.splice(r2,1)[0]);
      }
      debug("randomized fx sequence: ",opts.fxs);
    }
    return true;
  }
  function exposeAddSlide(opts,els){
    opts.addSlide=function(newSlide,prepend){
      var $s=$(newSlide),s=$s[0];
      if(!opts.autostopCount){
        opts.countdown++;
      }
      els[prepend?"unshift":"push"](s);
      if(opts.els){
        opts.els[prepend?"unshift":"push"](s);
      }
      opts.slideCount=els.length;
      $s.css("position","absolute");
      $s[prepend?"prependTo":"appendTo"](opts.$cont);
      if(prepend){
        opts.currSlide++;
        opts.nextSlide++;
      }
      if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){
        clearTypeFix($s);
      }
      if(opts.fit&&opts.width){
        $s.width(opts.width);
      }
      if(opts.fit&&opts.height&&opts.height!="auto"){
        $slides.height(opts.height);
      }
      s.cycleH=(opts.fit&&opts.height)?opts.height:$s.height();
      s.cycleW=(opts.fit&&opts.width)?opts.width:$s.width();
      $s.css(opts.cssBefore);
      if(opts.pager||opts.pagerAnchorBuilder){
        $.fn.cycle.createPagerAnchor(els.length-1,s,$(opts.pager),els,opts);
      }
      if($.isFunction(opts.onAddSlide)){
        opts.onAddSlide($s);
      }else{
        $s.hide();
      }
    };

  }
  $.fn.cycle.resetState=function(opts,fx){
    fx=fx||opts.fx;
    opts.before=[];
    opts.after=[];
    opts.cssBefore=$.extend({},opts.original.cssBefore);
    opts.cssAfter=$.extend({},opts.original.cssAfter);
    opts.animIn=$.extend({},opts.original.animIn);
    opts.animOut=$.extend({},opts.original.animOut);
    opts.fxFn=null;
    $.each(opts.original.before,function(){
      opts.before.push(this);
    });
    $.each(opts.original.after,function(){
      opts.after.push(this);
    });
    var init=$.fn.cycle.transitions[fx];
    if($.isFunction(init)){
      init(opts.$cont,$(opts.elements),opts);
    }
  };

  function go(els,opts,manual,fwd){
    if(manual&&opts.busy&&opts.manualTrump){
      debug("manualTrump in go(), stopping active transition");
      $(els).stop(true,true);
      opts.busy=false;
    }
    if(opts.busy){
      debug("transition active, ignoring new tx request");
      return;
    }
    var p=opts.$cont[0],curr=els[opts.currSlide],next=els[opts.nextSlide];
    if(p.cycleStop!=opts.stopCount||p.cycleTimeout===0&&!manual){
      return;
    }
    if(!manual&&!p.cyclePause&&!opts.bounce&&((opts.autostop&&(--opts.countdown<=0))||(opts.nowrap&&!opts.random&&opts.nextSlide<opts.currSlide))){
      if(opts.end){
        opts.end(opts);
      }
      return;
    }
    var changed=false;
    if((manual||!p.cyclePause)&&(opts.nextSlide!=opts.currSlide)){
      changed=true;
      var fx=opts.fx;
      curr.cycleH=curr.cycleH||$(curr).height();
      curr.cycleW=curr.cycleW||$(curr).width();
      next.cycleH=next.cycleH||$(next).height();
      next.cycleW=next.cycleW||$(next).width();
      if(opts.multiFx){
        if(opts.lastFx==undefined||++opts.lastFx>=opts.fxs.length){
          opts.lastFx=0;
        }
        fx=opts.fxs[opts.lastFx];
        opts.currFx=fx;
      }
      if(opts.oneTimeFx){
        fx=opts.oneTimeFx;
        opts.oneTimeFx=null;
      }
      $.fn.cycle.resetState(opts,fx);
      if(opts.before.length){
        $.each(opts.before,function(i,o){
          if(p.cycleStop!=opts.stopCount){
            return;
          }
          o.apply(next,[curr,next,opts,fwd]);
        });
      }
      var after=function(){
        $.each(opts.after,function(i,o){
          if(p.cycleStop!=opts.stopCount){
            return;
          }
          o.apply(next,[curr,next,opts,fwd]);
        });
      };

      debug("tx firing; currSlide: "+opts.currSlide+"; nextSlide: "+opts.nextSlide);
      opts.busy=1;
      if(opts.fxFn){
        opts.fxFn(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);
      }else{
        if($.isFunction($.fn.cycle[opts.fx])){
          $.fn.cycle[opts.fx](curr,next,opts,after,fwd,manual&&opts.fastOnEvent);
        }else{
          $.fn.cycle.custom(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);
        }
      }
    }
    if(changed||opts.nextSlide==opts.currSlide){
      opts.lastSlide=opts.currSlide;
      if(opts.random){
        opts.currSlide=opts.nextSlide;
        if(++opts.randomIndex==els.length){
          opts.randomIndex=0;
        }
        opts.nextSlide=opts.randomMap[opts.randomIndex];
        if(opts.nextSlide==opts.currSlide){
          opts.nextSlide=(opts.currSlide==opts.slideCount-1)?0:opts.currSlide+1;
        }
      }else{
        if(opts.backwards){
          var roll=(opts.nextSlide-1)<0;
          if(roll&&opts.bounce){
            opts.backwards=!opts.backwards;
            opts.nextSlide=1;
            opts.currSlide=0;
          }else{
            opts.nextSlide=roll?(els.length-1):opts.nextSlide-1;
            opts.currSlide=roll?0:opts.nextSlide+1;
          }
        }else{
          var roll=(opts.nextSlide+1)==els.length;
          if(roll&&opts.bounce){
            opts.backwards=!opts.backwards;
            opts.nextSlide=els.length-2;
            opts.currSlide=els.length-1;
          }else{
            opts.nextSlide=roll?0:opts.nextSlide+1;
            opts.currSlide=roll?els.length-1:opts.nextSlide-1;
          }
        }
      }
    }
    if(changed&&opts.pager){
      opts.updateActivePagerLink(opts.pager,opts.currSlide,opts.activePagerClass);
    }
    var ms=0;
    if(opts.timeout&&!opts.continuous){
      ms=getTimeout(els[opts.currSlide],els[opts.nextSlide],opts,fwd);
    }else{
      if(opts.continuous&&p.cyclePause){
        ms=10;
      }
    }
    if(ms>0){
      p.cycleTimeout=setTimeout(function(){
        go(els,opts,0,(!opts.rev&&!opts.backwards));
      },ms);
    }
  }
  $.fn.cycle.updateActivePagerLink=function(pager,currSlide,clsName){
    $(pager).each(function(){
      $(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);
    });
  };

  function getTimeout(curr,next,opts,fwd){
    if(opts.timeoutFn){
      var t=opts.timeoutFn.call(curr,curr,next,opts,fwd);
      while((t-opts.speed)<250){
        t+=opts.speed;
      }
      debug("calculated timeout: "+t+"; speed: "+opts.speed);
      if(t!==false){
        return t;
      }
    }
    return opts.timeout;
  }
  $.fn.cycle.next=function(opts){
    advance(opts,opts.rev?-1:1);
  };

  $.fn.cycle.prev=function(opts){
    advance(opts,opts.rev?1:-1);
  };

  function advance(opts,val){
    var els=opts.elements;
    var p=opts.$cont[0],timeout=p.cycleTimeout;
    if(timeout){
      clearTimeout(timeout);
      p.cycleTimeout=0;
    }
    if(opts.random&&val<0){
      opts.randomIndex--;
      if(--opts.randomIndex==-2){
        opts.randomIndex=els.length-2;
      }else{
        if(opts.randomIndex==-1){
          opts.randomIndex=els.length-1;
        }
      }
      opts.nextSlide=opts.randomMap[opts.randomIndex];
    }else{
      if(opts.random){
        opts.nextSlide=opts.randomMap[opts.randomIndex];
      }else{
        opts.nextSlide=opts.currSlide+val;
        if(opts.nextSlide<0){
          if(opts.nowrap){
            return false;
          }
          opts.nextSlide=els.length-1;
        }else{
          if(opts.nextSlide>=els.length){
            if(opts.nowrap){
              return false;
            }
            opts.nextSlide=0;
          }
        }
      }
    }
    var cb=opts.onPrevNextEvent||opts.prevNextClick;
    if($.isFunction(cb)){
      cb(val>0,opts.nextSlide,els[opts.nextSlide]);
    }
    go(els,opts,1,val>=0);
    return false;
  }
  function buildPager(els,opts){
    var $p=$(opts.pager);
    $.each(els,function(i,o){
      $.fn.cycle.createPagerAnchor(i,o,$p,els,opts);
    });
    opts.updateActivePagerLink(opts.pager,opts.startingSlide,opts.activePagerClass);
  }
  $.fn.cycle.createPagerAnchor=function(i,el,$p,els,opts){
    var a;
    if($.isFunction(opts.pagerAnchorBuilder)){
      a=opts.pagerAnchorBuilder(i,el);
      debug("pagerAnchorBuilder("+i+", el) returned: "+a);
    }else{
      a='<a href="#">'+(i+1)+"</a>";
    }
    if(!a){
      return;
    }
    var $a=$(a);
    if($a.parents("body").length===0){
      var arr=[];
      if($p.length>1){
        $p.each(function(){
          var $clone=$a.clone(true);
          $(this).append($clone);
          arr.push($clone[0]);
        });
        $a=$(arr);
      }else{
        $a.appendTo($p);
      }
    }
    opts.pagerAnchors=opts.pagerAnchors||[];
    opts.pagerAnchors.push($a);
    $a.bind(opts.pagerEvent,function(e){
      e.preventDefault();
      opts.nextSlide=i;
      var p=opts.$cont[0],timeout=p.cycleTimeout;
      if(timeout){
        clearTimeout(timeout);
        p.cycleTimeout=0;
      }
      var cb=opts.onPagerEvent||opts.pagerClick;
      if($.isFunction(cb)){
        cb(opts.nextSlide,els[opts.nextSlide]);
      }
      go(els,opts,1,opts.currSlide<i);
    });
    if(!/^click/.test(opts.pagerEvent)&&!opts.allowPagerClickBubble){
      $a.bind("click.cycle",function(){
        return false;
      });
    }
    if(opts.pauseOnPagerHover){
      $a.hover(function(){
        opts.$cont[0].cyclePause++;
      },function(){
        opts.$cont[0].cyclePause--;
      });
    }
  };

  $.fn.cycle.hopsFromLast=function(opts,fwd){
    var hops,l=opts.lastSlide,c=opts.currSlide;
    if(fwd){
      hops=c>l?c-l:opts.slideCount-l;
    }else{
      hops=c<l?l-c:l+opts.slideCount-c;
    }
    return hops;
  };

  function clearTypeFix($slides){
    debug("applying clearType background-color hack");
    function hex(s){
      s=parseInt(s).toString(16);
      return s.length<2?"0"+s:s;
    }
    function getBg(e){
      for(;e&&e.nodeName.toLowerCase()!="html";e=e.parentNode){
        var v=$.css(e,"background-color");
        if(v.indexOf("rgb")>=0){
          var rgb=v.match(/\d+/g);
          return"#"+hex(rgb[0])+hex(rgb[1])+hex(rgb[2]);
        }
        if(v&&v!="transparent"){
          return v;
        }
      }
      return"#ffffff";
    }
    $slides.each(function(){
      $(this).css("background-color",getBg(this));
    });
  }
  $.fn.cycle.commonReset=function(curr,next,opts,w,h,rev){
    $(opts.elements).not(curr).hide();
    opts.cssBefore.opacity=1;
    opts.cssBefore.display="block";
    if(w!==false&&next.cycleW>0){
      opts.cssBefore.width=next.cycleW;
    }
    if(h!==false&&next.cycleH>0){
      opts.cssBefore.height=next.cycleH;
    }
    opts.cssAfter=opts.cssAfter||{};

    opts.cssAfter.display="none";
    $(curr).css("zIndex",opts.slideCount+(rev===true?1:0));
    $(next).css("zIndex",opts.slideCount+(rev===true?0:1));
  };

  $.fn.cycle.custom=function(curr,next,opts,cb,fwd,speedOverride){
    var $l=$(curr),$n=$(next);
    var speedIn=opts.speedIn,speedOut=opts.speedOut,easeIn=opts.easeIn,easeOut=opts.easeOut;
    $n.css(opts.cssBefore);
    if(speedOverride){
      if(typeof speedOverride=="number"){
        speedIn=speedOut=speedOverride;
      }else{
        speedIn=speedOut=1;
      }
      easeIn=easeOut=null;
    }
    var fn=function(){
      $n.animate(opts.animIn,speedIn,easeIn,cb);
    };

    $l.animate(opts.animOut,speedOut,easeOut,function(){
      if(opts.cssAfter){
        $l.css(opts.cssAfter);
      }
      if(!opts.sync){
        fn();
      }
    });
    if(opts.sync){
      fn();
    }
  };

  $.fn.cycle.transitions={
    fade:function($cont,$slides,opts){
      $slides.not(":eq("+opts.currSlide+")").css("opacity",0);
      opts.before.push(function(curr,next,opts){
        $.fn.cycle.commonReset(curr,next,opts);
        opts.cssBefore.opacity=0;
      });
      opts.animIn={
        opacity:1
      };

      opts.animOut={
        opacity:0
      };

      opts.cssBefore={
        top:0,
        left:0
      };

    }
  };

  $.fn.cycle.ver=function(){
    return ver;
  };

  $.fn.cycle.defaults={
    fx:"fade",
    timeout:4000,
    timeoutFn:null,
    continuous:0,
    speed:1000,
    speedIn:null,
    speedOut:null,
    next:null,
    prev:null,
    onPrevNextEvent:null,
    prevNextEvent:"click.cycle",
    pager:null,
    onPagerEvent:null,
    pagerEvent:"click.cycle",
    allowPagerClickBubble:false,
    pagerAnchorBuilder:null,
    before:null,
    after:null,
    end:null,
    easing:null,
    easeIn:null,
    easeOut:null,
    shuffle:null,
    animIn:null,
    animOut:null,
    cssBefore:null,
    cssAfter:null,
    fxFn:null,
    height:"auto",
    startingSlide:0,
    sync:1,
    random:0,
    fit:0,
    containerResize:1,
    pause:0,
    pauseOnPagerHover:0,
    autostop:0,
    autostopCount:0,
    delay:0,
    slideExpr:null,
    cleartype:!$.support.opacity,
    cleartypeNoBg:false,
    nowrap:0,
    fastOnEvent:0,
    randomizeEffects:1,
    rev:0,
    manualTrump:true,
    requeueOnImageNotLoaded:true,
    requeueTimeout:250,
    activePagerClass:"activeSlide",
    updateActivePagerLink:null,
    backwards:false
  };

})(mnjQuery);
/*
 * jQuery Cycle Plugin Transition Definitions
 * This script is a plugin for the jQuery Cycle Plugin
 * Examples and documentation at: http://malsup.com/mnjquery/cycle/
 * Copyright (c) 2007-2010 M. Alsup
 * Version:	 2.72
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
(function($){
  $.fn.cycle.transitions.none=function($cont,$slides,opts){
    opts.fxFn=function(curr,next,opts,after){
      $(next).show();
      $(curr).hide();
      after();
    };

  };

  $.fn.cycle.transitions.scrollUp=function($cont,$slides,opts){
    $cont.css("overflow","hidden");
    opts.before.push($.fn.cycle.commonReset);
    var h=$cont.height();
    opts.cssBefore={
      top:h,
      left:0
    };

    opts.cssFirst={
      top:0
    };

    opts.animIn={
      top:0
    };

    opts.animOut={
      top:-h
    };

  };

  $.fn.cycle.transitions.scrollDown=function($cont,$slides,opts){
    $cont.css("overflow","hidden");
    opts.before.push($.fn.cycle.commonReset);
    var h=$cont.height();
    opts.cssFirst={
      top:0
    };

    opts.cssBefore={
      top:-h,
      left:0
    };

    opts.animIn={
      top:0
    };

    opts.animOut={
      top:h
    };

  };

  $.fn.cycle.transitions.scrollLeft=function($cont,$slides,opts){
    $cont.css("overflow","hidden");
    opts.before.push($.fn.cycle.commonReset);
    var w=$cont.width();
    opts.cssFirst={
      left:0
    };

    opts.cssBefore={
      left:w,
      top:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      left:0-w
    };

  };

  $.fn.cycle.transitions.scrollRight=function($cont,$slides,opts){
    $cont.css("overflow","hidden");
    opts.before.push($.fn.cycle.commonReset);
    var w=$cont.width();
    opts.cssFirst={
      left:0
    };

    opts.cssBefore={
      left:-w,
      top:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      left:w
    };

  };

  $.fn.cycle.transitions.scrollHorz=function($cont,$slides,opts){
    $cont.css("overflow","hidden").width();
    opts.before.push(function(curr,next,opts,fwd){
      $.fn.cycle.commonReset(curr,next,opts);
      opts.cssBefore.left=fwd?(next.cycleW-1):(1-next.cycleW);
      opts.animOut.left=fwd?-curr.cycleW:curr.cycleW;
    });
    opts.cssFirst={
      left:0
    };

    opts.cssBefore={
      top:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      top:0
    };

  };

  $.fn.cycle.transitions.scrollVert=function($cont,$slides,opts){
    $cont.css("overflow","hidden");
    opts.before.push(function(curr,next,opts,fwd){
      $.fn.cycle.commonReset(curr,next,opts);
      opts.cssBefore.top=fwd?(1-next.cycleH):(next.cycleH-1);
      opts.animOut.top=fwd?curr.cycleH:-curr.cycleH;
    });
    opts.cssFirst={
      top:0
    };

    opts.cssBefore={
      left:0
    };

    opts.animIn={
      top:0
    };

    opts.animOut={
      left:0
    };

  };

  $.fn.cycle.transitions.slideX=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $(opts.elements).not(curr).hide();
      $.fn.cycle.commonReset(curr,next,opts,false,true);
      opts.animIn.width=next.cycleW;
    });
    opts.cssBefore={
      left:0,
      top:0,
      width:0
    };

    opts.animIn={
      width:"show"
    };

    opts.animOut={
      width:0
    };

  };

  $.fn.cycle.transitions.slideY=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $(opts.elements).not(curr).hide();
      $.fn.cycle.commonReset(curr,next,opts,true,false);
      opts.animIn.height=next.cycleH;
    });
    opts.cssBefore={
      left:0,
      top:0,
      height:0
    };

    opts.animIn={
      height:"show"
    };

    opts.animOut={
      height:0
    };

  };

  $.fn.cycle.transitions.shuffle=function($cont,$slides,opts){
    var i,w=$cont.css("overflow","visible").width();
    $slides.css({
      left:0,
      top:0
    });
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,true,true);
    });
    if(!opts.speedAdjusted){
      opts.speed=opts.speed/2;
      opts.speedAdjusted=true;
    }
    opts.random=0;
    opts.shuffle=opts.shuffle||{
      left:-w,
      top:15
    };

    opts.els=[];
    for(i=0;i<$slides.length;i++){
      opts.els.push($slides[i]);
    }
    for(i=0;i<opts.currSlide;i++){
      opts.els.push(opts.els.shift());
    }
    opts.fxFn=function(curr,next,opts,cb,fwd){
      var $el=fwd?$(curr):$(next);
      $(next).css(opts.cssBefore);
      var count=opts.slideCount;
      $el.animate(opts.shuffle,opts.speedIn,opts.easeIn,function(){
        var hops=$.fn.cycle.hopsFromLast(opts,fwd);
        for(var k=0;k<hops;k++){
          fwd?opts.els.push(opts.els.shift()):opts.els.unshift(opts.els.pop());
        }
        if(fwd){
          for(var i=0,len=opts.els.length;i<len;i++){
            $(opts.els[i]).css("z-index",len-i+count);
          }
        }else{
          var z=$(curr).css("z-index");
          $el.css("z-index",parseInt(z)+1+count);
        }
        $el.animate({
          left:0,
          top:0
        },opts.speedOut,opts.easeOut,function(){
          $(fwd?this:curr).hide();
          if(cb){
            cb();
          }
        });
      });
    };

    opts.cssBefore={
      display:"block",
      opacity:1,
      top:0,
      left:0
    };

  };

  $.fn.cycle.transitions.turnUp=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,false);
      opts.cssBefore.top=next.cycleH;
      opts.animIn.height=next.cycleH;
    });
    opts.cssFirst={
      top:0
    };

    opts.cssBefore={
      left:0,
      height:0
    };

    opts.animIn={
      top:0
    };

    opts.animOut={
      height:0
    };

  };

  $.fn.cycle.transitions.turnDown=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,false);
      opts.animIn.height=next.cycleH;
      opts.animOut.top=curr.cycleH;
    });
    opts.cssFirst={
      top:0
    };

    opts.cssBefore={
      left:0,
      top:0,
      height:0
    };

    opts.animOut={
      height:0
    };

  };

  $.fn.cycle.transitions.turnLeft=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,true);
      opts.cssBefore.left=next.cycleW;
      opts.animIn.width=next.cycleW;
    });
    opts.cssBefore={
      top:0,
      width:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      width:0
    };

  };

  $.fn.cycle.transitions.turnRight=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,true);
      opts.animIn.width=next.cycleW;
      opts.animOut.left=curr.cycleW;
    });
    opts.cssBefore={
      top:0,
      left:0,
      width:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      width:0
    };

  };

  $.fn.cycle.transitions.zoom=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,false,true);
      opts.cssBefore.top=next.cycleH/2;
      opts.cssBefore.left=next.cycleW/2;
      opts.animIn={
        top:0,
        left:0,
        width:next.cycleW,
        height:next.cycleH
      };

      opts.animOut={
        width:0,
        height:0,
        top:curr.cycleH/2,
        left:curr.cycleW/2
      };

    });
    opts.cssFirst={
      top:0,
      left:0
    };

    opts.cssBefore={
      width:0,
      height:0
    };

  };

  $.fn.cycle.transitions.fadeZoom=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,false);
      opts.cssBefore.left=next.cycleW/2;
      opts.cssBefore.top=next.cycleH/2;
      opts.animIn={
        top:0,
        left:0,
        width:next.cycleW,
        height:next.cycleH
      };

    });
    opts.cssBefore={
      width:0,
      height:0
    };

    opts.animOut={
      opacity:0
    };

  };

  $.fn.cycle.transitions.blindX=function($cont,$slides,opts){
    var w=$cont.css("overflow","hidden").width();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts);
      opts.animIn.width=next.cycleW;
      opts.animOut.left=curr.cycleW;
    });
    opts.cssBefore={
      left:w,
      top:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      left:w
    };

  };

  $.fn.cycle.transitions.blindY=function($cont,$slides,opts){
    var h=$cont.css("overflow","hidden").height();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts);
      opts.animIn.height=next.cycleH;
      opts.animOut.top=curr.cycleH;
    });
    opts.cssBefore={
      top:h,
      left:0
    };

    opts.animIn={
      top:0
    };

    opts.animOut={
      top:h
    };

  };

  $.fn.cycle.transitions.blindZ=function($cont,$slides,opts){
    var h=$cont.css("overflow","hidden").height();
    var w=$cont.width();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts);
      opts.animIn.height=next.cycleH;
      opts.animOut.top=curr.cycleH;
    });
    opts.cssBefore={
      top:h,
      left:w
    };

    opts.animIn={
      top:0,
      left:0
    };

    opts.animOut={
      top:h,
      left:w
    };

  };

  $.fn.cycle.transitions.growX=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,true);
      opts.cssBefore.left=this.cycleW/2;
      opts.animIn={
        left:0,
        width:this.cycleW
      };

      opts.animOut={
        left:0
      };

    });
    opts.cssBefore={
      width:0,
      top:0
    };

  };

  $.fn.cycle.transitions.growY=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,false);
      opts.cssBefore.top=this.cycleH/2;
      opts.animIn={
        top:0,
        height:this.cycleH
      };

      opts.animOut={
        top:0
      };

    });
    opts.cssBefore={
      height:0,
      left:0
    };

  };

  $.fn.cycle.transitions.curtainX=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,false,true,true);
      opts.cssBefore.left=next.cycleW/2;
      opts.animIn={
        left:0,
        width:this.cycleW
      };

      opts.animOut={
        left:curr.cycleW/2,
        width:0
      };

    });
    opts.cssBefore={
      top:0,
      width:0
    };

  };

  $.fn.cycle.transitions.curtainY=function($cont,$slides,opts){
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,false,true);
      opts.cssBefore.top=next.cycleH/2;
      opts.animIn={
        top:0,
        height:next.cycleH
      };

      opts.animOut={
        top:curr.cycleH/2,
        height:0
      };

    });
    opts.cssBefore={
      left:0,
      height:0
    };

  };

  $.fn.cycle.transitions.cover=function($cont,$slides,opts){
    var d=opts.direction||"left";
    var w=$cont.css("overflow","hidden").width();
    var h=$cont.height();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts);
      if(d=="right"){
        opts.cssBefore.left=-w;
      }else{
        if(d=="up"){
          opts.cssBefore.top=h;
        }else{
          if(d=="down"){
            opts.cssBefore.top=-h;
          }else{
            opts.cssBefore.left=w;
          }
        }
      }
    });
    opts.animIn={
      left:0,
      top:0
    };

    opts.animOut={
      opacity:1
    };

    opts.cssBefore={
      top:0,
      left:0
    };

  };

  $.fn.cycle.transitions.uncover=function($cont,$slides,opts){
    var d=opts.direction||"left";
    var w=$cont.css("overflow","hidden").width();
    var h=$cont.height();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,true,true);
      if(d=="right"){
        opts.animOut.left=w;
      }else{
        if(d=="up"){
          opts.animOut.top=-h;
        }else{
          if(d=="down"){
            opts.animOut.top=h;
          }else{
            opts.animOut.left=-w;
          }
        }
      }
    });
    opts.animIn={
      left:0,
      top:0
    };

    opts.animOut={
      opacity:1
    };

    opts.cssBefore={
      top:0,
      left:0
    };

  };

  $.fn.cycle.transitions.toss=function($cont,$slides,opts){
    var w=$cont.css("overflow","visible").width();
    var h=$cont.height();
    opts.before.push(function(curr,next,opts){
      $.fn.cycle.commonReset(curr,next,opts,true,true,true);
      if(!opts.animOut.left&&!opts.animOut.top){
        opts.animOut={
          left:w*2,
          top:-h/2,
          opacity:0
        };

      }else{
        opts.animOut.opacity=0;
      }
    });
    opts.cssBefore={
      left:0,
      top:0
    };

    opts.animIn={
      left:0
    };

  };

  $.fn.cycle.transitions.wipe=function($cont,$slides,opts){
    var w=$cont.css("overflow","hidden").width();
    var h=$cont.height();
    opts.cssBefore=opts.cssBefore||{};

    var clip;
    if(opts.clip){
      if(/l2r/.test(opts.clip)){
        clip="rect(0px 0px "+h+"px 0px)";
      }else{
        if(/r2l/.test(opts.clip)){
          clip="rect(0px "+w+"px "+h+"px "+w+"px)";
        }else{
          if(/t2b/.test(opts.clip)){
            clip="rect(0px "+w+"px 0px 0px)";
          }else{
            if(/b2t/.test(opts.clip)){
              clip="rect("+h+"px "+w+"px "+h+"px 0px)";
            }else{
              if(/zoom/.test(opts.clip)){
                var top=parseInt(h/2);
                var left=parseInt(w/2);
                clip="rect("+top+"px "+left+"px "+top+"px "+left+"px)";
              }
            }
          }
        }
      }
    }
    opts.cssBefore.clip=opts.cssBefore.clip||clip||"rect(0px 0px 0px 0px)";
    var d=opts.cssBefore.clip.match(/(\d+)/g);
    var t=parseInt(d[0]),r=parseInt(d[1]),b=parseInt(d[2]),l=parseInt(d[3]);
    opts.before.push(function(curr,next,opts){
      if(curr==next){
        return;
      }
      var $curr=$(curr),$next=$(next);
      $.fn.cycle.commonReset(curr,next,opts,true,true,false);
      opts.cssAfter.display="block";
      var step=1,count=parseInt((opts.speedIn/13))-1;
      (function f(){
        var tt=t?t-parseInt(step*(t/count)):0;
        var ll=l?l-parseInt(step*(l/count)):0;
        var bb=b<h?b+parseInt(step*((h-b)/count||1)):h;
        var rr=r<w?r+parseInt(step*((w-r)/count||1)):w;
        $next.css({
          clip:"rect("+tt+"px "+rr+"px "+bb+"px "+ll+"px)"
        });
        (step++<=count)?setTimeout(f,13):$curr.css("display","none");
      })();
    });
    opts.cssBefore={
      display:"block",
      opacity:1,
      top:0,
      left:0
    };

    opts.animIn={
      left:0
    };

    opts.animOut={
      left:0
    };

  };

})(mnjQuery);

/*
 * Metadata - jQuery plugin for parsing metadata from elements
 *
 * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.metadata.js 3620 2007-10-10 20:55:38Z pmclanahan $
 *
 */
(function($){
  $.extend({
    metadata:{
      defaults:{
        type:'class',
        name:'metadata',
        cre:/({.*})/,
        single:'metadata'
      },
      setType:function(type,name){
        this.defaults.type=type;
        this.defaults.name=name;
      },
      get:function(elem,opts){
        var settings=$.extend({},this.defaults,opts);
        if(!settings.single.length)settings.single='metadata';
        var data=$.data(elem,settings.single);
        if(data)return data;
        data="{}";
        if(settings.type=="class"){
          var m=settings.cre.exec(elem.className);
          if(m)data=m[1];
        }else if(settings.type=="elem"){
          if(!elem.getElementsByTagName)return;
          var e=elem.getElementsByTagName(settings.name);
          if(e.length)data=$.trim(e[0].innerHTML);
        }else if(elem.getAttribute!=undefined){
          var attr=elem.getAttribute(settings.name);
          if(attr)data=attr;
        }
        if(data.indexOf('{')<0)data="{"+data+"}";
        data=eval("("+data+")");
        $.data(elem,settings.single,data);
        return data;
      }
    }
  });
  $.fn.metadata=function(opts){
    return $.metadata.get(this[0],opts);
  };

})(mnjQuery);




/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.0.3
 * Requires jQuery 1.1.3+
 * Docs: http://docs.jquery.com/Plugins/livequery
 */

(function($) {
	
  $.extend($.fn, {
    livequery: function(type, fn, fn2) {
      var self = this, q;
		
      // Handle different call patterns
      if ($.isFunction(type))
        fn2 = fn, fn = type, type = undefined;
			
      // See if Live Query already exists
      $.each( $.livequery.queries, function(i, query) {
        if ( self.selector == query.selector && self.context == query.context &&
          type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
          // Found the query, exit the each loop
          return (q = query) && false;
      });
		
      // Create new Live Query if it wasn't found
      q = q || new $.livequery(this.selector, this.context, type, fn, fn2);
		
      // Make sure it is running
      q.stopped = false;
		
      // Run it immediately for the first time
      q.run();
		
      // Contnue the chain
      return this;
    },
	
    expire: function(type, fn, fn2) {
      var self = this;
		
      // Handle different call patterns
      if ($.isFunction(type))
        fn2 = fn, fn = type, type = undefined;
			
      // Find the Live Query based on arguments and stop it
      $.each( $.livequery.queries, function(i, query) {
        if ( self.selector == query.selector && self.context == query.context &&
          (!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
          $.livequery.stop(query.id);
      });
		
      // Continue the chain
      return this;
    }
  });

  $.livequery = function(selector, context, type, fn, fn2) {
    this.selector = selector;
    this.context  = context || document;
    this.type     = type;
    this.fn       = fn;
    this.fn2      = fn2;
    this.elements = [];
    this.stopped  = false;
	
    // The id is the index of the Live Query in $.livequery.queries
    this.id = $.livequery.queries.push(this)-1;
	
    // Mark the functions for matching later on
    fn.$lqguid = fn.$lqguid || $.livequery.guid++;
    if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;
	
    // Return the Live Query
    return this;
  };

  $.livequery.prototype = {
    stop: function() {
      var query = this;
		
      if ( this.type )
        // Unbind all bound events
        this.elements.unbind(this.type, this.fn);
      else if (this.fn2)
        // Call the second function for all matched elements
        this.elements.each(function(i, el) {
          query.fn2.apply(el);
        });
			
      // Clear out matched elements
      this.elements = [];
		
      // Stop the Live Query from running until restarted
      this.stopped = true;
    },
	
    run: function() {
      // Short-circuit if stopped
      if ( this.stopped ) return;
      var query = this;
		
      var oEls = this.elements,
      els  = $(this.selector, this.context),
      nEls = els.not(oEls);
		
      // Set elements to the latest set of matched elements
      this.elements = els;
		
      if (this.type) {
        // Bind events to newly matched elements
        nEls.bind(this.type, this.fn);
			
        // Unbind events to elements no longer matched
        if (oEls.length > 0)
          $.each(oEls, function(i, el) {
            if ( $.inArray(el, els) < 0 )
              $.event.remove(el, query.type, query.fn);
          });
      }
      else {
        // Call the first function for newly matched elements
        nEls.each(function() {
          query.fn.apply(this);
        });
			
        // Call the second function for elements no longer matched
        if ( this.fn2 && oEls.length > 0 )
          $.each(oEls, function(i, el) {
            if ( $.inArray(el, els) < 0 )
              query.fn2.apply(el);
          });
      }
    }
  };

  $.extend($.livequery, {
    guid: 0,
    queries: [],
    queue: [],
    running: false,
    timeout: null,
	
    checkQueue: function() {
      if ( $.livequery.running && $.livequery.queue.length ) {
        var length = $.livequery.queue.length;
        // Run each Live Query currently in the queue
        while ( length-- )
          $.livequery.queries[ $.livequery.queue.shift() ].run();
      }
    },
	
    pause: function() {
      // Don't run anymore Live Queries until restarted
      $.livequery.running = false;
    },
	
    play: function() {
      // Restart Live Queries
      $.livequery.running = true;
      // Request a run of the Live Queries
      $.livequery.run();
    },
	
    registerPlugin: function() {
      $.each( arguments, function(i,n) {
        // Short-circuit if the method doesn't exist
        if (!$.fn[n]) return;
			
        // Save a reference to the original method
        var old = $.fn[n];
			
        // Create a new method
        $.fn[n] = function() {
          // Call the original method
          var r = old.apply(this, arguments);
				
          // Request a run of the Live Queries
          $.livequery.run();
				
          // Return the original methods result
          return r;
        }
      });
    },
	
    run: function(id) {
      if (id != undefined) {
        // Put the particular Live Query in the queue if it doesn't already exist
        if ( $.inArray(id, $.livequery.queue) < 0 )
          $.livequery.queue.push( id );
      }
      else
        // Put each Live Query in the queue if it doesn't already exist
        $.each( $.livequery.queries, function(id) {
          if ( $.inArray(id, $.livequery.queue) < 0 )
            $.livequery.queue.push( id );
        });
		
      // Clear timeout if it already exists
      if ($.livequery.timeout) clearTimeout($.livequery.timeout);
      // Create a timeout to check the queue and actually run the Live Queries
      $.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
    },
	
    stop: function(id) {
      if (id != undefined)
        // Stop are particular Live Query
        $.livequery.queries[ id ].stop();
      else
        // Stop all Live Queries
        $.each( $.livequery.queries, function(id) {
          $.livequery.queries[ id ].stop();
        });
    }
  });

  // Register core DOM manipulation methods
  $.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove');

  // Run Live Queries when the Document is ready
  $(function() {
    $.livequery.play();
  });


  // Save a reference to the original init method
  var init = $.prototype.init;

  // Create a new init method that exposes two new properties: selector and context
  $.prototype.init = function(a,c) {
    // Call the original init and save the result
    var r = init.apply(this, arguments);
	
    // Copy over properties if they exist already
    if (a && a.selector)
      r.context = a.context, r.selector = a.selector;
		
    // Set properties
    if ( typeof a == 'string' )
      r.context = c || document, r.selector = a;
	
    // Return the result
    return r;
  };

  // Give the init function the jQuery prototype for later instantiation (needed after Rev 4091)
  $.prototype.init.prototype = $.prototype;
	
})(mnjQuery);


/* overlay plugin */
(function($){
  $.fn.oLay = function(options, origin) {
    var defaults = {
      opacity: .6,
      oLayBgColor: '#000',
      //contHt: 'auto',
      //contWt: 300,
      addy: '', //ajax url
      addyParam: '', //ajax params
      callback: null, //callback function fires on ajax success, returns response data
      oLayPosition: 'center', // center, mouse, coord
      oLayType: 'overLay', //overlay, popup
      pageContain: '.mn_outWrap', //keep popups within this box
      content: '', //popup/overlay content src
      type: '' //adding this due to conditional error, use dynamic for dhtml
    };

    var options = $.extend(defaults, options);
    $('.mn_oLayContainer').remove(); // close any that are open
    $('.mn_resetTab').removeClass('.mn_resetTab')
    var obj = $(this)

    // create the overlay div and containers for loading indicator and content
    $('body').prepend('<div class="mn_oLayContainer"><div class="mn_oLayInnerContain"><div class="mn_olayContentWrap"><div class="mn_oLayLoadImg"></div><div id="mn_olayResults" tabindex="1"></div></div><div class="mn_oLayBack"></div></div></div>');

    //get contents
    if (options.content != '' && options.type == ''){
      var newPop = $(options.content).clone(true);
      $('#mn_olayResults').append(newPop);
      $(newPop).css({
        position: 'static' // assuming offleft positioning
      });
      olayPos();
    }
    else {
      if (options.type != ''){
        if (options.type == 'dynamic'){
          $('#mn_olayResults').append($(options.content));
        }
        else if (options.type == 'noclone'){
          var par = $(options.content).parent();
          $('#mn_olayResults').append($(options.content));
        }
        else {
          $(options.content).remove().clone(true).prependTo('.mn_olayContentWrap');
        }
      }
      else {
        $.ajax({
          type: 'GET',
          async: false,
          url: options.addy,
          data: options.addyParam,
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            $('#mn_olayResults').html('There was a problem with your request, please try again.' +errorThrown + ':' +textStatus);
          },
          success: function(response) {
            // $('#mn_olayResults').html(response);

            if (options.callback){
              options.callback.call(this, response)
            }
            else {
              if (response.search(/mn_redirect=/i) == -1){
                $('#mn_olayResults').get(0).innerHTML = response; //fixes issue with IE

                ImageSwap.init();
                // custom functions
                if ($('#mn_tbody').length > 0){
                  tabAdjust(); //merchant overlay
                }
              //end custom functions
              }
              else {
                var a = response.split('=');
                location.href = a[1];
              }
            }

            olayPos();
            $('#mn_olayResults a').livequery(function(){
              var links = $('#mn_olayResults a[rel="external"]'); // grab all links with rel=external
              $(links).attr('target','_blank');
            });
          }
        });
      }
    }

    if (options.oLayType.toLowerCase() == 'overlay'){
      olayBack();
      if($.browser.msie && parseInt($.browser.version) < 7) {
        $(window).scroll(function(){
          olayPos();
        });
      }
      $(window).resize(function(){
        olayPos();
      });

      $(window).unload( function () {
        closeOlay();
      });
    }

    // set overlay position
    if (options.content != '' && options.oLayPosition != '')
      options.oLayPosition == 'center' ? olayPos() : olayMousePos();

    $('.mn_closePopBox, .mn_oLayBack').livequery('click', function(){
      closeOlay();
    });

    //keyboard functions
    $('#mn_olayResults').focus().css('outline','none');
    $(origin).addClass('mn_resetTab');
    $(document).keyup(function(event){
      var thepar = $(event.target).parents().is('.mn_oLayContainer')
      if((event.keyCode == 27) || (event.keyCode == 9 && thepar != true)){
        closeOlay();
        $('.mn_resetTab').focus().removeClass('mn_resetTab');
      }
    });




    function olayBack(){
      var winWidth = $(window).width();
      var docHeight = $(document).height(); //ie6
      var winHeight =  $(window).height();




      if ($('#mn_olayResults').outerHeight() > winHeight){
        var elemPosition = "absolute";
      }
      else {
        elemPosition = "fixed"
      }

      // IE6 doesn't understand fixed position
      if ($.browser.msie && parseInt($.browser.version) < 7) {
        $('.mn_oLayBack').css({
          top: 0,
          left: 0,
          width: '100%',
          height: docHeight,
          position: 'absolute',
          display: 'block',
          opacity: options.opacity,
          background: options.oLayBgColor,
          zIndex: 9999
        });

        $('select').css('visibility', 'hidden');
        $('.mn_oLayContainer select').css('visibility', 'visible');
      }
      else {
        $('.mn_oLayContainer').css({
          top: 0,
          left: 0,
          width: winWidth,
          height: winHeight,
          position: elemPosition,
          display: 'block',
          zIndex: 9999999
        }).show();


        // background with transparency
        $('.mn_oLayBack').css({
          opacity: options.opacity,
          position: 'absolute',
          top: 0,
          left: 0,
          bottom: 0,
          right: 0,
          width: winWidth,
          height: docHeight,
          background: options.oLayBgColor,
          zIndex: 9998
        });
      }
    // $('.mn_oLayBack').fadeTo(1000, options.opacity);
    }

    function olayPos(){
      var left, top;
      var winWidth = $(window).width();
      var winHeight =  $(window).height();
      var oLayResults = $('#mn_olayResults');
      var oLayHeight = $(oLayResults).children().height();
      var oLayWidth = $(oLayResults).children().width();

      if ($.browser.msie) {
        left = document.body.scrollLeft || document.documentElement.scrollLeft;
        top = document.body.scrollTop || document.documentElement.scrollTop;
      }
      else {
        left = window.pageXOffset;
        top = window.pageYOffset;
      }

      var topAbs = top + winHeight/2 - oLayHeight/2; //IE6
      var	leftAbs = left + winWidth/2 - oLayWidth/2; //IE6
      var topFix = topAbs - top;
      var	leftFix = leftAbs - left;


      // don't center vertically if  taller than window
      topAbs < 0 ? topAbs = 10 : '';
      topFix < 0 ? topFix = 10 : '';

      if ($('#mn_olayResults').outerHeight() > winHeight){
        var elemPosition = "absolute";
      }
      else {
        elemPosition = "fixed"
      }

      // ie6 doesn't support fixed positioning
      if ($.browser.msie && parseInt($.browser.version) < 7) {

        $('.mn_oLayInnerContain').children('.mn_olayContentWrap').css({
          top: topAbs,
          left: leftAbs,
          position: 'absolute',
          zIndex: 10000
        }).show();
      }
      else {
        $('.mn_oLayInnerContain').children('.mn_olayContentWrap').css({
          top: topFix,
          left: leftFix,
          position: elemPosition,
          zIndex: 10000
        }).show();
      }
    }

    function olayMousePos(){
      //find container boundries
      var offTop = $(options.pageContain).get(0).offsetTop;
      var offLeft = $(options.pageContain).get(0).offsetLeft;
      var offWidth = $(options.pageContain).get(0).offsetWidth;
      var offHeight = $(options.pageContain).get(0).offsetHeight;

      //pop up size
      var contWidth = $('.mn_oLayContainer').width();
      var contHeight = $('.mn_oLayContainer').height();

      //mouse coords
      var mLeft = event.pageX + 15;
      var mTop = event.pageY - contHeight -5;

      //find where box ends from point of click
      var contX = mLeft + contWidth;
      var contY = mTop + contHeight;

      //restrict pop up to page container
      var posLeft = 0, posTop = 0;
      if (contX > (offLeft + offWidth)){
        posLeft = contX - (offLeft + offWidth);
      }

      if (contY > (offTop + offHeight)){
        posTop = contY - (offTop + offHeight);
      }

      //restrict pop up to viewport
      var view = olayViewport();
      if (contX > (view.winX + view.winWidth)){
        posLeft = contX - (view.winX + view.winWidth);
      }

      if (contY > (view.winY + view.winHeight)){
        posTop = contY - (view.winY + view.winHeight);
      }

      $('.mn_oLayContainer').css({
        position: 'absolute',
        top: mTop - posTop -15,
        left: mLeft - posLeft -5,
        zIndex: 10000
      });
    }

    function olayViewport() {
      return {
        winX: $(window).scrollLeft(),
        winY: $(window).scrollTop(),
        winWidth: $(window).width(),
        winHeight: $(window).height()
      };
    }

    function closeOlay(){
      // $('.mn_oLayContainer').fadeTo(200, 0, function(){
      $('select').css('visibility', 'visible');

      if (options.type == 'noclone') {
        $(par).append($(options.content))
      }

      $('.mn_oLayContainer').remove();
    // });
    }

    //custom functions
    function tabAdjust(){
      var tbHt = $('#mn_tbody').height();
      var tabHt = $('#mn_tbody').children().height();
      if (tabHt < tbHt)
        $('#mn_tbody').height(tabHt);

      $('#mn_tbody').css({
        overflowX: 'hidden'
      });
    }

    function resizeImg(){
      if (typeof mn_imgRszOvr == 'function'){ //check for default override
        mn_imgRszOvr();
      }
      else{
        $('.mn_checkBig').imageAspect({
          maxHt: 300,
          maxWt: 300
        });
      }
    }

  };
})(mnjQuery);



//window resizing
(function($,sr){
 
  // debouncing function from John Hann
  // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
  var debounce = function (func, threshold, execAsap) {
    var timeout;
 
    return function debounced () {
      var obj = this, args = arguments;
      function delayed () {
        if (!execAsap)
          func.apply(obj, args);
        timeout = null;
      };
 
      if (timeout)
        clearTimeout(timeout);
      else if (execAsap)
        func.apply(obj, args);
 
      timeout = setTimeout(delayed, threshold || 100);
    };
  }
  // smartresize
  mnjQuery.fn[sr] = function(fn){
    return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
  };
 
})(mnjQuery,'smartresize');

    
// ******************
   
    
// Table Sorter Plugin
(function($){
  $.extend({
    tablesorter:new function(){
      var parsers=[],widgets=[];
      this.defaults={
        cssHeader:"header",
        cssAsc:"headerSortUp",
        cssDesc:"headerSortDown",
        sortInitialOrder:"asc",
        sortMultiSortKey:"shiftKey",
        sortForce:null,
        sortAppend:null,
        textExtraction:"simple",
        parsers:{},
        widgets:[],
        widgetZebra:{
          css:["even","odd"]
        },
        headers:{},
        widthFixed:false,
        cancelSelection:true,
        sortList:[],
        headerList:[],
        dateFormat:"us",
        decimal:'.',
        debug:false
      };

      function benchmark(s,d){
        log(s+","+(new Date().getTime()-d.getTime())+"ms");
      }
      this.benchmark=benchmark;
      function log(s){
        if(typeof console!="undefined"&&typeof console.debug!="undefined"){
          console.log(s);
        }else{
          alert(s);
        }
      }
      function buildParserCache(table,$headers){
        if(table.config.debug){
          var parsersDebug="";
        }
        var rows=table.tBodies[0].rows;
        if(table.tBodies[0].rows[0]){
          var list=[],cells=rows[0].cells,l=cells.length;
          for(var i=0;i<l;i++){
            var p=false;
            if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){
              p=getParserById($($headers[i]).metadata().sorter);
            }else if((table.config.headers[i]&&table.config.headers[i].sorter)){
              p=getParserById(table.config.headers[i].sorter);
            }
            if(!p){
              p=detectParserForColumn(table,cells[i]);
            }
            if(table.config.debug){
              parsersDebug+="column:"+i+" parser:"+p.id+"\n";
            }
            list.push(p);
          }
        }
        if(table.config.debug){
          log(parsersDebug);
        }
        return list;
      };

      function detectParserForColumn(table,node){
        var l=parsers.length;
        for(var i=1;i<l;i++){
          if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)){
            return parsers[i];
          }
        }
        return parsers[0];
      }
      function getParserById(name){
        var l=parsers.length;
        for(var i=0;i<l;i++){
          if(parsers[i].id.toLowerCase()==name.toLowerCase()){
            return parsers[i];
          }
        }
        return false;
      }
      function buildCache(table){
        if(table.config.debug){
          var cacheTime=new Date();
        }
        var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={
          row:[],
          normalized:[]
        };

        for(var i=0;i<totalRows;++i){
          var c=table.tBodies[0].rows[i],cols=[];
          cache.row.push($(c));
          for(var j=0;j<totalCells;++j){
            cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));
          }
          cols.push(i);
          cache.normalized.push(cols);
          cols=null;
        };

        if(table.config.debug){
          benchmark("Building cache for "+totalRows+" rows:",cacheTime);
        }
        return cache;
      };

      function getElementText(config,node){
        if(!node)return"";
        var t="";
        if(config.textExtraction=="simple"){
          if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){
            t=node.childNodes[0].innerHTML;
          }else{
            t=node.innerHTML;
          }
        }else{
          if(typeof(config.textExtraction)=="function"){
            t=config.textExtraction(node);
          }else{
            t=$(node).text();
          }
        }
        return t;
      }
      function appendToTable(table,cache){
        if(table.config.debug){
          var appendTime=new Date()
        }
        var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];
        for(var i=0;i<totalRows;i++){
          rows.push(r[n[i][checkCell]]);
          if(!table.config.appender){
            var o=r[n[i][checkCell]];
            var l=o.length;
            for(var j=0;j<l;j++){
              tableBody[0].appendChild(o[j]);
            }
          }
        }
        if(table.config.appender){
          table.config.appender(table,rows);
        }
        rows=null;
        if(table.config.debug){
          benchmark("Rebuilt table:",appendTime);
        }
        applyWidget(table);
        setTimeout(function(){
          $(table).trigger("sortEnd");
        },0);
      };

      function buildHeaders(table){
        if(table.config.debug){
          var time=new Date();
        }
        var meta=($.metadata)?true:false,tableHeadersRows=[];
        for(var i=0;i<table.tHead.rows.length;i++){
          tableHeadersRows[i]=0;
        };

        $tableHeaders=$("thead th",table);
        $tableHeaders.each(function(index){
          this.count=0;
          this.column=index;
          this.order=formatSortingOrder(table.config.sortInitialOrder);
          if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;
          if(!this.sortDisabled){
            $(this).addClass(table.config.cssHeader);
          }
          table.config.headerList[index]=this;
        });
        if(table.config.debug){
          benchmark("Built headers:",time);
          log($tableHeaders);
        }
        return $tableHeaders;
      };

      function checkCellColSpan(table,rows,row){
        var arr=[],r=table.tHead.rows,c=r[row].cells;
        for(var i=0;i<c.length;i++){
          var cell=c[i];
          if(cell.colSpan>1){
            arr=arr.concat(checkCellColSpan(table,headerArr,row++));
          }else{
            if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){
              arr.push(cell);
            }
          }
        }
        return arr;
      };

      function checkHeaderMetadata(cell){
        if(($.metadata)&&($(cell).metadata().sorter===false)){
          return true;
        };

        return false;
      }
      function checkHeaderOptions(table,i){
        if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){
          return true;
        };

        return false;
      }
      function applyWidget(table){
        var c=table.config.widgets;
        var l=c.length;
        for(var i=0;i<l;i++){
          getWidgetById(c[i]).format(table);
        }
      }
      function getWidgetById(name){
        var l=widgets.length;
        for(var i=0;i<l;i++){
          if(widgets[i].id.toLowerCase()==name.toLowerCase()){
            return widgets[i];
          }
        }
      };

      function formatSortingOrder(v){
        if(typeof(v)!="Number"){
          i=(v.toLowerCase()=="desc")?1:0;
        }else{
          i=(v==(0||1))?v:0;
        }
        return i;
      }
      function isValueInArray(v,a){
        var l=a.length;
        for(var i=0;i<l;i++){
          if(a[i][0]==v){
            return true;
          }
        }
        return false;
      }
      function setHeadersCss(table,$headers,list,css){
        $headers.removeClass(css[0]).removeClass(css[1]);
        var h=[];
        $headers.each(function(offset){
          if(!this.sortDisabled){
            h[this.column]=$(this);
          }
        });
        var l=list.length;
        for(var i=0;i<l;i++){
          h[list[i][0]].addClass(css[list[i][1]]);
        }
      }
      function fixColumnWidth(table,$headers){
        var c=table.config;
        if(c.widthFixed){
          var colgroup=$('<colgroup>');
          $("tr:first td",table.tBodies[0]).each(function(){
            colgroup.append($('<col>').css('width',$(this).width()));
          });
          $(table).prepend(colgroup);
        };

      }
      function updateHeaderSortCount(table,sortList){
        var c=table.config,l=sortList.length;
        for(var i=0;i<l;i++){
          var s=sortList[i],o=c.headerList[s[0]];
          o.count=s[1];
          o.count++;
        }
      }
      function multisort(table,sortList,cache){
        if(table.config.debug){
          var sortTime=new Date();
        }
        var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;
        for(var i=0;i<l;i++){
          var c=sortList[i][0];
          var order=sortList[i][1];
          var s=(getCachedSortType(table.config.parsers,c)=="text")?((order==0)?"sortText":"sortTextDesc"):((order==0)?"sortNumeric":"sortNumericDesc");
          var e="e"+i;
          dynamicExp+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";
          dynamicExp+="if("+e+") { return "+e+"; } ";
          dynamicExp+="else { ";
        }
        var orgOrderCol=cache.normalized[0].length-1;
        dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";
        for(var i=0;i<l;i++){
          dynamicExp+="}; ";
        }
        dynamicExp+="return 0; ";
        dynamicExp+="}; ";
        eval(dynamicExp);
        cache.normalized.sort(sortWrapper);
        if(table.config.debug){
          benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);
        }
        return cache;
      };

      function sortText(a,b){
        return((a<b)?-1:((a>b)?1:0));
      };

      function sortTextDesc(a,b){
        return((b<a)?-1:((b>a)?1:0));
      };

      function sortNumeric(a,b){
        return a-b;
      };

      function sortNumericDesc(a,b){
        return b-a;
      };

      function getCachedSortType(parsers,i){
        return parsers[i].type;
      };

      this.construct=function(settings){
        return this.each(function(){
          if(!this.tHead||!this.tBodies)return;
          var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;
          this.config={};

          config=$.extend(this.config,$.tablesorter.defaults,settings);
          $this=$(this);
          $headers=buildHeaders(this);
          this.config.parsers=buildParserCache(this,$headers);
          cache=buildCache(this);
          var sortCSS=[config.cssDesc,config.cssAsc];
          fixColumnWidth(this);
          $headers.click(function(e){
            $this.trigger("sortStart");
            var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;
            if(!this.sortDisabled&&totalRows>0){
              var $cell=$(this);
              var i=this.column;
              this.order=this.count++%2;
              if(!e[config.sortMultiSortKey]){
                config.sortList=[];
                if(config.sortForce!=null){
                  var a=config.sortForce;
                  for(var j=0;j<a.length;j++){
                    if(a[j][0]!=i){
                      config.sortList.push(a[j]);
                    }
                  }
                }
                config.sortList.push([i,this.order]);
              }else{
                if(isValueInArray(i,config.sortList)){
                  for(var j=0;j<config.sortList.length;j++){
                    var s=config.sortList[j],o=config.headerList[s[0]];
                    if(s[0]==i){
                      o.count=s[1];
                      o.count++;
                      s[1]=o.count%2;
                    }
                  }
                }else{
                  config.sortList.push([i,this.order]);
                }
              };

              setTimeout(function(){
                setHeadersCss($this[0],$headers,config.sortList,sortCSS);
                appendToTable($this[0],multisort($this[0],config.sortList,cache));
              },1);
              return false;
            }
          }).mousedown(function(){
            if(config.cancelSelection){
              this.onselectstart=function(){
                return false
              };

              return false;
            }
          });
          $this.bind("update",function(){
            this.config.parsers=buildParserCache(this,$headers);
            cache=buildCache(this);
          }).bind("sorton",function(e,list){
            $(this).trigger("sortStart");
            config.sortList=list;
            var sortList=config.sortList;
            updateHeaderSortCount(this,sortList);
            setHeadersCss(this,$headers,sortList,sortCSS);
            appendToTable(this,multisort(this,sortList,cache));
          }).bind("appendCache",function(){
            appendToTable(this,cache);
          }).bind("applyWidgetId",function(e,id){
            getWidgetById(id).format(this);
          }).bind("applyWidgets",function(){
            applyWidget(this);
          });
          if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){
            config.sortList=$(this).metadata().sortlist;
          }
          if(config.sortList.length>0){
            $this.trigger("sorton",[config.sortList]);
          }
          applyWidget(this);
        });
      };

      this.addParser=function(parser){
        var l=parsers.length,a=true;
        for(var i=0;i<l;i++){
          if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){
            a=false;
          }
        }
        if(a){
          parsers.push(parser);
        };

      };

      this.addWidget=function(widget){
        widgets.push(widget);
      };

      this.formatFloat=function(s){
        var i=parseFloat(s);
        return(isNaN(i))?0:i;
      };

      this.formatInt=function(s){
        var i=parseInt(s);
        return(isNaN(i))?0:i;
      };

      this.isDigit=function(s,config){
        var DECIMAL='\\'+config.decimal;
        var exp='/(^[+]?0('+DECIMAL+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+DECIMAL+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+DECIMAL+'0+$)/';
        return RegExp(exp).test($.trim(s));
      };

      this.clearTableBody=function(table){
        if($.browser.msie){
          function empty(){
            while(this.firstChild)this.removeChild(this.firstChild);
          }
          empty.apply(table.tBodies[0]);
        }else{
          table.tBodies[0].innerHTML="";
        }
      };

    }
  });
  $.fn.extend({
    tablesorter:$.tablesorter.construct
  });
  var ts=$.tablesorter;
  ts.addParser({
    id:"text",
    is:function(s){
      return true;
    },
    format:function(s){
      return $.trim(s.toLowerCase());
    },
    type:"text"
  });
  ts.addParser({
    id:"digit",
    is:function(s,table){
      var c=table.config;
      return $.tablesorter.isDigit(s,c);
    },
    format:function(s){
      return $.tablesorter.formatFloat(s);
    },
    type:"numeric"
  });
  ts.addParser({
    id:"currency",
    is:function(s){
      return/^[£$€?.]/.test(s);
    },
    format:function(s){
      return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
    },
    type:"numeric"
  });
  ts.addParser({
    id:"ipAddress",
    is:function(s){
      return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);
    },
    format:function(s){
      var a=s.split("."),r="",l=a.length;
      for(var i=0;i<l;i++){
        var item=a[i];
        if(item.length==2){
          r+="0"+item;
        }else{
          r+=item;
        }
      }
      return $.tablesorter.formatFloat(r);
    },
    type:"numeric"
  });
  ts.addParser({
    id:"url",
    is:function(s){
      return/^(https?|ftp|file):\/\/$/.test(s);
    },
    format:function(s){
      return mnmnjQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));
    },
    type:"text"
  });
  ts.addParser({
    id:"isoDate",
    is:function(s){
      return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);
    },
    format:function(s){
      return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");
    },
    type:"numeric"
  });
  ts.addParser({
    id:"percent",
    is:function(s){
      return/\%$/.test($.trim(s));
    },
    format:function(s){
      return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));
    },
    type:"numeric"
  });
  ts.addParser({
    id:"usLongDate",
    is:function(s){
      return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));
    },
    format:function(s){
      return $.tablesorter.formatFloat(new Date(s).getTime());
    },
    type:"numeric"
  });
  ts.addParser({
    id:"shortDate",
    is:function(s){
      return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
    },
    format:function(s,table){
      var c=table.config;
      s=s.replace(/\-/g,"/");
      if(c.dateFormat=="us"){
        s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");
      }else if(c.dateFormat=="uk"){
        s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");
      }else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){
        s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");
      }
      return $.tablesorter.formatFloat(new Date(s).getTime());
    },
    type:"numeric"
  });
  ts.addParser({
    id:"time",
    is:function(s){
      return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);
    },
    format:function(s){
      return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());
    },
    type:"numeric"
  });
  ts.addParser({
    id:"metadata",
    is:function(s){
      return false;
    },
    format:function(s,table,cell){
      var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;
      return $(cell).metadata()[p];
    },
    type:"numeric"
  });
  ts.addWidget({
    id:"zebra",
    format:function(table){
      if(table.config.debug){
        var time=new Date();
      }
      $("tr:visible",table.tBodies[0]).filter(':even').removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0]).end().filter(':odd').removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);
      if(table.config.debug){
        $.tablesorter.benchmark("Applying Zebra widget",time);
      }
    }
  });
})(mnjQuery);

// PNG Transparency Plugin
(function($){
  $.fn.pngFix=function(settings){
    settings=$.extend({
      blankgif:'blank.gif'
    },settings);
    var ie55=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 5.5")!=-1);
    var ie6=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 6.0")!=-1);
    if($.browser.msie&&(ie55||ie6)){
      $(this).find("img[src$=.png]").each(function(){
        $(this).attr('width',$(this).width());
        $(this).attr('height',$(this).height());
        var prevStyle='';
        var strNewHTML='';
        var imgId=($(this).attr('id'))?'id="'+$(this).attr('id')+'" ':'';
        var imgClass=($(this).attr('class'))?'class="'+$(this).attr('class')+'" ':'';
        var imgTitle=($(this).attr('title'))?'title="'+$(this).attr('title')+'" ':'';
        var imgAlt=($(this).attr('alt'))?'alt="'+$(this).attr('alt')+'" ':'';
        var imgAlign=($(this).attr('align'))?'float:'+$(this).attr('align')+';':'';
        var imgHand=($(this).parent().attr('href'))?'cursor:hand;':'';
        if(this.style.border){
          prevStyle+='border:'+this.style.border+';';
          this.style.border='';
        }
        if(this.style.padding){
          prevStyle+='padding:'+this.style.padding+';';
          this.style.padding='';
        }
        if(this.style.margin){
          prevStyle+='margin:'+this.style.margin+';';
          this.style.margin='';
        }
        var imgStyle=(this.style.cssText);
        strNewHTML+='<span '+imgId+imgClass+imgTitle+imgAlt;
        strNewHTML+='style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
        strNewHTML+='width:'+$(this).width()+'px;'+'height:'+$(this).height()+'px;';
        strNewHTML+='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+$(this).attr('src')+'\', sizingMethod=\'scale\');';
        strNewHTML+=imgStyle+'"></span>';
        if(prevStyle!=''){
          strNewHTML='<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:'+$(this).width()+'px;'+'height:'+$(this).height()+'px;'+'">'+strNewHTML+'</span>';
        }
        $(this).hide();
        $(this).after(strNewHTML);
      });
      $(this).find("*").each(function(){
        var bgIMG=$(this).css('background-image');
        if(bgIMG.indexOf(".png")!=-1){
          var iebg=bgIMG.split('url("')[1].split('")')[0];
          $(this).css('background-image','none');
          $(this).get(0).runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+iebg+"',sizingMethod='scale')";
        }
      });
      $(this).find("input[src$=.png]").each(function(){
        var bgIMG=$(this).attr('src');
        $(this).get(0).runtimeStyle.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+bgIMG+'\', sizingMethod=\'scale\');';
        $(this).attr('src',settings.blankgif)
      });
    }
    return $;
  };

})(mnjQuery);
    

/*
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
mnjQuery.cookie = function(name, value, options) {
  if (typeof value != 'undefined') { // name and value given, set cookie
    options = options || {};
    if (value === null) {
      value = '';
      options.expires = -1;
    }
    var expires = '';
    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
      var date;
      if (typeof options.expires == 'number') {
        date = new Date();
        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
      } else {
        date = options.expires;
      }
      expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
    }
    // CAUTION: Needed to parenthesize options.path and options.domain
    // in the following expressions, otherwise they evaluate to undefined
    // in the packed version for some reason...
    var path = options.path ? '; path=' + (options.path) : '';
    var domain = options.domain ? '; domain=' + (options.domain) : '';
    var secure = options.secure ? '; secure' : '';
    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  } else { // only name given, get cookie
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
        var cookie = mnjQuery.trim(cookies[i]);
        // Does this cookie string begin with the name we want?
        if (cookie.substring(0, name.length + 1) == (name + '=')) {
          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
          break;
        }
      }
    }
    return cookieValue;
  }
};
// makeGroups
(function(mnjQuery){
  // plugin to group multiple elements for paging, etc.
  $.fn.makeGroups = function(opts){
    var opts = $.extend(opts);
   
    var container = this;
    var type = container.get(0) && container.get(0).tagName || 'DIV';
    var isListType = type.match(/(UL|OL)/);
    var items = container.children();
        
    // check for exclusions
    if (opts.exclude){
      items = items.not(opts.exclude);
    }

    // store heights of items
    items.each(function(){
      var elem = $(this);
      elem.data('height',elem.outerHeight(true));
    });

    // set default amount of items per group
    var grpCount = opts.groupCount || 3;

    // get the number of groups
    var grpAmt = Math.ceil(items.length/grpCount);

    if (grpAmt > 1) { // do nothing if only one group
      // Slice groups and wrap
      if (isListType) {
        var elems = items.clone(true);
        for(var i=0;i<grpAmt;i++) {
          var grp = elems.slice(i*grpCount,(i+1)*grpCount);
          grp.wrapAll('<'+type+' class="mn_contGrp"></'+type+'>');
          var parent = grp.parent();
          parent.hide();
          container.before(parent);
          $('mn_contGrp').css('width', $('mn_contGroup').contents().outerWidth());
        }
        container.remove();
      } else {
        for(var i=0;i<grpAmt;i++) {
          items.slice(i*grpCount,(i+1)*grpCount).wrapAll('<div class="mn_contGrp" />');
          $('mn_contGrp').css('width', $('mn_contGroup').contents().outerWidth());
        }
      }
    }

    // optional callback
    if (opts.callback) opts.callback.call(this);
  }
})(mnjQuery);



//date picker
//calendar plugin

/*
mn_jdPicker 1.0
Requires jQuery version: >= 1.2.6

2010 - ? -- Paul Da Silva, AMJ Groupe

Copyright (c) 2007-2008 Jonathan Leighton & Torchbox Ltd

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
mn_jdPicker = (function($) {

  function mn_jdPicker(el, opts) {
    if (typeof(opts) != "object") opts = {};
    $.extend(this, mn_jdPicker.DEFAULT_OPTS, opts);

    this.input = $(el);
    this.bindMethodsToObj("show", "hide", "hideIfClickOutside", "keydownHandler", "selectDate");

    this.build();
    this.selectDate();

    this.hide();
  };
  mn_jdPicker.DEFAULT_OPTS = {
    month_names: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    short_month_names: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
    short_day_names: ["S", "M", "T", "W", "T", "F", "S"],
    error_out_of_range: "Selected date is out of range",
    selectable_days: [0, 1, 2, 3, 4, 5, 6],
    non_selectable: [],
    rec_non_selectable: [],
    start_of_week: 0,
    show_week: 0,
    select_week: 0,
    week_label: "",
    date_min: "",
    date_max: "",
    date_format: "mm/dd/YYYY"
  };
  mn_jdPicker.prototype = {
    build: function() {

      this.wrapp = this.input.wrap('<div class="jdpicker_w">');

      if(this.input.context.type!="hidden"){
        var clearer = $('<span title="clear field" class="date_clearer">&times;</span>');
        clearer.click(this.bindToObj(function(){
          this.input.val("");
          this.selectDate();
        }));
        this.input.after(clearer);
      }

      switch (this.date_format){
        case "dd/mm/YYYY":
          this.reg = new RegExp(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
          this.date_decode = "new Date(matches[3], parseInt(matches[2]-1), matches[1]);";
          this.date_encode = 'this.strpad(date.getDate()) + "/" + this.strpad(date.getMonth()+1) + "/" + date.getFullYear();';
          this.date_encode_s = 'this.strpad(date.getDate()) + "/" + this.strpad(date.getMonth()+1)';
          break;
        case "FF dd YYYY":
          this.reg = new RegExp(/^([a-zA-Z]+) (\d{1,2}) (\d{4})$/);
          this.date_decode = "new Date(matches[3], this.indexFor(this.month_names, matches[1]), matches[2]);";
          this.date_encode = 'this.month_names[date.getMonth()] + " " + this.strpad(date.getDate()) + " " + date.getFullYear();';
          this.date_encode_s = 'this.month_names[date.getMonth()] + " " + this.strpad(date.getDate());';
          break;
        case "dd MM YYYY":
          this.reg = new RegExp(/^(\d{1,2}) ([a-zA-Z]{3}) (\d{4})$/);
          this.date_decode = "new Date(matches[3], this.indexFor(this.short_month_names, matches[2]), matches[1]);";
          this.date_encode = 'this.strpad(date.getDate()) + " " + this.short_month_names[date.getMonth()] + " " + date.getFullYear();';
          this.date_encode_s = 'this.strpad(date.getDate()) + " " + this.short_month_names[date.getMonth()];';
          break;
        case "MM dd YYYY":
          this.reg = new RegExp(/^([a-zA-Z]{3}) (\d{1,2}) (\d{4})$/);
          this.date_decode = "new Date(matches[3], this.indexFor(this.short_month_names, matches[1]), matches[2]);";
          this.date_encode = 'this.short_month_names[date.getMonth()] + " " + this.strpad(date.getDate()) + " " + date.getFullYear();';
          this.date_encode_s = 'this.short_month_names[date.getMonth()] + " " + this.strpad(date.getDate());';
          break;
        case "dd FF YYYY":
          this.reg = new RegExp(/^(\d{1,2}) ([a-zA-Z]+) (\d{4})$/);
          this.date_decode = "new Date(matches[3], this.indexFor(this.month_names, matches[2]), matches[1]);";
          this.date_encode = 'this.strpad(date.getDate()) + " " + this.month_names[date.getMonth()] + " " + date.getFullYear();';
          this.date_encode_s = 'this.strpad(date.getDate()) + " " + this.month_names[date.getMonth()];';
          break;
        case "YYYY-mm-dd":
          this.reg = new RegExp(/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/);
          this.date_decode = "new Date(matches[1], parseInt(matches[2]-1), matches[3]);";
          this.date_encode = 'date.getFullYear() + "-" + this.strpad(date.getMonth()+1) + "-" + this.strpad(date.getDate());';
          this.date_encode_s = 'this.strpad(date.getMonth()+1) + "-" + this.strpad(date.getDate());';
          break;
        case "YYYY/mm/dd":
        default:
          this.reg = new RegExp(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/);
          this.date_decode = "new Date(matches[1], parseInt(matches[2]-1), matches[3]);";
          this.date_encode = 'date.getFullYear() + "/" + this.strpad(date.getMonth()+1) + "/" + this.strpad(date.getDate());';
          this.date_encode_s = 'this.strpad(date.getMonth()+1) + "/" + this.strpad(date.getDate());';
          break;
        case "mm/dd/YYYY":
          this.reg = new RegExp(/^(\d{1,2}) ([a-zA-Z]{3}) (\d{4})$/);
          this.date_decode = "new Date(matches[1], parseInt(matches[2]-1), matches[3]);";
          this.date_encode = 'this.strpad(date.getMonth()+1) + "/" + this.strpad(date.getDate()) + "/" + date.getFullYear();';
          this.date_encode_s = 'this.strpad(date.getMonth()+1) + "/" + this.strpad(date.getDate());';
          break;
      }

      if(this.date_max != "" && this.date_max.match(this.reg)){
        var matches = this.date_max.match(this.reg);
        this.date_max = eval(this.date_decode);
      }else
        this.date_max = "";

      if(this.date_min != "" && this.date_min.match(this.reg)){
        var matches = this.date_min.match(this.reg);
        this.date_min = eval(this.date_decode);
      }else
        this.date_min = "";

      var monthNav = $('<p class="month_nav">' +
        '<span class="button prev" title="[Page-Up]">&#171;</span>' +
        ' <span class="month_name"></span> ' +
        '<span class="button next" title="[Page-Down]">&#187;</span>' +
        '</p>');

      this.monthNameSpan = $(".month_name", monthNav);
      $(".prev", monthNav).click(this.bindToObj(function() {
        this.moveMonthBy(-1);
      }));
      $(".next", monthNav).click(this.bindToObj(function() {
        this.moveMonthBy(1);
      }));

      this.monthNameSpan.dblclick(this.bindToObj(function(){
        this.monthNameSpan.empty().append(this.getMonthSelect());
        $('select', this.monthNameSpan).change(this.bindToObj(function(){
          this.moveMonthBy(parseInt($('select :selected', this.monthNameSpan).val()) - this.currentMonth.getMonth());
        }));
      }));

      var yearNav = $('<p class="year_nav">' +
        '<span class="button prev" title="[Ctrl+Page-Up]">&#171;</span>' +
        ' <span class="year_name" id="year_name"></span> ' +
        '<span class="button next" title="[Ctrl+Page-Down]">&#187;</span>' +
        '</p>');

      this.yearNameSpan = $(".year_name", yearNav);
      $(".prev", yearNav).click(this.bindToObj(function() {
        this.moveMonthBy(-12);
      }));
      $(".next", yearNav).click(this.bindToObj(function() {
        this.moveMonthBy(12);
      }));

      this.yearNameSpan.dblclick(this.bindToObj(function(){

        if($('.year_name input', this.rootLayers).length==0){
          var initialDate = this.yearNameSpan.html();

          var yearNameInput = $('<input type="text" class="text year_input" value="'+initialDate+'" />');
          this.yearNameSpan.empty().append(yearNameInput);

          $(".year_input", yearNav).keyup(this.bindToObj(function(){
            if($('input',this.yearNameSpan).val().length == 4 && $('input',this.yearNameSpan).val() != initialDate && parseInt($('input',this.yearNameSpan).val()) == $('input',this.yearNameSpan).val()){
              this.moveMonthBy(parseInt(parseInt(parseInt($('input',this.yearNameSpan).val()) - initialDate)*12));
            }else if($('input',this.yearNameSpan).val().length>4)
              $('input',this.yearNameSpan).val($('input',this.yearNameSpan).val().substr(0, 4));
          }));

          $('input',this.yearNameSpan).focus();
          $('input',this.yearNameSpan).select();
        }

      }));

      var error_msg = $('<div class="error_msg"></div>');

      var nav = $('<div class="nav"></div>').append(error_msg, monthNav, yearNav);

      var tableShell = "<table><thead><tr>";

      if(this.show_week == 1) tableShell +='<th class="week_label">'+(this.week_label)+'</th>';

      $(this.adjustDays(this.short_day_names)).each(function() {
        tableShell += "<th>" + this + "</th>";
      });

      tableShell += "</tr></thead><tbody></tbody></table>";

      var style = (this.input.context.type=="hidden")?' style="display:block; position:static; margin:0 auto"':'';

      this.dateSelector = this.rootLayers = $('<div class="date_selector" '+style+'></div>').append(nav, tableShell).insertAfter(this.input);

      if ($.browser.msie && $.browser.version < 7) {
        this.ieframe = $('<iframe class="date_selector_ieframe" frameborder="0" src="javascript:void(0)"></iframe>').insertBefore(this.dateSelector);
        this.rootLayers = this.rootLayers.add(this.ieframe);
        $(".button", nav).mouseover(function() {
          $(this).addClass("hover");
        });
        $(".button", nav).mouseout(function() {
          $(this).removeClass("hover");
        });
      };

      this.tbody = $("tbody", this.dateSelector);

      this.input.change(this.bindToObj(function() {
        this.selectDate();
      }));
      this.selectDate();

    },

    selectMonth: function(date) {
      var newMonth = new Date(date.getFullYear(), date.getMonth(), date.getDate());
      if(this.isNewDateAllowed(newMonth)){
        if (!this.currentMonth || !(this.currentMonth.getFullYear() == newMonth.getFullYear() &&
          this.currentMonth.getMonth() == newMonth.getMonth())) {

          this.currentMonth = newMonth;

          var rangeStart = this.rangeStart(date), rangeEnd = this.rangeEnd(date);
          var numDays = this.daysBetween(rangeStart, rangeEnd);
          var dayCells = "";

          for (var i = 0; i <= numDays; i++) {
            var currentDay = new Date(rangeStart.getFullYear(), rangeStart.getMonth(), rangeStart.getDate() + i, 12, 00);

            if (this.isFirstDayOfWeek(currentDay)){

              var firstDayOfWeek = currentDay;
              var lastDayOfWeek = new Date(currentDay.getFullYear(), currentDay.getMonth(), currentDay.getDate()+6, 12, 00);

              if(this.select_week && this.isNewDateAllowed(firstDayOfWeek))
                dayCells += "<tr date='" + this.dateToString(currentDay) + "' class='selectable_week'>";
              else
                dayCells += "<tr>";

              if(this.show_week==1)
                dayCells += '<td class="week_num">'+this.getWeekNum(currentDay)+'</td>';
            }
            if ((this.select_week == 0 && currentDay.getMonth() == date.getMonth() && this.isNewDateAllowed(currentDay) && !this.isHoliday(currentDay)) || (this.select_week==1 && currentDay.getMonth() == date.getMonth() && this.isNewDateAllowed(firstDayOfWeek))) {
              dayCells += '<td class="selectable_day" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>';
            } else {
              dayCells += '<td class="unselected_month" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>';
            };

            if (this.isLastDayOfWeek(currentDay)) dayCells += "</tr>";
          };
          this.tbody.empty().append(dayCells);

          this.monthNameSpan.empty().append(this.monthName(date));
          this.yearNameSpan.empty().append(this.currentMonth.getFullYear());

          if(this.select_week == 0){
            $(".selectable_day", this.tbody).click(this.bindToObj(function(event) {
              this.changeInput($(event.target).attr("date"));
            }));
          }else{
            $(".selectable_week", this.tbody).click(this.bindToObj(function(event) {
              this.changeInput($(event.target.parentNode).attr("date"));
            }));
          }

          $("td[date=" + this.dateToString(new Date()) + "]", this.tbody).addClass("today");
          if(this.select_week == 1){
            $("tr", this.tbody).mouseover(function() {
              $(this).addClass("hover");
            });
            $("tr", this.tbody).mouseout(function() {
              $(this).removeClass("hover");
            });
          }else{
            $("td.selectable_day", this.tbody).mouseover(function() {
              $(this).addClass("hover");
            });
            $("td.selectable_day", this.tbody).mouseout(function() {
              $(this).removeClass("hover");
            });
          }
        };

        $('.selected', this.tbody).removeClass("selected");
        $('td[date=' + this.selectedDateString + '], tr[date=' + this.selectedDateString + ']', this.tbody).addClass("selected");
      }else
        this.show_error(this.error_out_of_range);
    },

    selectDate: function(date) {
      if (typeof(date) == "undefined") {
        date = this.stringToDate(this.input.val());
      };
      if (!date) date = new Date();

      if(this.select_week == 1 && !this.isFirstDayOfWeek(date))
        date = new Date(date.getFullYear(), date.getMonth(), (date.getDate() - date.getDay() + this.start_of_week), 12, 00);

      if(this.isNewDateAllowed(date)){
        this.selectedDate = date;
        this.selectedDateString = this.dateToString(this.selectedDate);
        this.selectMonth(this.selectedDate);
      }else if((this.date_min) && this.daysBetween(this.date_min, date)<0){
        this.selectedDate = this.date_min;
        this.selectMonth(this.date_min);
        this.input.val(" ");
      }else{
        this.selectMonth(this.date_max);
        this.input.val(" ");
      }
    },

    isNewDateAllowed: function(date){
      return ((!this.date_min) || this.daysBetween(this.date_min, date)>=0) && ((!this.date_max) || this.daysBetween(date, this.date_max)>=0);
    },

    isHoliday: function(date){
      return ((this.indexFor(this.selectable_days, date.getDay())===false || this.indexFor(this.non_selectable, this.dateToString(date))!==false) || this.indexFor(this.rec_non_selectable, this.dateToShortString(date))!==false);
    },

    changeInput: function(dateString) {
      this.input.val(dateString).change();
      if(this.input.context.type!="hidden")
        this.hide();
    },

    show: function() {
      $('.error_msg', this.rootLayers).css('display', 'none');
      this.rootLayers.slideDown();
      $([window, document.body]).click(this.hideIfClickOutside);
      this.input.unbind("focus", this.show);
      this.input.attr('readonly', true);
      $(document.body).keydown(this.keydownHandler);
      this.setPosition();
    },

    hide: function() {
      if(this.input.context.type!="hidden"){
        this.input.removeAttr('readonly');
        this.rootLayers.slideUp();
        $([window, document.body]).unbind("click", this.hideIfClickOutside);
        this.input.focus(this.show);
        $(document.body).unbind("keydown", this.keydownHandler);
      }
    },

    hideIfClickOutside: function(event) {
      if (event.target != this.input[0] && !this.insideSelector(event)) {
        this.hide();
      };
    },

    insideSelector: function(event) {
      var offset = this.dateSelector.position();
      offset.right = offset.left + this.dateSelector.outerWidth();
      offset.bottom = offset.top + this.dateSelector.outerHeight();

      return event.pageY < offset.bottom &&
      event.pageY > offset.top &&
      event.pageX < offset.right &&
      event.pageX > offset.left;
    },

    keydownHandler: function(event) {
      switch (event.keyCode)
      {
        case 9:
        case 27:
          this.hide();
          return;
          break;
        case 13:
          if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
            this.changeInput(this.selectedDateString);
          break;
        case 33:
          this.moveDateMonthBy(event.ctrlKey ? -12 : -1);
          break;
        case 34:
          this.moveDateMonthBy(event.ctrlKey ? 12 : 1);
          break;
        case 38:
          this.moveDateBy(-7);
          break;
        case 40:
          this.moveDateBy(7);
          break;
        case 37:
          if(this.select_week == 0) this.moveDateBy(-1);
          break;
        case 39:
          if(this.select_week == 0) this.moveDateBy(1);
          break;
        default:
          return;
      }
      event.preventDefault();
    },

    stringToDate: function(string) {
      var matches;

      if (matches = string.match(this.reg)) {
        if(matches[3]==0 && matches[2]==0 && matches[1]==0)
          return null;
        else
          return eval(this.date_decode);
      } else {
        return null;
      };
    },

    dateToString: function(date) {
      return eval(this.date_encode);
    },

    dateToShortString: function(date){
      return eval(this.date_encode_s);
    },

    setPosition: function() {
      var offset = this.input.offset();
      this.rootLayers.css({
        top: offset.top + this.input.outerHeight(),
        left: offset.left
      });

      if (this.ieframe) {
        this.ieframe.css({
          width: this.dateSelector.outerWidth(),
          height: this.dateSelector.outerHeight()
        });
      };
    },

    moveDateBy: function(amount) {
      var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), this.selectedDate.getDate() + amount);
      this.selectDate(newDate);
    },

    moveDateMonthBy: function(amount) {
      var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth() + amount, this.selectedDate.getDate());
      if (newDate.getMonth() == this.selectedDate.getMonth() + amount + 1) {
        newDate.setDate(0);
      };
      this.selectDate(newDate);
    },

    moveMonthBy: function(amount) {
      if(amount<0)
        var newMonth = new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + amount+1, -1);
      else
        var newMonth = new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + amount, 1);
      this.selectMonth(newMonth);
    },

    monthName: function(date) {
      return this.month_names[date.getMonth()];
    },

    getMonthSelect:function(){
      var month_select = '<select>';
      for(var i = 0; i<this.month_names.length; i++){
        if(i==this.currentMonth.getMonth())
          month_select += '<option value="'+(i)+'" selected="selected">'+this.month_names[i]+'</option>';
        else
          month_select += '<option value="'+(i)+'">'+this.month_names[i]+'</option>';
      }
      month_select += '</select>';

      return month_select;
    },

    bindToObj: function(fn) {
      var self = this;
      return function() {
        return fn.apply(self, arguments)
      };
    },

    bindMethodsToObj: function() {
      for (var i = 0; i < arguments.length; i++) {
        this[arguments[i]] = this.bindToObj(this[arguments[i]]);
      };
    },

    indexFor: function(array, value) {
      for (var i = 0; i < array.length; i++) {
        if (value == array[i]) return i;
      };
      return false;
    },

    monthNum: function(month_name) {
      return this.indexFor(this.month_names, month_name);
    },

    shortMonthNum: function(month_name) {
      return this.indexFor(this.short_month_names, month_name);
    },

    shortDayNum: function(day_name) {
      return this.indexFor(this.short_day_names, day_name);
    },

    daysBetween: function(start, end) {
      start = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
      end = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
      return (end - start) / 86400000;
    },

    changeDayTo: function(dayOfWeek, date, direction) {
      var difference = direction * (Math.abs(date.getDay() - dayOfWeek - (direction * 7)) % 7);
      return new Date(date.getFullYear(), date.getMonth(), date.getDate() + difference);
    },

    rangeStart: function(date) {
      return this.changeDayTo(this.start_of_week, new Date(date.getFullYear(), date.getMonth()), -1);
    },

    rangeEnd: function(date) {
      return this.changeDayTo((this.start_of_week - 1) % 7, new Date(date.getFullYear(), date.getMonth() + 1, 0), 1);
    },

    isFirstDayOfWeek: function(date) {
      return date.getDay() == this.start_of_week;
    },

    getWeekNum:function(date){
      date_week= new Date(date.getFullYear(), date.getMonth(), date.getDate()+6);
      var firstDayOfYear = new Date(date_week.getFullYear(), 0, 1, 12, 00);
      var n = parseInt(this.daysBetween(firstDayOfYear, date_week)) + 1;
      return Math.floor((date_week.getDay() + n + 5)/7) - Math.floor(date_week.getDay() / 5);
    },

    isLastDayOfWeek: function(date) {
      return date.getDay() == (this.start_of_week - 1) % 7;
    },

    show_error: function(error){
      $('.error_msg', this.rootLayers).html(error);
      $('.error_msg', this.rootLayers).slideDown(400, function(){
        setTimeout("$('.error_msg', this.rootLayers).slideUp(200);", 2000);
      });
    },

    adjustDays: function(days) {
      var newDays = [];
      for (var i = 0; i < days.length; i++) {
        newDays[i] = days[(i + this.start_of_week) % 7];
      };
      return newDays;
    },

    strpad: function(num){
      if(parseInt(num)<10)	return "0"+parseInt(num);
      else	return parseInt(num);
    }

  };

  $.fn.mn_jdPicker = function(opts) {
    return this.each(function() {
      new mn_jdPicker(this, opts);
    });
  };
  $.mn_jdPicker = {
    initialize: function(opts) {
      $("input.jdpicker").mn_jdPicker(opts);
    }
  };

  return mn_jdPicker;
})(mnjQuery);

$($.mn_jdPicker.initialize);



  /*
http://www.html-advisor.com/javascript/hide-email-with-javascript-jquery/
Example markup:
---------------
<span class="mailme" title="Send me a letter!">me at mydomain dot com</span>
Example code:
	-------------
	// Replaces all the matching elements with a <a href="mailto:..> tag.
$('span.mailme').mailme();
*/

  mnjQuery.fn.mailme = function() {
    var at = / at /;
    var dot = / dot /g;
    this.each( function() {
      var addr = mnjQuery(this).text().replace(at,"@").replace(dot,".");
      var title = mnjQuery(this).attr('title')
      $(this)
      .after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
      .remove();
    });
  };



//zip code validation
(function($){
  $.fn.zipVal = function(opts){
    var opts = $.extend(opts);
    var el = $(this);
    var zVal = el.val();
    if (zVal == '' && !opts.noBlank){
      opts.callback.call(this, 'true');
    }
    else {
      var exp = /^(?!0{5})(\d{5})(?!-?0{4})(-?\d{4})?$/i;
      var result = exp.test(zVal);
      if (!result && !opts.custom){
        el.parent().prepend('<p class="mn_err">Please enter a valid zip code.</p>');
        opts.callback.call(this, result)
      }

      else {
        // callback for custom message
        opts.callback.call(this, result);
      }
    }
  }
})(mnjQuery);



