function addPageTools() {
	var clientDomainName = 'avera.org',
		clientSiteName = 'Avera',
		currentPageUrl = document.location,
		currentPageTitle = $.trim($('title').text()),
		emailSubject = clientDomainName + ': ' + currentPageTitle,
		emailHref = 'mailto:?subject=' + escape(emailSubject) + '&body=I thought you would be interested in a page on the ' + escape(clientSiteName) + ' Web site: ' + escape(currentPageTitle) + ' - ' + escape(currentPageUrl);
    var urlToUse = (('https:' == document.location.protocol) ? 'https://secure.addthis.com/js/250/addthis_widget.js?pub=averaaddthis' : 'http://s7.addthis.com/js/250/addthis_widget.js?pub=averaaddthis');
	$('#PageToolsWrapper').append('<div id="PageTools"><ul>' +
		'<li class="AddThis">' +
			'<script type="text/javascript">var addthis_pub = "averaaddthis";</script>' +
			'<a href="http://www.addthis.com/bookmark.php?v=250&pub=averaaddthis" onclick="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close();" onclick="return addthis_sendto();">Share This Page</a>' +
			'<script type="text/javascript" src="' + urlToUse + '"></script>' +
		'</li>' +
		'<li class="Email"><a href="' + emailHref + '">Email</a></li>' +
		'<li class="Print"><a href="javascript:;" onclick="print();">Print</a></li>' +
	'</ul></div>');
}
function addTextSizer() {
    $('#PageTools').before('<div id="TextSizer"><p>Change Font Size</p><ul>' +
				'<li><a class="NormalFont" href="javascript:;" title="Small Font Size">Normal</a></li>' +
				'<li><a class="LargeFont" href="javascript:;" title="Medium Font Size">Large</a></li>' +
				'<li><a class="X-LargeFont" href="javascript:;" title="Large Font Size">X-Large</a></li>' +
			"</ul></div>");
	$('a.NormalFont').click(function() {$('#Content').removeClass('textLarge').removeClass('textXLarge');$.cookie('text_sizer', null, { path: '/' });});
	$('a.LargeFont').click(function() {$('#Content').addClass('textLarge').removeClass('textXLarge');$.cookie('text_sizer', 'large', { path: '/' });});
	$('a.X-LargeFont').click(function() {$('#Content').removeClass('textLarge').addClass('textXLarge');$.cookie('text_sizer', 'xlarge', { path: '/' });});
	$('#TextSizer a').click(function() {$('#TextSizer a').removeClass('active');$(this).addClass('active');});
}
function text_size_checker() {
	var text_sizer_cookie = $.cookie('text_sizer');
	if (text_sizer_cookie==null){$('a.NormalFont').addClass('active')};
	if (text_sizer_cookie=='large'){ $('#Content').addClass('textLarge');$('a.LargeFont').addClass('active') };
	if (text_sizer_cookie=='xlarge'){ $('#Content').addClass('textXLarge');$('a.X-LargeFont').addClass('active') };
}
	
