// public site specific plugins
/**
 * jCarousel - Riding carousels with jQuery
 *   http://sorgalla.com/jcarousel/
 *
 * Copyright (c) 2006 Jan Sorgalla (http://sorgalla.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Built on top of the jQuery library
 *   http://jquery.com
 *
 * Inspired by the "Carousel Component" by Bill Scott
 *   http://billwscott.com/carousel/
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(9($){$.1v.C=9(o){z 4.1b(9(){3p r(4,o)})};8 q={Z:F,25:1,21:1,u:7,1c:3,15:7,1K:\'2X\',2c:\'2Q\',1q:0,B:7,1j:7,1G:7,2F:7,2B:7,2z:7,2x:7,2v:7,2s:7,2p:7,1S:\'<P></P>\',1Q:\'<P></P>\',2m:\'2l\',2k:\'2l\',1O:7,1L:7};$.C=9(e,o){4.5=$.16({},q,o||{});4.Q=F;4.D=7;4.H=7;4.t=7;4.U=7;4.R=7;4.N=!4.5.Z?\'1H\':\'26\';4.E=!4.5.Z?\'24\':\'23\';8 a=\'\',1e=e.K.1e(\' \');1r(8 i=0;i<1e.I;i++){6(1e[i].2y(\'C-2w\')!=-1){$(e).1E(1e[i]);8 a=1e[i];1p}}6(e.2t==\'3o\'||e.2t==\'3n\'){4.t=$(e);4.D=4.t.19();6(4.D.1o(\'C-H\')){6(!4.D.19().1o(\'C-D\'))4.D=4.D.B(\'<P></P>\');4.D=4.D.19()}10 6(!4.D.1o(\'C-D\'))4.D=4.t.B(\'<P></P>\').19()}10{4.D=$(e);4.t=$(e).3h(\'>2o,>2n,P>2o,P>2n\')}6(a!=\'\'&&4.D.19()[0].K.2y(\'C-2w\')==-1)4.D.B(\'<P 3g=" \'+a+\'"></P>\');4.H=4.t.19();6(!4.H.I||!4.H.1o(\'C-H\'))4.H=4.t.B(\'<P></P>\').19();4.R=$(\'.C-11\',4.D);6(4.R.u()==0&&4.5.1Q!=7)4.R=4.H.1z(4.5.1Q).11();4.R.V(4.K(\'C-11\'));4.U=$(\'.C-17\',4.D);6(4.U.u()==0&&4.5.1S!=7)4.U=4.H.1z(4.5.1S).11();4.U.V(4.K(\'C-17\'));4.H.V(4.K(\'C-H\'));4.t.V(4.K(\'C-t\'));4.D.V(4.K(\'C-D\'));8 b=4.5.15!=7?1k.1P(4.1m()/4.5.15):7;8 c=4.t.32(\'1F\');8 d=4;6(c.u()>0){8 f=0,i=4.5.21;c.1b(9(){d.1I(4,i++);f+=d.S(4,b)});4.t.y(4.N,f+\'T\');6(!o||o.u===J)4.5.u=c.u()}4.D.y(\'1y\',\'1A\');4.U.y(\'1y\',\'1A\');4.R.y(\'1y\',\'1A\');4.2G=9(){d.17()};4.2b=9(){d.11()};4.1U=9(){d.2q()};6(4.5.1j!=7)4.5.1j(4,\'2a\');6($.2A.28){4.1f(F,F);$(27).1u(\'2I\',9(){d.1t()})}10 4.1t()};8 r=$.C;r.1v=r.2H={C:\'0.2.3\'};r.1v.16=r.16=$.16;r.1v.16({1t:9(){4.A=7;4.G=7;4.X=7;4.13=7;4.14=F;4.1d=7;4.O=7;4.W=F;6(4.Q)z;4.t.y(4.E,4.1s(4.5.21)+\'T\');8 p=4.1s(4.5.25);4.X=4.13=7;4.1i(p,F);$(27).22(\'2E\',4.1U).1u(\'2E\',4.1U)},2D:9(){4.t.2C();4.t.y(4.E,\'3u\');4.t.y(4.N,\'3t\');6(4.5.1j!=7)4.5.1j(4,\'2D\');4.1t()},2q:9(){6(4.O!=7&&4.W)4.t.y(4.E,r.M(4.t.y(4.E))+4.O);4.O=7;4.W=F;6(4.5.1G!=7)4.5.1G(4);6(4.5.15!=7){8 a=4;8 b=1k.1P(4.1m()/4.5.15),N=0,E=0;$(\'1F\',4.t).1b(9(i){N+=a.S(4,b);6(i+1<a.A)E=N});4.t.y(4.N,N+\'T\');4.t.y(4.E,-E+\'T\')}4.1c(4.A,F)},3s:9(){4.Q=1h;4.1f()},3r:9(){4.Q=F;4.1f()},u:9(s){6(s!=J){4.5.u=s;6(!4.Q)4.1f()}z 4.5.u},3q:9(i,a){6(a==J||!a)a=i;6(4.5.u!==7&&a>4.5.u)a=4.5.u;1r(8 j=i;j<=a;j++){8 e=4.L(j);6(!e.I||e.1o(\'C-1a-1D\'))z F}z 1h},L:9(i){z $(\'.C-1a-\'+i,4.t)},2u:9(i,s){8 e=4.L(i),20=0,2u=0;6(e.I==0){8 c,e=4.1B(i),j=r.M(i);1n(c=4.L(--j)){6(j<=0||c.I){j<=0?4.t.2r(e):c.1X(e);1p}}}10 20=4.S(e);e.1E(4.K(\'C-1a-1D\'));1R s==\'3l\'?e.3k(s):e.2C().3j(s);8 a=4.5.15!=7?1k.1P(4.1m()/4.5.15):7;8 b=4.S(e,a)-20;6(i>0&&i<4.A)4.t.y(4.E,r.M(4.t.y(4.E))-b+\'T\');4.t.y(4.N,r.M(4.t.y(4.N))+b+\'T\');z e},1V:9(i){8 e=4.L(i);6(!e.I||(i>=4.A&&i<=4.G))z;8 d=4.S(e);6(i<4.A)4.t.y(4.E,r.M(4.t.y(4.E))+d+\'T\');e.1V();4.t.y(4.N,r.M(4.t.y(4.N))-d+\'T\')},17:9(){4.1C();6(4.O!=7&&!4.W)4.1T(F);10 4.1c(((4.5.B==\'1Z\'||4.5.B==\'G\')&&4.5.u!=7&&4.G==4.5.u)?1:4.A+4.5.1c)},11:9(){4.1C();6(4.O!=7&&4.W)4.1T(1h);10 4.1c(((4.5.B==\'1Z\'||4.5.B==\'A\')&&4.5.u!=7&&4.A==1)?4.5.u:4.A-4.5.1c)},1T:9(b){6(4.Q||4.14||!4.O)z;8 a=r.M(4.t.y(4.E));!b?a-=4.O:a+=4.O;4.W=!b;4.X=4.A;4.13=4.G;4.1i(a)},1c:9(i,a){6(4.Q||4.14)z;4.1i(4.1s(i),a)},1s:9(i){6(4.Q||4.14)z;6(4.5.B!=\'18\')i=i<1?1:(4.5.u&&i>4.5.u?4.5.u:i);8 a=4.A>i;8 b=r.M(4.t.y(4.E));8 f=4.5.B!=\'18\'&&4.A<=1?1:4.A;8 c=a?4.L(f):4.L(4.G);8 j=a?f:f-1;8 e=7,l=0,p=F,d=0;1n(a?--j>=i:++j<i){e=4.L(j);p=!e.I;6(e.I==0){e=4.1B(j).V(4.K(\'C-1a-1D\'));c[a?\'1z\':\'1X\'](e)}c=e;d=4.S(e);6(p)l+=d;6(4.A!=7&&(4.5.B==\'18\'||(j>=1&&(4.5.u==7||j<=4.5.u))))b=a?b+d:b-d}8 g=4.1m();8 h=[];8 k=0,j=i,v=0;8 c=4.L(i-1);1n(++k){e=4.L(j);p=!e.I;6(e.I==0){e=4.1B(j).V(4.K(\'C-1a-1D\'));c.I==0?4.t.2r(e):c[a?\'1z\':\'1X\'](e)}c=e;8 d=4.S(e);6(d==0){3f(\'3e: 3d 1H/26 3c 1r 3b. 3a 39 38 37 36 35. 34...\');z 0}6(4.5.B!=\'18\'&&4.5.u!==7&&j>4.5.u)h.33(e);10 6(p)l+=d;v+=d;6(v>=g)1p;j++}1r(8 x=0;x<h.I;x++)h[x].1V();6(l>0){4.t.y(4.N,4.S(4.t)+l+\'T\');6(a){b-=l;4.t.y(4.E,r.M(4.t.y(4.E))-l+\'T\')}}8 n=i+k-1;6(4.5.B!=\'18\'&&4.5.u&&n>4.5.u)n=4.5.u;6(j>n){k=0,j=n,v=0;1n(++k){8 e=4.L(j--);6(!e.I)1p;v+=4.S(e);6(v>=g)1p}}8 o=n-k+1;6(4.5.B!=\'18\'&&o<1)o=1;6(4.W&&a){b+=4.O;4.W=F}4.O=7;6(4.5.B!=\'18\'&&n==4.5.u&&(n-k+1)>=1){8 m=r.Y(4.L(n),!4.5.Z?\'1l\':\'1N\');6((v-m)>g)4.O=v-g-m}1n(i-->o)b+=4.S(4.L(i));4.X=4.A;4.13=4.G;4.A=o;4.G=n;z b},1i:9(p,a){6(4.Q||4.14)z;4.14=1h;8 b=4;8 c=9(){b.14=F;6(p==0)b.t.y(b.E,0);6(b.5.B==\'1Z\'||b.5.B==\'G\'||b.5.u==7||b.G<b.5.u)b.2j();b.1f();b.1M(\'2i\')};4.1M(\'31\');6(!4.5.1K||a==F){4.t.y(4.E,p+\'T\');c()}10{8 o=!4.5.Z?{\'24\':p}:{\'23\':p};4.t.1i(o,4.5.1K,4.5.2c,c)}},2j:9(s){6(s!=J)4.5.1q=s;6(4.5.1q==0)z 4.1C();6(4.1d!=7)z;8 a=4;4.1d=30(9(){a.17()},4.5.1q*2Z)},1C:9(){6(4.1d==7)z;2Y(4.1d);4.1d=7},1f:9(n,p){6(n==J||n==7){8 n=!4.Q&&4.5.u!==0&&((4.5.B&&4.5.B!=\'A\')||4.5.u==7||4.G<4.5.u);6(!4.Q&&(!4.5.B||4.5.B==\'A\')&&4.5.u!=7&&4.G>=4.5.u)n=4.O!=7&&!4.W}6(p==J||p==7){8 p=!4.Q&&4.5.u!==0&&((4.5.B&&4.5.B!=\'G\')||4.A>1);6(!4.Q&&(!4.5.B||4.5.B==\'G\')&&4.5.u!=7&&4.A==1)p=4.O!=7&&4.W}8 a=4;4.U[n?\'1u\':\'22\'](4.5.2m,4.2G)[n?\'1E\':\'V\'](4.K(\'C-17-1w\')).1J(\'1w\',n?F:1h);4.R[p?\'1u\':\'22\'](4.5.2k,4.2b)[p?\'1E\':\'V\'](4.K(\'C-11-1w\')).1J(\'1w\',p?F:1h);6(4.U.I>0&&(4.U[0].1g==J||4.U[0].1g!=n)&&4.5.1O!=7){4.U.1b(9(){a.5.1O(a,4,n)});4.U[0].1g=n}6(4.R.I>0&&(4.R[0].1g==J||4.R[0].1g!=p)&&4.5.1L!=7){4.R.1b(9(){a.5.1L(a,4,p)});4.R[0].1g=p}},1M:9(a){8 b=4.X==7?\'2a\':(4.X<4.A?\'17\':\'11\');4.12(\'2F\',a,b);6(4.X!==4.A){4.12(\'2B\',a,b,4.A);4.12(\'2z\',a,b,4.X)}6(4.13!==4.G){4.12(\'2x\',a,b,4.G);4.12(\'2v\',a,b,4.13)}4.12(\'2s\',a,b,4.A,4.G,4.X,4.13);4.12(\'2p\',a,b,4.X,4.13,4.A,4.G)},12:9(a,b,c,d,e,f,g){6(4.5[a]==J||(1R 4.5[a]!=\'2h\'&&b!=\'2i\'))z;8 h=1R 4.5[a]==\'2h\'?4.5[a][b]:4.5[a];6(!$.2W(h))z;8 j=4;6(d===J)h(j,c,b);10 6(e===J)4.L(d).1b(9(){h(j,4,d,c,b)});10{1r(8 i=d;i<=e;i++)6(i!==7&&!(i>=f&&i<=g))4.L(i).1b(9(){h(j,4,i,c,b)})}},1B:9(i){z 4.1I(\'<1F></1F>\',i)},1I:9(e,i){8 a=$(e).V(4.K(\'C-1a\')).V(4.K(\'C-1a-\'+i));a.1J(\'2V\',i);z a},K:9(c){z c+\' \'+c+(!4.5.Z?\'-2U\':\'-Z\')},S:9(e,d){8 a=e.2g!=J?e[0]:e;8 b=!4.5.Z?a.1x+r.Y(a,\'2f\')+r.Y(a,\'1l\'):a.2e+r.Y(a,\'2d\')+r.Y(a,\'1N\');6(d==J||b==d)z b;8 w=!4.5.Z?d-r.Y(a,\'2f\')-r.Y(a,\'1l\'):d-r.Y(a,\'2d\')-r.Y(a,\'1N\');$(a).y(4.N,w+\'T\');z 4.S(a)},1m:9(){z!4.5.Z?4.H[0].1x-r.M(4.H.y(\'2T\'))-r.M(4.H.y(\'2S\')):4.H[0].2e-r.M(4.H.y(\'2R\'))-r.M(4.H.y(\'3i\'))},2P:9(i,s){6(s==J)s=4.5.u;z 1k.2O((((i-1)/s)-1k.2N((i-1)/s))*s)+1}});r.16({3m:9(d){z $.16(q,d||{})},Y:9(e,p){6(!e)z 0;8 a=e.2g!=J?e[0]:e;6(p==\'1l\'&&$.2A.28){8 b={\'1y\':\'1A\',\'2M\':\'2L\',\'1H\':\'1q\'},1Y,1W;$.29(a,b,9(){1Y=a.1x});b[\'1l\']=0;$.29(a,b,9(){1W=a.1x});z 1W-1Y}z r.M($.y(a,p))},M:9(v){v=2K(v);z 2J(v)?0:v}})})(3v);',62,218,'||||this|options|if|null|var|function||||||||||||||||||||list|size||||css|return|first|wrap|jcarousel|container|lt|false|last|clip|length|undefined|className|get|intval|wh|tail|div|locked|buttonPrev|dimension|px|buttonNext|addClass|inTail|prevFirst|margin|vertical|else|prev|callback|prevLast|animating|visible|extend|next|circular|parent|item|each|scroll|timer|split|buttons|jcarouselstate|true|animate|initCallback|Math|marginRight|clipping|while|hasClass|break|auto|for|pos|setup|bind|fn|disabled|offsetWidth|display|before|block|create|stopAuto|placeholder|removeClass|li|reloadCallback|width|format|attr|animation|buttonPrevCallback|notify|marginBottom|buttonNextCallback|ceil|buttonPrevHTML|typeof|buttonNextHTML|scrollTail|funcResize|remove|oWidth2|after|oWidth|both|old|offset|unbind|top|left|start|height|window|safari|swap|init|funcPrev|easing|marginTop|offsetHeight|marginLeft|jquery|object|onAfterAnimation|startAuto|buttonPrevEvent|click|buttonNextEvent|ol|ul|itemVisibleOutCallback|reload|prepend|itemVisibleInCallback|nodeName|add|itemLastOutCallback|skin|itemLastInCallback|indexOf|itemFirstOutCallback|browser|itemFirstInCallback|empty|reset|resize|itemLoadCallback|funcNext|prototype|load|isNaN|parseInt|none|float|floor|round|index|swing|borderTopWidth|borderRightWidth|borderLeftWidth|horizontal|jcarouselindex|isFunction|normal|clearTimeout|1000|setTimeout|onBeforeAnimation|children|push|Aborting|loop|infinite|an|cause|will|This|items|set|No|jCarousel|alert|class|find|borderBottomWidth|append|html|string|defaults|OL|UL|new|has|unlock|lock|10px|0px|jQuery'.split('|'),0,{}))
function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};









/**
* Label Over
*   http://plugins.jquery.com/project/labelover
*   2007-Jun-19
*/
jQuery.fn.labelOver = function(overClass)
{
    return this.each(function()
    {
        var label = jQuery(this);
        var f = label.attr('for');
        if (f)
        {
            var input = jQuery('#' + f);

            this.hide = function()
            {
                label.css({ textIndent: -10000 })
            }

            this.show = function()
            {
                if (input.val() == '') label.css({ textIndent: 0 })
            }

            // handlers
            input.focus(this.hide);
            input.blur(this.show);
            label.addClass(overClass).click(function() { input.focus() });

            if (input.val() != '') this.hide();
        }
    })
}













