// This file is for Jquery plugins and objects


/*
 * 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){
        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){
                    $(this).bind('load error', function(){
                        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); 
                                }
                            }
                        }
                    }).each(function(){    
                    if (this.complete || this.complete === undefined){
                            var src = this.src;
                            this.src = '#';
                            this.src = src;
                        } //needed for webkit & potential cached images
                    });
                });
            }
        };

        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});
        //  }
    }

};

////////////////////

/* Image aspect ratio plugin */
(function($){
    $.fn.imageAspect = function(options) {
        var defaults = {
            maxHt: 125,
            maxWt: 100
        };
        var options = $.extend(defaults, options);      
        return this.each(function(i) {

            $(this).removeAttr('height');
            $(this).removeAttr('width');

            var obj = this;
            var natHt = obj.height;
            var natWt = obj.width;


            if (natHt > options.maxHt || natWt > options.maxWt){
                if ((natHt > natWt) || (natHt == natWt) && natHt > options.maxHt){
                    var heightDif = getDiff(natHt, options.maxHt);
                    var newWt = eVal(natWt, heightDif);
                    if (newWt > options.maxWt){
                        newDiff = getDiff(newWt, options.maxWt);
                        newHt = eVal(options.maxHt, newDiff);
                        $(obj).css('height', newHt);
                        $(obj).css('width', options.maxWt);
                    }
                    else {
                        $(obj).css('height', options.maxHt);
                        $(obj).css('width', newWt);
                    }
                }

                else if ((natWt > natHt) || (natWt == natHt) && natWt > options.maxWt){
                    var widthDif = getDiff(natWt, options.maxWt);
                    var newHt = eVal(natHt, widthDif);
                    if (newHt > options.maxHt){
                        newDiff = getDiff(newHt, options.maxHt);
                        newWt = eVal(options.maxWt, newDiff);
                        $(obj).css('height', options.maxHt);
                        $(obj).css('width', newWt);
                    }
                    else {
                        $(obj).css('width', options.maxWt)
                        $(obj).css('height', newHt);
                    }
                }

                else {
                    $(obj).css('height', natHt);
                    $(obj).css('width', natWt);
                }
            }

            else {
                $(obj).css('height', natHt);
                $(obj).css('width', natWt);
            }
            
            //mn_imgResizeStatus += 1;
            // console.log(mn_imgResizeStatus+'count');

            function getDiff(dim, maxDim){
                var dimDiff = (dim - maxDim) / dim;
                return dimDiff;
            }

            function eVal(val, diff){
                var newVal = val - (val * diff);
                return newVal;
            }
        })
    }; 
})(mnjQuery);



/* 'whenLoaded' mnjQuery plugin
 * @author James Padolsey
 * @description Runs a callback function (specified as argument) when all
 *              selected elements have loaded. Works only with certain elements,
 *               i.e. those which have an onload event (e.g. iframe,img etc.)
 * @version 1.0
 */
(function($){
    $.fn.whenLoaded = function(fn){
        var $elements = this,
        total = this.length;
        $elements.each(function(){
            $(this).load(function(){
                $(this).data('isLoaded',true);
            });
        });
        function check() {
            var loaded = 0;
            $elements.each(function(){
                if($(this).data('isLoaded')) {
                    loaded++;
                }
            });
            if(loaded===total) {
                fn.call($elements);
            } else {
                setTimeout(check,300);
            }
        }
        check();
    }
})(mnjQuery);