function dynamicWMVVideoPlayer(){
	// Like the above player, but instead will allow for WMV instead.
	// <a class="WMVVideoLink" href="video/filename.wmv" name="height=288;width=512;hideControls=true;autoStart=true">Any Text You Like</a>
		$('a.WMVVideoLink').each(function(n){
	
		var divID = 'WMVid'+n;
		$(this).wrap('<div class="WMVVideoPlayer" id="' + divID + '"></div>');
		$(this).hide();
		
		var filename = $(this).attr('href');
		var vars = $(this).attr('name').replace(/\s+/g,'');
		var varArray = vars.split(";");
		
		var height, width, hideControls, autoStart;
		height = width = hideControls = autoStart = '';
		
		var cnt = 0
		while (cnt < varArray.length) {
			if (varArray[cnt].toLowerCase().startsWith('height=')) { var height = varArray[cnt].toLowerCase().replace(/height=/g,''); };
			if (varArray[cnt].toLowerCase().startsWith('width=')) { var width = varArray[cnt].toLowerCase().replace(/width=/g,''); };
			if (varArray[cnt].toLowerCase().startsWith('hidecontrols=')) { var hideControls = varArray[cnt].toLowerCase().replace(/hidecontrols=/g,''); };
			if (varArray[cnt].toLowerCase().startsWith('autoStart=')) { var autoStart = varArray[cnt].toLowerCase().replace(/autoStart=/g,''); };
			cnt+=1;
		};

		if (height < 0 || height > 600) { var height = "240" };
		if (width < 0 || width > 800) { var width = "360" };
		if (hideControls == 'true') { hideControls = 'false' } else if (hideControls == 'false') { hideControls = 'true' };
		if (hideControls !== 'true' || hideControls !== 'false') { var hideControls = 'true' };
		
		if (hideControls == 'false') { autoStart = 'true' };
			
		$('#'+divID)
		.append('<OBJECT ID="MediaPlayer" WIDTH="' + width +'" HEIGHT="' + height +'" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">'
				+ '<PARAM NAME="FileName" VALUE="' + filename + '">'
				+ '<PARAM name="autostart" VALUE="' + autoStart + '">'
				+ '<PARAM name="ShowControls" VALUE="' + hideControls + '">'
				+ '<param name="ShowStatusBar" value="false">'
				+ '<PARAM name="ShowDisplay" VALUE="false">'
				+ '<EMBED TYPE="application/x-mplayer2" SRC="' + filename + '" NAME="MediaPlayer" WIDTH="' + width +'" HEIGHT="' + height +'" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="0"> </EMBED>'
				+ '</OBJECT>');
	});
	}

$(document).ready(function(){
	addPageTools();	
	addTextSizer();
	text_size_checker();
	dynamicWMVVideoPlayer();
});


//Extras

// img embelished style
function ImageEmbellish(){
    $('.ImageEmbellished img').each(function(){
		var $i = $(this);
		if ($i.get(0).complete){ DoImgOverlay($i,$i.height(),$i.width()) }
		else{ $i.load(function(){ DoImgOverlay($i,$i.height(),$i.width()) }) }
    });
	function DoImgOverlay(obj,h,w){obj.siblings('.ImageEmbellishedOverlay').css({height: h, width: w}) }
}