jqZoomObj = null;
$(document).ready(function()
{


    // Accessible Target links
    $(".external-window").click(function(e)
    {
        // Abort if a modifier key is pressed
        if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
        {
            return true;
        } else
        {
            // Change "_blank" to something like "newWindow" to load all links in the same new window
            var newWindow = window.open(this.getAttribute('href'), '_blank');
            if (newWindow)
            {
                if (newWindow.focus)
                {
                    newWindow.focus();
                }
                return false;
            }
            return true;
        }

    });
    $(".external-window").attr("title", "Link opens in an external window");

    // Key tracking for TB esc/close
    $(this).keydown(function(e)
    {
        if (e == null)
        { // ie
            keycode = event.keyCode;
        } else
        { // mozilla
            keycode = e.which;
        }
        if (keycode == 27)
        { // close
            if (document.getElementById('TB_overlay')) tb_remove();
        }
    });

    /*
    ** Components
    */
    /*
    ** Add HTML on load
    <div id="overlay" class="hidden"></div>
    <div id="processing" class="hidden">
    <img src="<%=this.AppUrl%>media/images/loader.gif" width="15" height="15" class="fleft" />
    <h2>Payment Processing</h2>
    <p>
    Please wait while we process this order...
    </p>			
    </div>
    */
    //$("body").prepend('<div id="overlay" class="hidden"></div><div id="processing" class="hidden"><img src="' + baseMediaPath + 'media/images/loader.gif" width="15" height="15" class="fleft" /><h2>Payment Processing</h2><p>Please wait while we process this order...</p></div>');

    //colour preferences
    jQuery.fn.reverse = Array.prototype.reverse; // mod so you can reverse the order of dom collections from jquery object
    if (document.getElementById('colourPreferencesOptions'))
    {
        cpMainRef = $("#colourPreferencesOptions");
        cpMainRefInputs = $("#colourPreferencesOptions input");
        cpMainRefInputs = cpMainRefInputs.reverse();
        cpMainRef.css("visibility", "hidden");

        splitSizeText = cpMainRef.find("label").textChildren({ stringDelimiter: '|' }).split("|");
        //console.log(splitSizeText);
        splitSizeTextCleaned = new Array();
        j = 0;
        for (i = 0; i < splitSizeText.length; i++)
        {
            if (splitSizeText[i] != "")
            {
                splitSizeTextCleaned[j] = splitSizeText[i];
                j++;
            }
        }

        $("#colourPreferencesOptions").empty();

        for (i = 0; i < splitSizeTextCleaned.length; i++)
        {
            $("#colourPreferencesOptions").prepend(cpMainRefInputs[i]);
        }
        for (i = 0; i < splitSizeTextCleaned.length; i++)
        {
            $("#colourPreferencesOptions input:eq(" + i + ")").wrap('<label for="' + $("#colourPreferencesOptions input:eq(" + i + ")").attr("id") + '"></label>').parent().append("<small>" + splitSizeTextCleaned[(splitSizeTextCleaned[i] == "" ? i + 1 : i)] + "</small>");
        }
        cpMainRef.css("visibility", "visible");

        $("#colourPreferencesOptions input").click(
			function()
			{
			    //console.log("setting colour to "+$(this).parent().find("small").text());
			    $("#selectedColour").attr("value", ($(this).parent().find("small").text()));
			}
		);
    }



    /*
    ** Quicksearch setups
    */
    if ($("#tabButtonSet").length > 0)
    {
        // for QLD
        $('#ABList ul li').quicksearch({ position: 'before', attached: '#ABList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#CEList ul li').quicksearch({ position: 'before', attached: '#CEList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#FJList ul li').quicksearch({ position: 'before', attached: '#FJList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#KMList ul li').quicksearch({ position: 'before', attached: '#KMList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#NRList ul li').quicksearch({ position: 'before', attached: '#NRList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#SVList ul li').quicksearch({ position: 'before', attached: '#SVList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });
        $('#WZList ul li').quicksearch({ position: 'before', attached: '#WZList ul', loaderImg: baseMediaPath + 'media/images/loader.gif', labelText: 'Keyword filter:' });

        // Button set
        if ($("#tabButtonSet .selected").length > 0) $($("#tabButtonSet .selected a").attr("href")).css("display", "block");
        $("#tabButtonSet a").click(
			function()
			{
			    $("#tabButtonSet li").removeClass("selected");
			    $(this).parents("li").addClass("selected");

			    $(".qsearch-group").css("display", "none");
			    $($("#tabButtonSet .selected a").attr("href")).css("display", "block");

			    return false;
			}
		);
    }
    /*
    ** state-selection map
    */
    if ($("#stateSelection").length > 0)
    {
        originalClass = $("#stateSelection .map-au")[0].className;
        $("#stateSelection li").hover(
			function() { mapEle = $(this).parents(".map-au"); mapEle[0].className = "map-au"; mapEle.addClass($(this).attr("class") + "-active"); },
			function() { $(this).parents(".map-au")[0].className = originalClass }
		);
    }

    /*
    ** Image FXs
    */
    if ($("#defaultcolumns").length > 0 && $(".specials").length > 0)
    {
        $(".suggest-specials li").hoverIntent({
            sensitivity: 1,
            interval: 1,
            over: function()
            {
                $(this).animate({ opacity: 1 }, 100);
            },
            timeout: 50,
            out: function()
            {
                $(this).animate({ opacity: .7 }, 100);
            }
        });
    }

    //Hint text for textareas
    $("label.labelOver").each
    (
        function()
        {
            $(this).labelOver('labelOver-apply');
        }
    );

    /* loadthickbox */
    if ((window.location).toString().match("#TB_inline"))
    {
        tbURL = window.location.toString().split("#");
        var caption = $(".thickbox:first").attr("title") || $(".thickbox:first").attr("name") || "";
        tb_show(caption, "#" + tbURL, null);
    }


    /* all occasions sub menu*/
    if (document.getElementById('navcontainer'))
    {

        $(".navitem:last").hoverIntent({
            sensitivity: 1,
            interval: 1,
            over: function()
            {
                $(".mainmenu-submenu", this).removeClass("hide").animate({ opacity: 1 }, 100);
            },
            timeout: 50,
            out: function()
            {
                $(".mainmenu-submenu", this).addClass("hide").animate({ opacity: .0 }, 100);
            }
        });
    }


    /* delivery search menu */
    $(".topmenu ul:first li").hoverIntent({
        sensitivity: 1,
        interval: 1,
        over: function()
        {
            $(this).addClass("hover");
            $(".submenu", this).animate({ opacity: .0 }, 1, function() { $(this).removeClass("invisible").animate({ opacity: 1 }, 220); });
        },
        timeout: 50,
        out: function()
        {
            $(this).removeClass("hover");
            $(".submenu", this).animate({ opacity: .0 }, 100, function() { $(this).addClass("invisible") });
        }
    });


    /* delivery search menu */
    $(".top-menu ul:first li span#find-locations").hoverIntent({
        sensitivity: 1,
        interval: 1,
        over: function()
        {
            $(this).addClass("hover");
            $("#locations-view").animate({ opacity: .0 }, 1, function() { $("#locations-view").removeClass("invisible").animate({ opacity: 1 }, 220); });
        },
        timeout: 50,
        out: function()
        {
            $(this).removeClass("hover");
            $("#locations-view").animate({ opacity: .0 }, 100, function() { $(this).addClass("invisible") });
        }
    });


    /* .page-heading menu adjustment*/
    if (document.getElementById("pageHeading"))
    {
        $("#flowerselection").addClass("menu-alt");
    }

    /* flv component */
    if ($("#flashPlaybackComponent").length > 0)
    {
        loadFLV($(".videolist a:first").text(), false);
        $(".videolist a").click(
			function()
			{
			    txt = $(this).text();
			    if ($(this).parent()[0].className != "youtube")
			    {
			        loadFLV(txt, true);
			        return false;
			    }
			}
		);
    }

    /*/ Image loading
    if($(".load-image").length>0) {
    console.log("initial delay is "+(450+(Math.floor(($(".load-image").length * 10) / 2))));
    setTimeout(loadAllImagesNow, 450+(Math.floor(($(".load-image").length * 15) / 2)));
    console.log("time to do full check is "+(10000+(Math.floor(($(".load-image").length * 50)))));
    setTimeout(animateReadyImages, 10000);
    }
    */

    // Section Heading
    $('.fancy-type').flash(
		{
		    src: baseURL + 'media/flash/jfr-jey.swf',
		    flashvars: {
		        css: [
					'* { color: #eae6ea; }',
					'a { color: #eae6ea; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
		    },
		    wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions)
		{
		    htmlOptions.flashvars.txt = this.innerHTML;
		    this.innerHTML = '<span>' + this.innerHTML + '</span>';
		    var $alt = $(this.firstChild);
		    htmlOptions.height = $alt.height();
		    htmlOptions.width = $alt.width();
		    $alt.addClass('alt');
		    $(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);
    $('.jfr-corinthia').flash(
		{
		    src: baseURL + 'media/flash/jfr-corinthia.swf',
		    flashvars: {
		        css: [
					'* { color: #49255c; }',
					'a { color: #49255c; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
		    },
		    wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions)
		{
		    htmlOptions.flashvars.txt = this.innerHTML;
		    this.innerHTML = '<span>' + this.innerHTML + '</span>';
		    var $alt = $(this.firstChild);
		    htmlOptions.height = $alt.height();
		    htmlOptions.width = $alt.width();
		    $alt.addClass('alt');
		    $(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);
    $('.bello').flash(
		{
		    src: baseURL + 'media/flash/jfr-bello.swf',
		    flashvars: {
		        css: [
					'* { color: #202D06; }',
					'a { color: #202D06; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
		    },
		    wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions)
		{
		    htmlOptions.flashvars.txt = this.innerHTML;
		    this.innerHTML = '<span>' + this.innerHTML + '</span>';
		    var $alt = $(this.firstChild);
		    htmlOptions.height = $alt.height();
		    htmlOptions.width = $alt.width();
		    $alt.addClass('alt');
		    $(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);

    /* Image Zoom */
    if (document.getElementById('productImage1'))
    {
        jqZoomObj = $(".jqzoom").jqueryzoom({
            xzoom: 285, //zooming div default width(default width value is 200)
            yzoom: 260, //zooming div default width(default height value is 200)
            offset: 10, //zooming div default offset(default offset value is 10)
            position: "left", //zooming div position(default position value is "right")
            preload: 1,
            lens: 1
        });
        if ($(".jqzoom").length > 0)
        {
            $("#imageTools").append('<a href="#" class="quickzoom">turn off quickzoom</a>');
        }
    }

    /* product thumbnail */
    $("#thumbNav li").click(
		function()
		{
		    // change indicator
		    $("#thumbNav li").removeClass("selected");
		    $(this).addClass("selected");
		    // change viewing image
		    $("#viewImageArea .zoom-image").addClass("offleft");
		    $($("a", this).attr("href")).removeClass("offleft");
		    // return false to stop jumping
		    return false;
		}
	);
    $("#viewImageArea").hoverIntent({
        sensitivity: 1,
        interval: 1,
        over: function()
        {
            $("#imageTools", this).animate({ opacity: 1, top: '290px' }, 100);
        },
        timeout: 50,
        out: function()
        {
            $("#imageTools", this).animate({ opacity: .0, top: '275px' }, 100);
        }
    });

    if (document.getElementById('imageTools')) $("#imageTools").animate({ opacity: .0 }, 2000);
    // enable/disable quickzoom
    $("#imageTools a.quickzoom").click(
		function()
		{
		    if ($(this).text().match("turn off"))
		    {
		        $(".jqzoom").jqueryzoom.settings = {
		            xzoom: 285, //zooming div default width(default width value is 200)
		            yzoom: 260, //zooming div default width(default height value is 200)
		            offset: 10, //zooming div default offset(default offset value is 10)
		            position: "right", //zooming div position(default position value is "right")
		            preload: 1,
		            lens: 1,
		            qzenabled: 0
		        };
		        $(this).text("turn on quickzoom");
		    } else
		    {
		        $(".jqzoom").jqueryzoom.settings = {
		            xzoom: 285, //zooming div default width(default width value is 200)
		            yzoom: 260, //zooming div default width(default height value is 200)
		            offset: 10, //zooming div default offset(default offset value is 10)
		            position: "right", //zooming div position(default position value is "right")
		            preload: 1,
		            lens: 1,
		            qzenabled: 1
		        };
		        $(this).text("turn off quickzoom");
		    }

		    return false;
		}
	);
    // product price
    $(".product-sizes label").click(
		function()
		{
		    updatePriceSummaries();
		    //$("#productPrice span:eq(1)").text($("span:first", this).text().replace($("small:first", this).text(), ""));
		}
	);
    if (document.getElementById('productPrice'))
    {
        $("#productPrice span:eq(1)").text($(".product-sizes input:checked").parent().find("span:first").text().replace($(".product-sizes input:checked").parent().find("small:first").text(), ""));
    }

    InitialiseSwishyTabs(100);

    // Tooltips
    $('.tooltip').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        extraClass: "pretty",
        fixPNG: true,
        left: 17,
        top: -32
    });


    $("a[rel^='prettyOverlay'],a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'fast', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: true, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/' /* The separator for the gallery counter 1 "of" 2 */
    });

    $("a[rel^='prettyPopin']").prettyPopin();

    $(".delivery-calculator input.txt").focus(
		function()
		{
		    if ($(this).val() == "enter suburb") $(this).val("");
		}
	);
    /*
    $(".delivery-calculator input.imgbtn").click(
    function() {
    $(".delivery-calculator a[rel^='prettyPopin']").click();
    return false;
    }
    );
    */
    $(".delivery-calculator a").click(
		function()
		{
		    return false;
		}
	);


    /*
    # Product Details :: Add On Components
    */
    if (document.getElementById('addonSet'))
    {
        //$("#frmProductDetails").append('<ul id="jslogger"></ul>');
        // type tabs
        $("#addonSet .addon-type li").click(
			function()
			{
			    // Handle switch to new set
			    $("#addonSet .addon-options fieldset").addClass("offleft");
			    $($("a", this).attr('href')).removeClass("offleft");
			    // Handle indicator on tab nav
			    $(this).parent().find("li").removeClass("selected");
			    $(this).addClass("selected");
			    // return false to stop jumping
			    return false;
			}
		);
        // options slider	
        $('#addonSet .addon-options ul').jcarousel({
            vertical: true,
            scroll: 1
        });
        // addon item summary
        $("#addonSummary li").remove();
        $("#addonSet .addon-options input").each(function()
        {
            if ($(this)[0].checked) addToItemSummaryList($(this).attr("id"), $(this).val());
        }
		);
        $("#addonSet .addon-options label input").click(
			function()
			{
			    //$("#jslogger").append('<li>that was '+($(this)[0].checked)+'</li>');
			    //if(!$(this)[0].checked) { // if not currently checked
			    //console.log($(this).val() + " and it's id is "+$(this).attr("id"));
			    theVal = $(this).val();
			    theID = $(this).attr("id");
			    clearArr = new Array();
			    if ($("#addonSummary li[rel='" + $(this).attr("id") + "']").length == 0)
			    { // add it to the list
			        // but remove others from the same set
			        $(this).parents("ul:first").find("input").each(function()
			        {
			            if ($(this).attr('id') != theID) clearArr[clearArr.length] = $(this).attr('id'); // find and store id's of current list that's not the new one
			        }
						);
			        for (i = 0; i < clearArr.length; i++)
			        {
			            $("#addonSummary li[rel='" + clearArr[i] + "']").remove();
			            //console.log("removing "+clearArr[i]);
			        }
			        addToItemSummaryList(theID, theVal);
			    }
			    //}
			}
		);
    }


    /*
    # Order Pages :: widgets
    */
    $(".summary-widget .widget-control").click(
		function()
		{
		    if ($(this).parents(".summary-widget")[0].className.match('closed'))
		    { // then it's closed, open it
		        $(this).parents(".summary-widget").removeClass("widget-closed");
		    } else
		    {
		        $(this).parents(".summary-widget").addClass("widget-closed");
		    }
		    return false;
		}
	);


    // Handles the tabs on the category pages    
    if ($(".cattabs").length > 0)
    {
        jQuery(".cattabs").each
        (
            function(index)
            {
                var itemsCount = jQuery(this).find("li").length;
                if (itemsCount > 1)
                {
                    jQuery(this).find("li").click
                    (
			            function()
			            {
			                // Handle switch to new set
			                $(".tabset-parent-container .container").addClass("offleft");
			                $($("a", this).attr('href')).removeClass("offleft");
			                // Handle indicator on tab nav
			                $(this).parent().find("li").removeClass("selected");
			                $(this).addClass("selected");

			                // return false to stop jumping
			                return false;
			            }
		            );
                }
            }
        );
    }

    $(window).bind('resize', ThickboxResize);
});

$(window).bind('load', function() {
	/*
		# Slider
	*/
	if(document.getElementById('seqImages')) {
		seqRef = $("#seqImages");
		seqSettings = seqRef[0].className.split("_"); // sample: jennifer_seq_180_20
		if(seqSettings.length<4) {
			seqSettings[3] = seqSettings[2];
		}
		
		function loadSequenceImages() {
			var preload = new Array();
			htmlBuffer = "<ul>";
			for(i=0;i<seqSettings[3];i++) {
				seqNumString = ((i+1) < 10 ? "0"+(i+1) : (i+1));
				s = baseURL+'admin/prodImages/'+seqRef[0].className+'_'+seqNumString+'.jpg';
				// /admin/prodImages/592,592/Jessica.jpg
				htmlBuffer += '<li><a title="Return to Image Tab for more detailed images" href="'+baseURL+'admin/prodImages/592,592/'+seqSettings[0]+'.jpg'+'" class="thickbox"><img src="'+baseURL+'admin/prodImages/'+seqRef[0].className+'_'+seqNumString+'.jpg'+'" width="300" height="300" alt="" /></a></li>';
				preload.push(s);
			}
			var img = document.createElement('img');
		    $(img).bind('load', function() {
		        if(preload[0]) {
		            this.src = preload.shift();
		        } else { // finished preloading
					htmlBuffer += "</ul>";
					seqRef.html(htmlBuffer);
					$("ul", seqRef).css("top", "0px");
					tb_init($(".thickbox", seqRef));
					$("#sliderOverlayLoading").remove();
				}
		    }).trigger('load');
		}
		
		$("#sliderControls_Next").click(
			function() {
				offset = ($("ul", seqRef).css("top").replace("px", "").replace("pt", "")) - 300;
				if(isNaN(offset)) offset = -300;
				//console.log(offset+">"+((seqSettings[3]*300)*-1)+"?");
				if(offset>((seqSettings[3]*300)*-1)) {
					//console.log("yes, setting to "+offset);
					$("ul", seqRef).css("top", offset);
					
					position = ((offset * -1)/300);
					adjustment = 110/(uisSteps+1); // for +10% adjustment
					//console.log("moveTo "+Math.round((position)*(foo)));
					$("#sliderEle").slider("moveTo", Math.round(position*adjustment), ".ui-slider-handle", true);
				} else { //return top start
					//console.log("no, setting to 0px");
					$("ul", seqRef).css("top", "0px");
					$("#sliderEle").slider("moveTo", 0);
				}
				
				return false;
			}
		);
		$("#sliderControls_Prev").click(
			function() {
				//console.log($("ul", seqRef).css("top").replace("px", "").replace("pt", "") + " _ " + ($("ul", seqRef).css("top").replace("px", "").replace("pt", "") * 1));
				offset = parseInt(($("ul", seqRef).css("top").replace("px", "").replace("pt", "") * 1) + 300);
				//console.log(offset+"<"+300+"?");
				if(offset<300) {
					//console.log("yes, setting to "+offset);
					$("ul", seqRef).css("top", offset);
					position = ((offset * -1)/300);
					adjustment = 110/(uisSteps+1);
					//console.log(position*(110/(uisSteps+1)));
					$("#sliderEle").slider("moveTo", Math.round(position*adjustment), ".ui-slider-handle", true);
				} else { //return top start
					//console.log("no, setting to "+(((seqSettings[3]*300))*-1));
					$("ul", seqRef).css("top", ((seqSettings[3]*300)*-1)+300);
					$("#sliderEle").slider("moveTo", 100, ".ui-slider-handle", true);
				}
				
				return false;
			}
		);
		
		$("#sliderControls_Play").click(
			function() {
				//$("ul", seqRef).animate({top: "-300px"}, 10, function(){console.log("finished")});
				stepFrame("#seqImages", -300);
				
				return false;
			}
		);
		
		function stepFrame(elementRef, offsetAmount) { // initial  (seqRef, -300)
			element = $("ul", elementRef);
			offset = (element.css("top").replace("px", "").replace("pt", "")) - offsetAmount * -1;
			//console.log(offset+" > "+((seqSettings[3]*300)*-1));
			if(offset>((seqSettings[3]*300)*-1)) {
				position = ((offset * -1)/300);
				adjustment = 110/(uisSteps+1); // for +1 adjustment
				//console.log("moveTo "+Math.round((position)*(foo)));
				$("#sliderEle").slider("moveTo", Math.round(position*adjustment), ".ui-slider-handle", true);
				element.animate({top: offset}, 1, function(){
					setTimeout(function(){stepFrame("#seqImages", -300)}, 80); // 360 for 10
				});
			} else {
				element.css("top", "0px");
				$("#sliderEle").slider("moveTo", 0, ".ui-slider-handle", true);
			}
		}
		
		
		uisVal = 0;
		uisSteps = seqSettings[3]-1;
		
		$("#sliderEle").slider({
			steps: uisSteps,
			slide: function(e, ui) {
				if(e && ui.value!=uisVal) {
					//console.log("slide");
					//console.log(ui.value);
					uisVal = ui.value;
					uisPos = Math.floor((ui.value/100)*uisSteps);
					//console.log("slider position is "+uisPos);
					slideTo(uisPos);
				}
			},
			change: function(e, ui) {
				if(ui.value!=uisVal) {
					//console.log("change");
					uisVal = ui.value;
					uisPos = Math.floor((ui.value/100)*uisSteps);
					
					slideTo(uisPos);
				}
			}
		});
		uisWidth = parseInt($("#sliderEle").css("width").replace("px", ""));
		
		function slideTo(position) {
			//console.log("slideTo("+position+")");
			$("ul", seqRef).css("top", ((300 * position)*-1));
		}
		
		
		if(".swishytabs-controls li.selected :contains('360')" && $("#seqImages img").length<1) {
			setTimeout(function(){loadSequenceImages()}, 50);
		}
	}
	
	$("#cycleFeature").before('<div id="nav">').cycle({ 
		fx:     'fade', 
	    speedIn:  850, 
	    speedOut: 100, 
		speed: 1900,
		timeout: 7900,
		pause: 1,
		sync:  false,
	    delay:   -1000
	});

	ThickboxResize();
});

loadFLV = function(txt, autoPlay) {	
	$('#flashPlaybackComponent').empty().flash(
        { 
          src: baseURL+"media/flash/mediaplayer.swf",
          width: 520,
          height: 311,
          allowfullscreen: "true",
          wmode: "transparent",
          flashvars: { width: "520", height: "311", autostart: autoPlay, bufferlength: "3", file: baseURL+"media/video/"+txt.replace(/\s/g, "").toLowerCase()+".flv" }
        },
        { version: 8 }
    );
}

startIndex = -1;
imageCounter = 0;
numPerSet = 10;
imageCount = 0;
function loadAllImagesNow() {
	imageCount = $(".load-image").length;
	
	numSets = Math.ceil((imageCount/numPerSet));
	queImageLoad();
}

function queImageLoad() {
	if(startIndex==-1) {
		startIndex = 0;
	} else {
		startIndex += numPerSet;
	}
	loadImageSet(startIndex, (startIndex+numPerSet));
	if((startIndex+numPerSet)<imageCount) {
		setTimeout(queImageLoad, 1500);
	}
}

function loadImageSet(min, max) {
	//console.log("loadImageSet("+min+", "+max+")");
	$(".load-image:gt("+(min-1)+")").not(":gt("+(max-1)+")").each(
		function() {
			if($("img", this).length <1) {
			$(this).loadThatImage($(this).attr("rel"), function() {
				imageCounter++;
				$(this).wrap('<a href="'+$(this).parent().parent().find("a:first").attr("href")+'"></a>');
				timeoutDuraiton = (($(".load-image").length * 15) / 2) + (imageCounter*20);
				fadeImageIn(this, Math.floor(timeoutDuraiton));
			});
			}
		}
	);
}

imgRefs = new Array();
function fadeImageIn(img, timeoutDuraiton) {
	setTimeout(
		function() {
			$(img).animate({opacity: 1}, 300).parents("div:first").addClass("image-loaded");
		},
		timeoutDuraiton
	);
}

function animateReadyImages() {
	//console.log("animateReadyImages() called");
	$(".load-image").not(".image-loaded").each(
		function() {
			if($("img", this).length>0) {
				$("img", this).animate({opacity: 1}, 100);
				$(this).addClass("image-loaded");
			}
		}
	);
	if($(".load-image").length != $(".image-loaded").length) {
		setTimeout(animateReadyImages, 500);
	}
}

$.fn.loadThatImage = function(src, f){ 
  return this.each(function(){ 
    var i = new Image(); 
    i.src = src; 
    i.onload = f; 
    this.appendChild(i);
  }); 
} 


/*
	# addon item functions
*/
function addToItemSummaryList(theID, theVal) {
	sumryObj = $("#addonSummary");
	$("div", sumryObj).removeClass("hide");
	$("ul", sumryObj).append('<li rel="'+theID+'" style="display:none;">'+theVal+' <a href="#"><img src="'+baseURL+'media/images/icon-delete-small.gif" width="7" height="7" alt="remove add on" /></a></li>');
	$("li[rel='"+theID+"']", sumryObj).fadeIn().find("a").click( function() { 
		removeFromItemList($(this).parent().attr("rel")); 
		return false; 
	});
	// update price
	updatePriceSummaries();
}
function removeFromItemList(relRef) {
	$("#addonSummary li[rel='"+relRef+"']").animate({opacity: 0}, "slow", "swing", function(){ 
		//console.log($(this).parent().find("li").length);
		if($(this).parent().find("li").length == 1) {
			$(this).parents("div:first").addClass("hide");
		}
		$(this).remove(); 
		updatePriceSummaries();
	});
	$(".addon-options input[id='"+relRef+"']")[0].checked = false;
}

function updatePriceSummaries() 
{
	priceAddons = getAddonPriceTotal();
	priceProd = parseFloat($("#baseProductPrice").attr("value"));

	//console.log("addons = "+priceAddons);
	$("#addonTotal").text(priceAddons.toFixed(2));
	$("#selectedPrice").text("$" + (parseFloat(priceAddons + priceProd).toFixed(2)));
	
}

function getAddonPriceTotal() {
	var price = 0.00;
	$("#addonSummary li").each(	function() {
			//console.log("adding "+(parseFloat($(".addon-options input[id='"+$(this).attr("rel")+"']").parent().find("span").text())));
			price += parseFloat($(".addon-options input[id='"+$(this).attr("rel")+"']").parent().find("span").text());
		}
	);
	return parseFloat(price);
}


/*
	** Global functions
*/
jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};

jQuery.fn.log = function (msg) {
	console.log("%s: %o", msg, this);
	return this;
};

function enableJSClass()
{
	document.body.className = "jsEnabled";
}

function printPage() { 
	if (window.print) { 
		window.print(); 
	} else { 
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; 
	}
}


function StripNonNumericCharacters(id) {               
    var temp = $("#"+id).val();
    temp = temp.replace(/\D+/g, "");
    $("#"+id).val( temp );
}

var viewportWidth;
var viewportHeight;
function ThickboxResize()
{
    viewportWidth = Math.max((self.innerWidth || (document.documentElement.clientWidth || (document.body.clientWidth || 0))) - 80, 20);
    viewportHeight = Math.max((self.innerHeight || (document.documentElement.clientHeight || (document.body.clientHeight || 0))) - 80, 20);

    $('a.thickbox').each
	(
	    function()
	    {
	        var text = $(this).attr("href");

	        var idealWidthFound = false;
	        var idealWidth;
	        var widthidealmatches = text.match(/widthideal=[0-9]*/);
	        if (widthidealmatches != null && widthidealmatches.length > 0)
	        {
	            idealWidthFound = true;
	            idealWidth = widthidealmatches[0].substr(11);
	        }

	        var widthFound = false;
	        var width;
	        var widthmatches = text.match(/width=[0-9]*/);
	        if (widthmatches != null && widthmatches.length > 0)
	        {
	            widthFound = true;
	            width = widthmatches[0].substr(6);
	            if (!idealWidthFound)
	            {
	                idealWidth = width;
	            }
	        }

	        var idealHeightFound = false;
	        var idealHeight;
	        var heightidealmatches = text.match(/heightideal=[0-9]*/);
	        if (heightidealmatches != null && heightidealmatches.length > 0)
	        {
	            idealHeightFound = true;
	            idealHeight = heightidealmatches[0].substr(12);
	        }

	        var heightFound = false;
	        var height;
	        var heightmatches = text.match(/height=[0-9]*/);
	        if (heightmatches != null && heightmatches.length > 0)
	        {
	            heightFound = true;
	            height = heightmatches[0].substr(7);
	            if (!idealHeightFound)
	            {
	                idealHeight = height;
	            }
	        }

	        var changesMade = false;
	        if (idealWidthFound || widthFound)
	        {
	            if (viewportWidth < width)
	            {
	                // adjust the width
	                changesMade = true;
	                if (idealWidthFound)
	                {
	                    text = text.replace(/width=[0-9]*/, 'width=' + viewportWidth);
	                }
	                else
	                {
	                    text = text.replace(/width=[0-9]*/, 'widthideal=' + idealWidth + '&width=' + viewportWidth);
	                }
	            }
	            else if (viewportWidth > width && idealWidth > width)
	            {
	                changesMade = true;
	                text = text.replace(/width=[0-9]*/, 'width=' + Math.min(viewportWidth, idealWidth));
	            }
	        }

	        if (idealHeightFound || heightFound)
	        {
	            if (viewportHeight < height)
	            {
	                // adjust the height
	                changesMade = true;
	                if (idealHeightFound)
	                {
	                    text = text.replace(/height=[0-9]*/, 'height=' + viewportHeight);
	                }
	                else
	                {
	                    text = text.replace(/height=[0-9]*/, 'heightideal=' + idealHeight + '&height=' + viewportHeight);
	                }
	            }
	            else if (viewportHeight > height && idealHeight > height)
	            {
	                changesMade = true;
	                text = text.replace(/height=[0-9]*/, 'height=' + Math.min(viewportHeight, idealHeight));
	            }
	        }

	        if (changesMade)
	        {
	            $(this).attr("href", text);
	        }
	    }
	);
}

// toggle del pref, implemented for vday options
//function toggleDeliveryPrefMessages(pInput) {
//	var parts;
//    var parts1 = pInput.val().split(" ");
//    if (parts1.length > 1) {
//        parts = parts1[1].split("/");
//    }
//    else {
//        parts = parts1[0].split("/");
//    }
//    var deliveryDate = new Date(parts[2], parts[1] - 1 /* 0 based month */, parts[0], 0, 0, 0, 0);

//    var mday = new Date(2009, 4 /* 0 based month */, 10, 0, 0, 0, 0);
//	
//    if (deliveryDate.valueOf() == mday.valueOf()) {
//        $("#specialDeliveryMessage").show();
//    }
//    else {
//        $("#specialDeliveryMessage").hide();
//    }
//}