// 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){
            //$('.mn_prodMatchImage .mn_brokeImg').parents('li').remove();
            mnjQuery('.mn_prodMatchBigImg').cycle({
                fx:     'scrollDown',
                speed:  'fast',
                timeout: 0,
                pager:  '.mn_prodMatchThumb',
                width: 150,
                pagerAnchorBuilder: function(idx, slide) {
                    // return sel string for existing anchor
                    return '.mn_prodMatchThumb 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"){
                    $(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); 
    


/****/


/*
 * mnjQuery Cycle Plugin for light-weight slideshows
 * Examples and documentation at: http://malsup.com/jquery/cycle/
 * Copyright (c) 2007-2008 M. Alsup
 * Version: 2.24 (07/30/2008)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: mnjQuery v1.2.3 or later
 *
 * Based on the work of:
 *  1) Matt Oakes (http://portfolio.gizone.co.uk/applications/slideshow/)
 *  2) Torsten Baldes (http://medienfreunde.com/lab/innerfade/)
 *  3) Benjamin Sterling (http://www.benjaminsterling.com/experiments/jqShuffle/)
 */
(function($) {

    var ver = '2.24';
    var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);

    function log() {
        if (window.console && window.console.log)
            window.console.log('[cycle] ' + Array.prototype.join.call(arguments,''));
    };

    $.fn.cycle = function(options) {
        return this.each(function() {
            if (options === undefined || options === null)
                options = {};
            if (options.constructor == String) {
                switch(options) {
                    case 'stop':
                        if (this.cycleTimeout) clearTimeout(this.cycleTimeout);
                        this.cycleTimeout = 0;
                        $(this).data('cycle.opts', '');
                        return;
                    case 'pause':
                        this.cyclePause = 1;
                        return;
                    case 'resume':
                        this.cyclePause = 0;
                        return;
                    default:
                        options = { fx: options };
                };
            }
            else if (options.constructor == Number) {
                // go to the requested slide slide
                var num = options;
                options = $(this).data('cycle.opts');
                if (!options) {
                    log('options not found, can not advance slide');
                    return;
                }
                if (num < 0 || num >= options.elements.length) {
                    log('invalid slide index: ' + num);
                    return;
                }
                options.nextSlide = num;
                if (this.cycleTimeout) {
                    clearTimeout(this.cycleTimeout);
                    this.cycleTimeout = 0;
                }            
                go(options.elements, options, 1, 1);
                return;
            }

            // stop existing slideshow for this container (if there is one)
            if (this.cycleTimeout) clearTimeout(this.cycleTimeout);
            this.cycleTimeout = 0;
            this.cyclePause = 0;
        
            var $cont = $(this);
            var $slides = options.slideExpr ? $(options.slideExpr, this) : $cont.children();
            var els = $slides.get();
            if (els.length < 2) {
                log('terminating; too few slides: ' + els.length);
                return; // don't bother
            }

            // support metadata plugin (v1.0 and v2.0)
            var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
            if (opts.autostop) 
                opts.countdown = opts.autostopCount || els.length;

            $cont.data('cycle.opts', opts);
            opts.container = this;

            opts.elements = els;
            opts.before = opts.before ? [opts.before] : [];
            opts.after = opts.after ? [opts.after] : [];
            opts.after.unshift(function(){ opts.busy=0; });
            if (opts.continuous)
                opts.after.push(function() { go(els,opts,0,!opts.rev); });
            
            // clearType corrections
            if (ie6 && opts.cleartype && !opts.cleartypeNoBg)
                clearTypeFix($slides);

            // allow shorthand overrides of width, height and timeout
            var cls = this.className;
            opts.width = parseInt((cls.match(/w:(\d+)/)||[])[1]) || opts.width;
            opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1]) || opts.height;
            opts.timeout = parseInt((cls.match(/t:(\d+)/)||[])[1]) || opts.timeout;

            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.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 = 0;
                opts.startingSlide = opts.randomMap[0];
            }
            else if (opts.startingSlide >= els.length)
                opts.startingSlide = 0; // catch bogus input
            var first = opts.startingSlide || 0;
            $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) { 
                var z = first ? i >= first ? els.length - (i-first) : first-i : els.length-i;
                $(this).css('z-index', z) 
            });
        
            $(els[first]).css('opacity',1).show(); // opacity bit needed to handle reinit case
            if ($.browser.msie) els[first].style.removeAttribute('filter');

            if (opts.fit && opts.width) 
                $slides.width(opts.width);
            if (opts.fit && opts.height && opts.height != 'auto') 
                $slides.height(opts.height);
            if (opts.pause) 
                $cont.hover(function(){this.cyclePause=1;},function(){this.cyclePause=0;});

            // run transition init fn
            var init = $.fn.cycle.transitions[opts.fx];
            if ($.isFunction(init))
                init($cont, $slides, opts);
            else if (opts.fx != 'custom')
                log('unknown transition: ' + opts.fx);
        
            $slides.each(function() {
                var $el = $(this);
                this.cycleH = (opts.fit && opts.height) ? opts.height : $el.height();
                this.cycleW = (opts.fit && opts.width) ? opts.width : $el.width();
            });

            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) {
                // ensure that timeout and speed settings are sane
                if (opts.speed.constructor == String)
                    opts.speed = {slow: 600, fast: 200}[opts.speed] || 400;
                if (!opts.sync)
                    opts.speed = opts.speed / 2;
                while((opts.timeout - opts.speed) < 250)
                    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 = first;
            if (opts.random) {
                opts.nextSlide = opts.currSlide;
                if (++opts.randomIndex == els.length) 
                    opts.randomIndex = 0;
                opts.nextSlide = opts.randomMap[opts.randomIndex];
            }
            else
                opts.nextSlide = opts.startingSlide >= (els.length-1) ? 0 : opts.startingSlide+1;

            // fire artificial events
            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.click && !opts.next)
                opts.next = opts.click;
            if (opts.next)
                $(opts.next).bind('click', function(){return advance(els,opts,opts.rev?-1:1)});
            if (opts.prev)
                $(opts.prev).bind('click', function(){return advance(els,opts,opts.rev?1:-1)});
            if (opts.pager)
                buildPager(els,opts);

            // expose fn for adding slides after the show has started
            opts.addSlide = function(newSlide) {
                var $s = $(newSlide), s = $s[0];
                if (!opts.autostopCount)
                    opts.countdown++;
                els.push(s);
                if (opts.els) 
                    opts.els.push(s); // shuffle needs this
                opts.slideCount = els.length;
            
                $s.css('position','absolute').appendTo($cont);
            
                if (ie6 && 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)
                    $.fn.cycle.createPagerAnchor(els.length-1, s, $(opts.pager), els, opts);
            
                if (typeof opts.onAddSlide == 'function')
                    opts.onAddSlide($s);
            };

            if (opts.timeout || opts.continuous)
                this.cycleTimeout = setTimeout(
            function(){go(els,opts,0,!opts.rev)}, 
            opts.continuous ? 10 : opts.timeout + (opts.delay||0));
        });
    };

    function go(els, opts, manual, fwd) {
        if (opts.busy) return;
        var p = opts.container, curr = els[opts.currSlide], next = els[opts.nextSlide];
        if (p.cycleTimeout === 0 && !manual) 
            return;

        if (!manual && !p.cyclePause && 
            ((opts.autostop && (--opts.countdown <= 0)) ||
            (opts.nowrap && !opts.random && opts.nextSlide < opts.currSlide))) {
            if (opts.end)
                opts.end(opts);
            return;
        }

        if (manual || !p.cyclePause) {
            if (opts.before.length)
                $.each(opts.before, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
            var after = function() {
                if ($.browser.msie && opts.cleartype)
                    this.style.removeAttribute('filter');
                $.each(opts.after, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
            };

            if (opts.nextSlide != opts.currSlide) {
                opts.busy = 1;
                if (opts.fxFn)
                    opts.fxFn(curr, next, opts, after, fwd);
                else if ($.isFunction($.fn.cycle[opts.fx]))
                    $.fn.cycle[opts.fx](curr, next, opts, after);
                else
                    $.fn.cycle.custom(curr, next, opts, after);
            }
            if (opts.random) {
                opts.currSlide = opts.nextSlide;
                if (++opts.randomIndex == els.length) 
                    opts.randomIndex = 0;
                opts.nextSlide = opts.randomMap[opts.randomIndex];
            }
            else { // sequence
                var roll = (opts.nextSlide + 1) == els.length;
                opts.nextSlide = roll ? 0 : opts.nextSlide+1;
                opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
            }
            if (opts.pager)
                $.fn.cycle.updateActivePagerLink(opts.pager, opts.currSlide);
        }
        if (opts.timeout && !opts.continuous)
            p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev) }, opts.timeout);
        else if (opts.continuous && p.cyclePause) 
            p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev) }, 10);
    };

    $.fn.cycle.updateActivePagerLink = function(pager, currSlide) {
        $(pager).find('a').removeClass('activeSlide').filter('a:eq('+currSlide+')').addClass('activeSlide');
    };

    // advance slide forward or back
    function advance(els, opts, val) {
        var p = opts.container, timeout = p.cycleTimeout;
        if (timeout) {
            clearTimeout(timeout);
            p.cycleTimeout = 0;
        }
        if (opts.random && val < 0) {
            // move back to the previously display slide
            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) {
            if (++opts.randomIndex == els.length) 
                opts.randomIndex = 0;
            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;
            }
        }
    
        log('nextSlide: ' + opts.nextSlide + '; randomIndex: ' + opts.randomIndex);    
        if (opts.prevNextClick && typeof opts.prevNextClick == 'function')
            opts.prevNextClick(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);
        });
        $.fn.cycle.updateActivePagerLink(opts.pager, opts.startingSlide);
    };

    $.fn.cycle.createPagerAnchor = function(i, el, $p, els, opts) {
        var $a = (typeof opts.pagerAnchorBuilder == 'function')
            ? $(opts.pagerAnchorBuilder(i,el))
        : $('<a href="#">'+(i+1)+'</a>');
    
        // don't reparent if anchor is in the dom
        if ($a.parents('body').length == 0)
            $a.appendTo($p);
        
        $a.bind(opts.pagerEvent, function() {
            opts.nextSlide = i;
            var p = opts.container, timeout = p.cycleTimeout;
            if (timeout) {
                clearTimeout(timeout);
                p.cycleTimeout = 0;
            }            
            if (typeof opts.pagerClick == 'function')
                opts.pagerClick(opts.nextSlide, els[opts.nextSlide]);
            go(els,opts,1,opts.currSlide < i);
            return false;
        });
    };


    // this fixes clearType problems in ie6 by setting an explicit bg color
    function clearTypeFix($slides) {
        function hex(s) {
            var 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.custom = function(curr, next, opts, cb) {
        var $l = $(curr), $n = $(next);
        $n.css(opts.cssBefore);
        var fn = function() {$n.animate(opts.animIn, opts.speedIn, opts.easeIn, cb)};
        $l.animate(opts.animOut, opts.speedOut, opts.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.startingSlide+')').css('opacity',0);
            opts.before.push(function() { $(this).show() });
            opts.animIn    = { opacity: 1 };
            opts.animOut   = { opacity: 0 };
            opts.cssBefore = { opacity: 0 };
            opts.cssAfter  = { display: 'none' };
        }
    };

    $.fn.cycle.ver = function() { return ver; };

    // override these globally if you like (they are all optional)
    $.fn.cycle.defaults = {
        fx:           'fade', // one of: fade, shuffle, zoom, scrollLeft, etc
        timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance)
        continuous:    0,     // true to start next transition immediately after current one completes
        speed:         1000,  // speed of the transition (any valid fx speed value)
        speedIn:       null,  // speed of the 'in' transition
        speedOut:      null,  // speed of the 'out' transition
        next:          null,  // id of element to use as click trigger for next slide
        prev:          null,  // id of element to use as click trigger for previous slide
        prevNextClick: null,  // callback fn for prev/next clicks:  function(isNext, zeroBasedSlideIndex, slideElement)
        pager:         null,  // id of element to use as pager container
        pagerClick:    null,  // callback fn for pager clicks:  function(zeroBasedSlideIndex, slideElement)
        pagerEvent:   'click', // event which drives the pager navigation
        pagerAnchorBuilder: null, // callback fn for building anchor links
        before:        null,  // transition callback (scope set to element to be shown)
        after:         null,  // transition callback (scope set to element that was shown)
        end:           null,  // callback invoked when the slideshow terminates (use with autostop or nowrap options)
        easing:        null,  // easing method for both in and out transitions
        easeIn:        null,  // easing for "in" transition
        easeOut:       null,  // easing for "out" transition
        shuffle:       null,  // coords for shuffle animation, ex: { top:15, left: 200 }
        animIn:        null,  // properties that define how the slide animates in
        animOut:       null,  // properties that define how the slide animates out
        cssBefore:     null,  // properties that define the initial state of the slide before transitioning in
        cssAfter:      null,  // properties that defined the state of the slide after transitioning out
        fxFn:          null,  // function used to control the transition
        height:       'auto', // container height
        startingSlide: 0,     // zero-based index of the first slide to be displayed
        sync:          1,     // true if in/out transitions should occur simultaneously
        random:        0,     // true for random, false for sequence (not applicable to shuffle fx)
        fit:           0,     // force slides to fit container
        pause:         0,     // true to enable "pause on hover"
        autostop:      0,     // true to end slideshow after X transitions (where X == slide count)
        autostopCount: 0,     // number of transitions (optionally used with autostop to define X)
        delay:         0,     // additional delay (in ms) for first transition (hint: can be negative)
        slideExpr:     null,  // expression for selecting slides (if something other than all children is required)
        cleartype:     0,     // true if clearType corrections should be applied (for IE)
        nowrap:        0      // true to prevent slideshow from wrapping
    };

})(mnjQuery);