$(document).ready(function () {

    // ----------- TEMPLATE EXTRAS ------------------//

    //adding active class to hard coded main nav
    var sectionName = $.url.segment(0);
    if (sectionName != null) {
        if (sectionName.toLowerCase() == 'services') { $('#CorpMainNav li.First').addClass('Active'); }
        if (sectionName.toLowerCase() == 'locations') { $('#CorpMainNav li.Second').addClass('Active'); }
        if (sectionName.toLowerCase() == 'doctors') { $('#CorpMainNav li.Third').addClass('Active'); }
        if (sectionName.toLowerCase() == 'eventscalendar') { $('#CorpMainNav li.Fourth').addClass('Active'); }
        if (sectionName.toLowerCase() == 'health-info') { $('#CorpMainNav li.Fifth').addClass('Active'); }
        if (sectionName.toLowerCase() == 'careers') { $('#CorpMainNav li.Sixth').addClass('Active'); }
        if (sectionName.toLowerCase() == 'avera') { $('#CorpMainNav li.Seventh').addClass('Active'); }
    }
    $('#CorpMainNav li.Active a').addClass('Active');

    /* adding padding to the last main nav link to span across entire container 
    so that background spans all the way to the right.*/
    $('#CorpMainNav span').each(function (i) {
        var ah = $('#CorpMainNav ul').eq(i).width();
        var mh = (950 - ah - 1); //need -1 to fix wrapping on Mac
        $('#CorpMainNav li.Seventh a').eq(i).css('padding-right', mh);
        $('#CorpMainNav li.Seventh strong').eq(i).css('padding-right', mh);
    });

    // For Tri-State templates - moving prox nav within main nav
    $('body.TriStateLeftCol #ProximityNav').appendTo('#MainNav li.Active');
    $('body.LeftCol #ProximityNav').appendTo('#MainNav li.Active');
    $('body.Interior #ProximityNav').appendTo('#MainNav li.Active');
    $('body.Landing #ProximityNav').appendTo('#MainNav li.Active');

    // Removing Proximity Nav h2 if on page not in subsection.
    if ($('#Breadcrumbs p a[href]').length < 3) {
        $('#ProximityNav').addClass('RemoveH2');
    }
    else {
        $('#ProximityNav').addClass('KeepH2');
    }

    //Drop Down Styles
    // adds a width to the .Flyout .Dec div if it is shorter than Toggle anchor
    $('.DropDown').not('.Dropdown-Small').each(function () {
        var tw = $(this).find('a.Toggle').width();
        var fw = $(this).find('.Flyout').width();
        var mw = (tw - 22);
        if (fw < tw) {
            $(this).find('.Dec').css('width', mw);
        }
    });
    //Creates DropDown style function
    $('.Toggle').live('click', function () {
        var trigger = $(this);
        var triggerHeight = trigger.outerHeight();
        var triggerPosition = trigger.offset();
        var thePop = $(this).siblings('.Flyout');
        var popHeight = thePop.height();
        var docHeight = $(document).height();
        var winHeight = $(window).height();
        var scrolledHeight = $(window).scrollTop();

        var heightAboveTrigger = (triggerPosition.top - scrolledHeight);
        var heightBelowTrigger = winHeight - heightAboveTrigger - triggerHeight;

        var offset = 0;

        // if there's not enough room below, then set postion to be above trigger
        if (heightBelowTrigger < popHeight) {
            offset = -popHeight;
            // unless there's not enough room above it, then show below
            if (heightAboveTrigger < popHeight) {
                offset = $(this).outerHeight();
            }
            // except when we're at the end of the document, and there's not enough room below but there is above then show it above
            if ((docHeight - (winHeight + scrolledHeight) < popHeight) && (heightBelowTrigger < popHeight) && ((heightAboveTrigger + scrolledHeight) > popHeight)) {
                offset = -popHeight;
            }
        }
        // if there is enough room to show below, then do it
        else {
            offset = $(this).outerHeight();
        }

        // set z-index for dropdown then show the popup
        trigger.closest('.DropDown').css({ 'z-index': '3000' });
        //        thePop.css({ 'top': offset }).show();
        thePop.css({ 'top': offset, visibility: 'visible' });

    });

    // on mouseout, hide the popup
    $('.DropDown').mouseleave(function () {
        //        $(this).find('.Flyout').hide();
        $(this).find('.Flyout').css({ visibility: 'hidden' });
        $(this).css({ 'z-index': '0' });
    });

    //remove col3 if empty
    $('#Col3:empty').remove();

    //only show banner curve if panel exists within space
    $('#BannerCurve').hide();
    if ($('#Banner .cmspanel').length > 0) {
        $('#BannerCurve').show();
    }

    // Do the ImageEmbellish Thing on Page Load
    ImageEmbellish();

    // img embelished doesn't work with hidden elements... so we'll re-activate it when you click on a tab or accordion to update the images that were hidden.
    $('.Tabnav li').live('click', function () { ImageEmbellish() });
    $('.Accordion .Trigger').live('click', function () { ImageEmbellish() });

    // Avera Medical Group style
    $('.DrList li strong:contains("Avera Medical Group")').parent().parent().parent().parent().addClass('AMG');
    $('.DrList li strong:contains("Avera Medical Group")').prepend('<div id="HelpOverlay"><img src="/imgs/icons/help.gif" alt="What\'s this?" /><div class="Overlay"><p>Avera Medical Group physicians maintain their own practices and are backed by the resources of Avera.</p></div></div>');
    $('.DrList li strong:contains("Avera Medical Group")').text('Avera Medical Group').append('<div id="HelpOverlay"><img src="/imgs/icons/help.gif" alt="What\'s this?" /><div class="Overlay"><p>Avera Medical Group physicians maintain their own practices and are backed by the resources of Avera.</p></div></div>');

    // Hide the results list on the locations index page
    var thisDir = $.url.attr('directory')
    if (thisDir.indexOf('locations/index.aspx') > 0) {  // if the word 'locations/index.aspx' exists in the url path anywhere, then do this
        $('.Paging').remove();
        $('.LocationsList').remove();
    }

    // ----------- HACK LIST START ------------------//

    //removing padding from empty table cells from calendar event detail header
    $('.CalendarEventDetailHeader td:empty').addClass('Empty');

    // Doctors: move custom field link into Designations on Doctor Detail page
    // e.g.  http://avera5dev.geonetric.com/app/doctors/advanced/profile.aspx?id=1668#Profile
    $('#DrDetail .Directions h3').remove();

    var DrDirections = $('#DrDetail .Directions').html(),
		DrPrimaryLocation = $('#DrDetail .MapContainer li.PrimaryLocation strong').html(),
		DrOfficePhone = $('#DrDetail .Contacts li:contains("Office")').html();

    if (DrDirections !== null) { } else { DrDirections = '' }
    if (DrPrimaryLocation !== null) { DrPrimaryLocation = '<p class="DrPrimaryLocation">' + DrPrimaryLocation + '</p>' } else { DrPrimaryLocation = '' }
    if (DrOfficePhone !== null) { DrOfficePhone = '<p class="DrOfficePhone">' + DrOfficePhone.replace('Office: ', '') + '</p>' } else { DrOfficePhone = '' }
    $('#DrDetail .Directions').remove();
    $('#DrDetail .Designations').append('<div class="Extras">' + DrPrimaryLocation + DrOfficePhone + DrDirections + '</div>');

    // removing ClearFix so that the data isn't pushed down the page
    $('#DrDetail .Promotions').removeClass('ClearFix');

    // changing link text in Recent News SmartPanel
    $('#SmartPanelNewsRecent .MoreLink a').html('view additional news');

    // --- Hack for interior Location page Floyd Valley --- // Commenting out to resolve Bug#28794
    // Find image with class="NoMargin" and move image before #Banner. Then remove class="NoMargin" and replace styling
    //$('.Interior #Col2 #Content img.NoMargin').insertBefore($('#Col2Col3Wrapper #Banner')).removeClass('NoMargin').css("margin-left", "10px");
    // Next find the empty div caused by moving the image, and remove its parent div.cmspanel -- this removes the large space above the text 
    //$('.Interior #Col2 #Content .cmsPanelContent').empty().closest('.cmspanel').remove();

    // Add google Event Tracking to banner images on Homepage -- Bug #28675
    $(".Home #Banner ul li").click(function () {
        var i = $(".Home #Banner ul li").index($(this));
        _gaq.push(['_trackEvent', 'Banner', 'Click', 'Banner Image ' + (i + 1)]);
    });

    // ----------- HACK LIST END ------------------//

});


// TEMP ONLY!!! - CAN REMOVE AFTER NEW PHOTOSLIDER RELEASE
// PHOTO SLIDER
//  minify at http://refresh-sf.com/yui/
addLoadEvent(initializePhotoSliders);function initializePhotoSliders(){var c=[],f=[];$(".PhotoSliderVS").each(function(n){var o=$(this);o.wrapInner('<div class="Border ClearFix"><div class="Overflow"></div></div>').find(".Border").append('<div class="Buttons ClearFix"></div>').find(".Overflow").children("ul").addClass("Container").children("li").addClass("Slide").eq(0).addClass("Active");o.find("li.Slide:first").addClass("First");o.find("li.Slide:last").addClass("Last");if(o.attr("class").match(/^.*SlideW(\d+).*/)!==null){var m=o.attr("class").match(/^.*SlideW(\d+).*/)[1];o.find("li.Slide").width(parseInt(m))}if(!o.hasClass("HideCaptions")){o.find(".Buttons").before('<p class="PhotoCaption"></p>')}if(!o.hasClass("HideArrows")){o.find(".Buttons").append('<a class="Prev" href="javascript:;"></a><a class="Next" href="javascript:;"></a>')}if(o.hasClass("ShowNav")||o.hasClass("Vertical")){var v=o.find("li.Slide").size(),h='<div class="SlideNav ClearFix"><ul>',y=1;for(y=1;y<=v;y++){h+='<li><a href="javascript:;"><span>'+y+"</span></a></li>"}h+="</ul></div>";o.find(".Buttons").append(h);o.find(".SlideNav li:first").addClass("First");o.find(".SlideNav li:last").addClass("Last")}else{if(!o.hasClass("HideNumbers")){o.find(".Buttons").append('<em class="Count"><span></span>&nbsp;of&nbsp;<span></span></em>')}}if(o.hasClass("HideNumbers")&&o.hasClass("HideCaptions")){o.find(".Buttons").prepend("<em>&nbsp;</em>")}if(o.hasClass("Vertical")){o.find(".Border").addClass("Vertical")}var k=0,l=0,q=0,z=parseInt(o.find(".Border").css("borderBottomWidth"))*2,w=parseInt(o.css("padding-left")),u=parseInt(o.css("padding-right"));o.find(".Slide").each(function(){if($(this).outerWidth(true)>l){l=$(this).outerWidth(true)}});var j=o.attr("class").match(/^.*Width(\d+).*/),r;if(j!==null||o.hasClass("FullWidth")){if(o.hasClass("FullWidth")){o.hide();r=o.parent().width()-w-u;o.show()}else{r=parseInt(j[1])}o.width(r).addClass("manualWidth");o.find(".Overflow").width(r-z);var x=o.width()-o.css("padding-left").replace("px","")-o.css("padding-right").replace("px","");o.find(".Slide").width(x).addClass("SlideContent")}else{if(o.attr("class").match(/^.*Show(\d+).*/)!==null){o.addClass("manualWidth").addClass("MultiSlide");var p=o.attr("class").match(/^.*Show(\d+).*/)[1],m=o.find("li.Slide.Active").outerWidth(),t=o.find("li.Slide").size()-p;o.width(p*m+z);o.find(".Overflow").width(p*m);o.find("li.Slide").eq(t).addClass("LastSlideToShow")}else{o.width(l+z)}}o.find("li.Slide").each(function(){k+=$(this).outerWidth(true)});o.find(".Container").width(k+100);if(o.attr("class").match(/^.*AutoSlide.*/)!==null){o.addClass("Continuous");var s=4000;if(o.attr("class").match(/^.*AutoSlide(\d+).*/)){s=o.attr("class").match(/^.*AutoSlide(\d+).*/)[1]}f[e(o)]=s;c[e(o)]=setInterval(function(){d(e(o))},s)}d(e(this),0,true)});$('.PhotoSliderVS[class*="AutoSlide"]').hover(function(){var h=e($(this));$(this).addClass("Paused");clearInterval(c[h])},function(){var h=e($(this));$(this).removeClass("Paused");c[h]=setInterval(function(){d(h)},f[h])});$(".PhotoSliderVS .Buttons .Prev:not(.Inactive)").live("click",function(h){var i=$(this).closest(".PhotoSliderVS");if(i.hasClass("Continuous")&&i.hasClass("MultiSlide")&&i.find("li.Slide.Active").hasClass("First")){prevSlide=i.find("li.Slide").index(i.find("li.Slide.LastSlideToShow"))}else{if(i.hasClass("Continuous")&&i.find("li.Slide.Active").hasClass("First")){prevSlide=i.find("li.Slide").size()-1}else{prevSlide=a(this)-1}}d(e(this),prevSlide)});$(".PhotoSliderVS .Buttons .Next:not(.Inactive)").live("click",function(h){var i=$(this).closest(".PhotoSliderVS");if(i.hasClass("Continuous")&&i.hasClass("MultiSlide")&&i.find("li.Slide.Active").hasClass("LastSlideToShow")){nextSlide=0}else{if(i.hasClass("Continuous")&&i.find("li.Slide.Active").hasClass("Last")){nextSlide=0}else{nextSlide=a(this)+1}}d(e(this),nextSlide)});$(".PhotoSliderVS .Buttons .SlideNav li").live("click",function(){var h=$(this).parent("ul").find("li").index($(this));d(e(this),h)});$(".PhotoSliderVS .Buttons .SlideNav ul.ImageThumbs li").hover(function(){$(this).not(".Active").animate({opacity:1},200)},function(){$(this).not(".Active").animate({opacity:0.4},200)}).live("click",function(){$(this).css({opacity:1})});function b(i){var h=i.width()+parseInt(i.css("padding-left"))+parseInt(i.css("padding-right"))+parseInt(i.css("margin-right"))+parseInt(i.css("margin-left"))+parseInt(i.css("borderRightWidth"))+parseInt(i.css("borderLeftWidth"));return h}function g(j){var i=j.height()+parseInt(j.css("padding-top"))+parseInt(j.css("padding-bottom"))+parseInt(j.css("margin-top"))+parseInt(j.css("margin-bottom"))+parseInt(j.css("borderTopWidth"))+parseInt(j.css("borderBottomWidth"));return i}function e(i){var j=$(i).closest(".PhotoSliderVS"),h=$(".PhotoSliderVS").index(j);return h}function a(i){var j=$(i).closest(".PhotoSliderVS"),h=j.find("li.Slide").index(j.find("li.Slide.Active"));return h}function d(h,j,i){$(".PhotoSliderVS").eq(h).each(function(){var Q=$(this),N=Q.find(".Overflow"),H=Q.find(".Container"),G=Q.find("li.Slide").size(),U="slide";if(j==null){j=a(this)+1;if(Q.find("li.Slide.Active").hasClass("Last")){j=0}}Q.find("li.Slide.Active").removeClass("Active");Q.find("li.Slide").eq(j).addClass("Active");Q.find(".Buttons .Count span:first").html(a(Q)+1);Q.find(".Buttons .Count span:last").html(G);caption=Q.find("li.Slide.Active .Caption").html();if(caption==null){caption=Q.find("li.Slide.Active img").attr("alt")}Q.find(".PhotoCaption").html(caption);if(!Q.hasClass("Continuous")){if(a(Q)=="0"){Q.find(".Buttons .Prev").addClass("Inactive")}else{Q.find(".Buttons .Prev").removeClass("Inactive")}if(a(Q)+1==G||Q.find("li.Slide.Active").hasClass("LastSlideToShow")){Q.find(".Buttons .Next").addClass("Inactive")}else{Q.find(".Buttons .Next").removeClass("Inactive")}}Q.find(".SlideNav li.Active").removeClass("Active");Q.find(".SlideNav li").eq(a(Q)).addClass("Active");if(Q.hasClass("FadeMe")){U="fade";Q.find("li.Slide").css("position","absolute");Q.find("li.Slide").eq(a(Q)).addClass("Active").stop().css({opacity:"0","z-index":"92"});if(i==true){Q.find("li.Slide").eq(a(Q)).css({opacity:"1"},function(){Q.find("li.Slide").not(".Active").css({"z-index":"90"});Q.find("li.Slide.Active").css("z-index","91")})}else{Q.find("li.Slide").eq(a(Q)).animate({opacity:1},function(){Q.find("li.Slide").not(".Active").css({"z-index":"90"});Q.find("li.Slide.Active").css("z-index","91")})}}var K=Q.find("li.Slide.Active").outerWidth(),V=Q.find("li.Slide.Active").outerHeight(),X=0,E=0;Q.find("li.Slide").each(function(){if(E<$(this).outerHeight()){E=$(this).outerHeight()}});if(!Q.hasClass("manualWidth")){if(i==true){N.width(K).height(E)}else{N.animate({width:K})}}if(Q.hasClass("ShowNav")||Q.hasClass("Vertical")){var I,r,z=false,m=0,s=0,D=0,W=0,P=0,y=0,p="",l=0.1,S=Q.find(".SlideNav"),C=0,L=0,v=0,M=Q.find(".Buttons .Prev").outerHeight(),o=Q.find(".Buttons .Next").outerHeight(),F=Q.find(".Buttons .Prev").outerWidth(),Y=Q.find(".Buttons .Next").outerWidth(),R,k;if(M>0&&o>0&&F>0&&Y>0){if(M>o){k=M}else{k=o}if(F>Y){R=F}else{R=Y}}else{M=0;F=0;o=0;Y=0}if(Q.hasClass("Vertical")){z=true;I=Q.find(".Buttons").parent().height()-parseInt(Q.find(".Buttons").css("padding-top"))-parseInt(Q.find(".Buttons").css("padding-bottom"));r=I-(M+o);Q.find(".Buttons").height(I)}else{r=Q.find(".Buttons").width()-parseInt(Q.find(".Buttons").css("padding-left"))-parseInt(Q.find(".Buttons").css("padding-right"))-(F+Y)}if(Q.attr("class").match(/^.*ImageThumbs.*/)!==null){Q.find(".SlideNav ul").addClass("ImageThumbs");if(Q.attr("class").match(/^.*ImageThumbs(\d+).*/)){l=Q.attr("class").match(/^.*ImageThumbs(\d+).*/)[1]*0.01}S.find("li").each(function(n){p=Q.find("li img").eq(n);$(this).html('<img src="'+p.attr("src")+'" width="'+p.width()*l+'" height="'+p.height()*l+'"/>').not(".Active").css("opacity","0.4")})}S.find("li").each(function(){if(z){y=g($(this));$(this).height($(this).height())}else{y=b($(this))}D+=y;if(y>W){W=y}if($(this).outerWidth(true)>C){C=$(this).outerWidth(true);L=C}if(R>C){C=R}});P=(parseInt(r/W));var O=0;if($.browser.msie&&$.browser.version.substr(0,1)<7){O=parseInt(S.find("li").css("margin-right"))}if(r<D){if(!(P%2)){P=P-1}var T=S.find("li.Active"),x=S.find("li").index(T),A=0,t=(P*0.5)-0.5,B=x-t,u=B+P,q=0;if(B<0){B=0;u=B+P}if(u>G){u=G;B=u-P}S.find("li.ShowNav").removeClass("ShowNav");S.find("li").slice(B,u).addClass("ShowNav");var J=S.find("li").index(S.find(".ShowNav:first"));if(z){S.find("li").slice(0,J).each(function(){A+=g($(this))});S.find("li.ShowNav").each(function(){m+=g($(this))});S.find("ul").height(D+O).stop().animate({top:-A})}else{S.find("li").slice(0,J).each(function(){A+=b($(this))});S.find("li.ShowNav").each(function(){m+=b($(this))});S.find("ul").width(D+O).stop().animate({left:-A})}}else{if(z){S.find("ul").height(D+O)}else{S.find("ul").width(D+O)}m=D+O}if(z){S.height(m).css("top",((r-m)*0.5)+Q.find(".Buttons .Prev").outerHeight());if(i){S.find("li").width(L-parseInt(S.find("li").css("padding-right"))-parseInt(S.find("li").css("padding-left"))-parseInt(S.find("li").css("borderRightWidth"))-parseInt(S.find("li").css("borderLeftWidth")));I=+C+parseInt(Q.find(".Buttons").css("padding-left"))+parseInt(Q.find(".Buttons").css("padding-right"));Q.width($(this).width()+I);Q.find(".Buttons").width(C);if(Q.hasClass("NavRight")){Q.find(".Overflow,.PhotoCaption").css("margin-right",I);Q.find(".Border").addClass("NavRight");Q.find(".Buttons").css("margin-left",Q.find(".Overflow").width())}else{Q.find(".Overflow,.PhotoCaption").css("margin-left",I)}if(R>L){v=parseInt((C-L)*0.5);S.css("margin-left",v+"px").css("margin-right",v+"px")}else{v=parseInt((C-R)*0.5);S.siblings(".Prev,.Next").css("margin-left",v+"px").css("margin-right",v+"px")}}}else{S.width(m)}}Q.find("li.Slide:lt("+a(Q)+")").each(function(){X+=$(this).outerWidth(true)});if(U=="slide"){H.stop().animate({left:-X})}})}};