/*
 * mnjQuery Cycle Plugin Transition Definitions
 * This script is a plugin for the mnjQuery Cycle Plugin
 * Examples and documentation at: http://malsup.com/jquery/cycle/
 * Copyright (c) 2007-2008 M. Alsup
 * Version:  2.22
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
(function($) {

    //
    // These functions define one-time slide initialization for the named
    // transitions. To save file size feel free to remove any of these that you 
    // don't need.
    //

    // scrollUp/Down/Left/Right
    $.fn.cycle.transitions.scrollUp = function($cont, $slides, opts) {
        $cont.css('overflow','hidden');
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.top = next.offsetHeight;
            opts.animOut.top = 0-curr.offsetHeight;
        });
        opts.cssFirst = { top: 0 };
        opts.animIn   = { top: 0 };
        opts.cssAfter = { display: 'none' };
    };
    $.fn.cycle.transitions.scrollDown = function($cont, $slides, opts) {
        $cont.css('overflow','hidden');
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.top = 0-next.offsetHeight;
            opts.animOut.top = curr.offsetHeight;
        });
        opts.cssFirst = { top: 0 };
        opts.animIn   = { top: 0 };
        opts.cssAfter = { display: 'none' };
    };
    $.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
        $cont.css('overflow','hidden');
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.left = next.offsetWidth;
            opts.animOut.left = 0-curr.offsetWidth;
        });
        opts.cssFirst = { left: 0 };
        opts.animIn   = { left: 0 };
    };
    $.fn.cycle.transitions.scrollRight = function($cont, $slides, opts) {
        $cont.css('overflow','hidden');
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.left = 0-next.offsetWidth;
            opts.animOut.left = curr.offsetWidth;
        });
        opts.cssFirst = { left: 0 };
        opts.animIn   = { left: 0 };
    };
    $.fn.cycle.transitions.scrollHorz = function($cont, $slides, opts) {
        $cont.css('overflow','hidden').width();
        //    $slides.show();
        opts.before.push(function(curr, next, opts, fwd) {
            $(this).show();
            var currW = curr.offsetWidth, nextW = next.offsetWidth;
            opts.cssBefore = fwd ? { left: nextW } : { left: -nextW };
            opts.animIn.left = 0;
            opts.animOut.left = fwd ? -currW : currW;
            $slides.not(curr).css(opts.cssBefore);
        });
        opts.cssFirst = { left: 0 };
        opts.cssAfter = { display: 'none' }
    };
    $.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
        $cont.css('overflow','hidden');
        //    $slides.show();
        opts.before.push(function(curr, next, opts, fwd) {
            $(this).show();
            var currH = curr.offsetHeight, nextH = next.offsetHeight;
            opts.cssBefore = fwd ? { top: -nextH } : { top: nextH };
            opts.animIn.top = 0;
            opts.animOut.top = fwd ? currH : -currH;
            $slides.not(curr).css(opts.cssBefore);
        });
        opts.cssFirst = { top: 0 };
        opts.cssAfter = { display: 'none' }
    };

    // slideX/slideY
    $.fn.cycle.transitions.slideX = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(curr).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssBefore = { zIndex: 2 };
        opts.animIn  = { width: 'show' };
        opts.animOut = { width: 'hide' };
    };
    $.fn.cycle.transitions.slideY = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(curr).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssBefore = { zIndex: 2 };
        opts.animIn  = { height: 'show' };
        opts.animOut = { height: 'hide' };
    };

    // shuffle
    $.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
        var w = $cont.css('overflow', 'visible').width();
        $slides.css({left: 0, top: 0});
        opts.before.push(function() { $(this).show() });
        opts.speed = opts.speed / 2; // shuffle has 2 transitions        
        opts.random = 0;
        opts.shuffle = opts.shuffle || {left:-w, top:15};
        opts.els = [];
        for (var i=0; i < $slides.length; i++)
            opts.els.push($slides[i]);

        for (var i=0; i < opts.startingSlide; i++)
            opts.els.push(opts.els.shift());

        // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
        opts.fxFn = function(curr, next, opts, cb, fwd) {
            var $el = fwd ? $(curr) : $(next);
            $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
                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);
                else {
                    var z = $(curr).css('z-index');
                    $el.css('z-index', parseInt(z)+1);
                }
                $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
                    $(fwd ? this : curr).hide();
                    if (cb) cb();
                });
            });
        };
        opts.onAddSlide = function($s) { $s.hide(); };
    };

    // turnUp/Down/Left/Right
    $.fn.cycle.transitions.turnUp = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.top = next.cycleH;
            opts.animIn.height = next.cycleH;
        });
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssFirst  = { top: 0 };
        opts.cssBefore = { height: 0 };
        opts.animIn    = { top: 0 };
        opts.animOut   = { height: 0 };
        opts.cssAfter  = { display: 'none' };
    };
    $.fn.cycle.transitions.turnDown = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.animIn.height = next.cycleH;
            opts.animOut.top   = curr.cycleH;
        });
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssFirst  = { top: 0 };
        opts.cssBefore = { top: 0, height: 0 };
        opts.animOut   = { height: 0 };
        opts.cssAfter  = { display: 'none' };
    };
    $.fn.cycle.transitions.turnLeft = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore.left = next.cycleW;
            opts.animIn.width = next.cycleW;
        });
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssBefore = { width: 0 };
        opts.animIn    = { left: 0 };
        opts.animOut   = { width: 0 };
        opts.cssAfter  = { display: 'none' };
    };
    $.fn.cycle.transitions.turnRight = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.animIn.width = next.cycleW;
            opts.animOut.left = curr.cycleW;
        });
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssBefore = { left: 0, width: 0 };
        opts.animIn    = { left: 0 };
        opts.animOut   = { width: 0 };
        opts.cssAfter  = { display: 'none' };
    };

    // zoom
    $.fn.cycle.transitions.zoom = function($cont, $slides, opts) {
        opts.cssFirst = { top:0, left: 0 }; 
        opts.cssAfter = { display: 'none' };
    
        opts.before.push(function(curr, next, opts) {
            $(this).show();
            opts.cssBefore = { width: 0, height: 0, top: next.cycleH/2, left: next.cycleW/2 };
            opts.cssAfter  = { display: 'none' };
            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 };
            $(curr).css('zIndex',2);
            $(next).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
    };

    // fadeZoom
    $.fn.cycle.transitions.fadeZoom = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            opts.cssBefore = { width: 0, height: 0, opacity: 1, left: next.cycleW/2, top: next.cycleH/2, zIndex: 1 };
            opts.animIn    = { top: 0, left: 0, width: next.cycleW, height: next.cycleH };
        });    
        opts.animOut  = { opacity: 0 };
        opts.cssAfter = { zIndex: 0 };
    };

    // blindX
    $.fn.cycle.transitions.blindX = function($cont, $slides, opts) {
        var w = $cont.css('overflow','hidden').width();
        $slides.show();
        opts.before.push(function(curr, next, opts) {
            $(curr).css('zIndex',1);
        });    
        opts.cssBefore = { left: w, zIndex: 2 };
        opts.cssAfter = { zIndex: 1 };
        opts.animIn = { left: 0 };
        opts.animOut  = { left: w };
    };
    // blindY
    $.fn.cycle.transitions.blindY = function($cont, $slides, opts) {
        var h = $cont.css('overflow','hidden').height();
        $slides.show();
        opts.before.push(function(curr, next, opts) {
            $(curr).css('zIndex',1);
        });    
        opts.cssBefore = { top: h, zIndex: 2 };
        opts.cssAfter = { zIndex: 1 };
        opts.animIn = { top: 0 };
        opts.animOut  = { top: h };
    };
    // blindZ
    $.fn.cycle.transitions.blindZ = function($cont, $slides, opts) {
        var h = $cont.css('overflow','hidden').height();
        var w = $cont.width();
        $slides.show();
        opts.before.push(function(curr, next, opts) {
            $(curr).css('zIndex',1);
        });    
        opts.cssBefore = { top: h, left: w, zIndex: 2 };
        opts.cssAfter = { zIndex: 1 };
        opts.animIn = { top: 0, left: 0 };
        opts.animOut  = { top: h, left: w };
    };

    // growX - grow horizontally from centered 0 width
    $.fn.cycle.transitions.growX = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            opts.cssBefore = { left: this.cycleW/2, width: 0, zIndex: 2 };
            opts.animIn = { left: 0, width: this.cycleW };
            opts.animOut = { left: 0 };
            $(curr).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide().css('zIndex',1); };
    };
    // growY - grow vertically from centered 0 height
    $.fn.cycle.transitions.growY = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            opts.cssBefore = { top: this.cycleH/2, height: 0, zIndex: 2 };
            opts.animIn = { top: 0, height: this.cycleH };
            opts.animOut = { top: 0 };
            $(curr).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide().css('zIndex',1); };
    };

    // curtainX - squeeze in both edges horizontally
    $.fn.cycle.transitions.curtainX = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            opts.cssBefore = { left: next.cycleW/2, width: 0, zIndex: 1, display: 'block' };
            opts.animIn = { left: 0, width: this.cycleW };
            opts.animOut = { left: curr.cycleW/2, width: 0 };
            $(curr).css('zIndex',2);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssAfter = { zIndex: 1, display: 'none' };
    };
    // curtainY - squeeze in both edges vertically
    $.fn.cycle.transitions.curtainY = function($cont, $slides, opts) {
        opts.before.push(function(curr, next, opts) {
            opts.cssBefore = { top: next.cycleH/2, height: 0, zIndex: 1, display: 'block' };
            opts.animIn = { top: 0, height: this.cycleH };
            opts.animOut = { top: curr.cycleH/2, height: 0 };
            $(curr).css('zIndex',2);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssAfter = { zIndex: 1, display: 'none' };
    };

    // cover - curr slide covered by next slide
    $.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) {
            opts.cssBefore = opts.cssBefore || {};
            opts.cssBefore.zIndex = 2;
            opts.cssBefore.display = 'block';
        
            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;
            $(curr).css('zIndex',1);
        });    
        if (!opts.animIn)  opts.animIn = { left: 0, top: 0 };
        if (!opts.animOut) opts.animOut = { left: 0, top: 0 };
        opts.cssAfter = opts.cssAfter || {};
        opts.cssAfter.zIndex = 2;
        opts.cssAfter.display = 'none';
    };

    // uncover - curr slide moves off next slide
    $.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) {
            opts.cssBefore.display = 'block';
            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;
            $(curr).css('zIndex',2);
            $(next).css('zIndex',1);
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        if (!opts.animIn)  opts.animIn = { left: 0, top: 0 };
        opts.cssBefore = opts.cssBefore || {};
        opts.cssBefore.top = 0;
        opts.cssBefore.left = 0;
    
        opts.cssAfter = opts.cssAfter || {};
        opts.cssAfter.zIndex = 1;
        opts.cssAfter.display = 'none';
    };

    // toss - move top slide and fade away
    $.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) {
            $(curr).css('zIndex',2);
            opts.cssBefore.display = 'block'; 
            // provide default toss settings if animOut not provided
            if (!opts.animOut.left && !opts.animOut.top)
                opts.animOut = { left: w*2, top: -h/2, opacity: 0 };
            else
                opts.animOut.opacity = 0;
        });    
        opts.onAddSlide = function($s) { $s.hide(); };
        opts.cssBefore = { left: 0, top: 0, zIndex: 1, opacity: 1 };
        opts.animIn = { left: 0 };
        opts.cssAfter = { zIndex: 2, display: 'none' };
    };

    // wipe - clip animation
    $.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 t = parseInt(h/2);
                var l = parseInt(w/2);
                clip = 'rect('+t+'px '+l+'px '+t+'px '+l+'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).css('zIndex',2);
            var $next = $(next).css({
                zIndex:  3,
                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');
            }
            f();
        });    
        opts.cssAfter  = { };
        opts.animIn    = { left: 0 };
        opts.animOut   = { left: 0 };
    };

})(mnjQuery);


/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 1.98 (02-JUN-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 */
;(function($) { 

    var expr = (function() {
	if (! $.browser.msie) return false;
        var div = document.createElement('div');
        try { div.style.setExpression('width','0+0'); }
        catch(e) { return false; }
        return true;
    })();
    
    function sz(el, p) { 
        return parseInt($.css(el,p))||0; 
    };
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
            var v = $.css(node,'backgroundColor');
            if (v == 'rgba(0, 0, 0, 0)')
                continue; // webkit
            if (v.indexOf('rgb') >= 0) { 
                var rgb = v.match(/\d+/g); 
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };

    function getWidth(fx, i, width) {
        switch(fx) {
            case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
            case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
            case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
            case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
            case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
            case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
            case 'curl':   return Math.round(width*(Math.atan(i)));
            case 'tear':   return Math.round(width*(Math.cos(i)));
            case 'wicked': return Math.round(width*(Math.tan(i)));
            case 'long':   return Math.round(width*(Math.sqrt(i)));
            case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
            case 'dog':    return (i&1) ? (i+1) : width;
            case 'dog2':   return (i&2) ? (i+1) : width;
            case 'dog3':   return (i&3) ? (i+1) : width;
            case 'fray':   return (i%2)*width;
            case 'notch':  return width; 
            case 'bevel':  return i+1;
        }
    };

    $.fn.corner = function(o) {
        // in 1.3+ we can fix mistakes with the ready state
	if (this.length == 0) {
            if (!$.isReady && this.selector) {
                var s = this.selector, c = this.context;
                $(function() {
                    $(s,c).corner(o);
                });
            }
            return this;
	}

        o = (o||"").toLowerCase();
        var keep = /keep/.test(o);                       // keep borders?
        var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
        var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
        var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
        var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
        var fx = ((o.match(re)||['round'])[0]);
        var edges = { T:0, B:1 };
        var opts = {
            TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
            BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
        };
        if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
            opts = { TL:1, TR:1, BL:1, BR:1 };
        var strip = document.createElement('div');
        strip.style.overflow = 'hidden';
        strip.style.height = '1px';
        strip.style.backgroundColor = sc || 'transparent';
        strip.style.borderStyle = 'solid';
        return this.each(function(index){
            var pad = {
                T: parseInt($.css(this,'paddingTop'))||0,     R: parseInt($.css(this,'paddingRight'))||0,
                B: parseInt($.css(this,'paddingBottom'))||0,  L: parseInt($.css(this,'paddingLeft'))||0
            };

            if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
            if (!keep) this.style.border = 'none';
            strip.style.borderColor = cc || gpc(this.parentNode);
            var cssHeight = $.curCSS(this, 'height');

            for (var j in edges) {
                var bot = edges[j];
                // only add stips if needed
                if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
                    strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
                    var d = document.createElement('div');
                    $(d).addClass('jquery-corner');
                    var ds = d.style;

                    bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

                    if (bot && cssHeight != 'auto') {
                        if ($.css(this,'position') == 'static')
                            this.style.position = 'relative';
                        ds.position = 'absolute';
                        ds.bottom = ds.left = ds.padding = ds.margin = '0';
                        if (expr)
                            ds.setExpression('width', 'this.parentNode.offsetWidth');
                        else
                            ds.width = '100%';
                    }
                    else if (!bot && $.browser.msie) {
                        if ($.css(this,'position') == 'static')
                            this.style.position = 'relative';
                        ds.position = 'absolute';
                        ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
                    
                        // fix ie6 problem when blocked element has a border width
                        if (expr) {
                            var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
                            ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
                        }
                        else
                            ds.width = '100%';
                    }
                    else {
                        ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                            (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
                    }

                    for (var i=0; i < width; i++) {
                        var w = Math.max(0,getWidth(fx,i, width));
                        var e = strip.cloneNode(false);
                        e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                        bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
                    }
                }
            }
        });
    };

    $.fn.uncorner = function() { 
	$('div.jquery-corner', this).remove();
	return this;
    };
    
})(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: '',
            oLayPosition: 'center', // center, mouse, coord
            oLayType: 'overLay', //overlay, popup
            pageContain: '#e', //keep popups within this box
            content: '', //popup/overlay content src
            type: '' //adding this due to conditional error
        };
        
        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 != ''){
                $(options.content).remove().clone(true).prependTo('.mn_olayContentWrap');
            }
            else {
                $.ajax({
                    type: 'GET',
                    async: false,
                    url: options.addy,
                    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);
                        $('#mn_olayResults').get(0).innerHTML = response; //fixes issue with IE

                        
                        // custom functions
                        if ($('#mn_tbody').length > 0){
                            tabAdjust(); //merchant overlay
                        }
                        
                        if ($('.mn_checkBig').length > 0){ //product overlay img
                            $('.mn_checkBig').load(function(){
                                resizeImg();
                            }) 
                        }
                        
                        if ($('.mn_prodDetails').length > 0){
                           //addthis widget
                            var newDiv = $('<div class="mn_addThisDiv"></div');
                            $('.mn_prodId').before(newDiv);
                            var shareurl = location.protocol + "//" + document.domain + "/pd____.htm?pid=" + $(".mn_prodId").text();
                            var markup = $('<div style="margin-top:25px;margin-bottom:25px;" class="addthis_toolbox addthis_default_style"><a class="addthis_button_email"></a><a class="addthis_button_facebook"></a><a class="addthis_button_twitter"></a><a class="addthis_button_amazonwishlist"></a><span class="addthis_separator">|</span><a href="http://www.addthis.com/bookmark.php?v=250&amp;pub=mallnetworks" class="addthis_button_expanded">More</a></div>')
                            $('.mn_addThisDiv').append(markup);
                            addthis.toolbox(".addthis_toolbox", {services_expanded:"favorites,print,aim,blogger,buzz,delicious,google,kaboodle,kirtsy,live,myspace,stumbleupon,stylehive,thisnext,typepad,wordpress",ui_508_compliant:"true",data_track_linkback: "true"},{url: shareurl});
                        } 
                        //end custom functions
                        
                        
                        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();
        $(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: '200%', 
                    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');    
            $('.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);
    

