var viewer=null;var currentSearchIndex=0;var searchMosaicIDs=null;var cachedMosaicTiles=new Array();var slideshowTimeoutHandle=null;var noPhotosFoundHandle=null;var slideshowState="stop";var slideshowInterval=6000;var homeZoom=null;var triangleOffset=20;var omniture;var lastSearchTerm=null;var lastSearchType=null;var noPhotosFound;var maxZoom;function zoomAndPanToPixelBounds(f,c,b,i){var h=f.source.getPixelRatio(f.source.maxLevel);c=c.times(h.x);var a=f.viewport.getContainerSize();var g=f.viewport.getAspectRatio();var m=c.getBottomRight();var k=new Seadragon.Rect(c.x,c.y,c.width,c.height);if(k.getAspectRatio()>=g){k.height=c.width/g;k.y=m.y-k.height/2}else{k.width=c.height*g;k.x=m.x-k.width}f.viewport.panTo(f.viewport.getCenter(true),true);f.viewport.zoomTo(f.viewport.getZoom(true),null,true);var e=f.viewport.getBounds();var l=f.viewport.getZoom();var j=1/k.width;var d=k.getTopLeft();d.x+=b/(a.x/k.width);if(j==l||k.width==e.width){var n=k.getBottomRight();n.x-=f.viewport.getBounds().width/2;n.x+=b/(a.x/k.width);n.y-=(f.viewport.getBounds().height/2);f.viewport.panTo(n);return}var n=e.getTopLeft().times(a.x/e.width).minus(d.times(a.x/k.width)).divide(a.x/e.width-a.x/k.width);f.viewport.zoomTo(j,n,i)}Seadragon.Rect.prototype.times=function(a){return new Seadragon.Rect(this.x*a,this.y*a,this.width*a,this.height*a)};function zoomToTile(c,g,h,f,a){var e=document.getElementById("img_info");var d=c.elmt;var i=(Seadragon.Utils.getElementPosition(d).x+Seadragon.Utils.getElementSize(d).x)-Seadragon.Utils.getElementPosition(e).x;var b=new Seadragon.Rect(g,h,f,a);zoomAndPanToPixelBounds(c,b,i,false)}function zoomIn(a){if(viewer.viewport.getZoom()<175){hideSearchResults();omniture.logZoomIn("control");viewer.viewport.zoomBy(Seadragon.Config.zoomPerClick/1)}}function zoomOut(a){if(viewer.viewport.getZoom()>0.732734933137937){hideSearchResults();omniture.logZoomOut("control");viewer.viewport.zoomBy(1/Seadragon.Config.zoomPerClick)}}var infoPanel;var searchPanel;var zoomLevelPanel;var textField;var favoriteShoe;var country;var ratingSelect;$(function(){setupReferences();initSeadragon();infoPanel.fadeOut(1);$("#shoes_scrollable").scrollable({vertical:true,size:9}).mousewheel();$("#country_scrollable").scrollable({vertical:true,size:9}).mousewheel();$("#rating_scrollable").scrollable({vertical:true,size:6}).mousewheel();favoriteShoe.hoverIntent({sensitivity:3,interval:200,over:function(){favoriteShoe.PopupWindow.show("fast");favoriteShoe.addClass("fav_shoe_on")},timeout:300,out:function(){favoriteShoe.PopupWindow.hide("fast");favoriteShoe.removeClass("fav_shoe_on")}});ratingSelect.hoverIntent({sensitivity:3,interval:200,over:function(){ratingSelect.PopupWindow.show("fast");ratingSelect.addClass("rating_on")},timeout:300,out:function(){ratingSelect.PopupWindow.hide("fast");ratingSelect.removeClass("rating_on")}});country.hoverIntent({sensitivity:3,interval:200,over:function(){country.PopupWindow.show("fast");country.addClass("country_on")},timeout:300,out:function(){country.PopupWindow.hide("fast");country.removeClass("country_on")}});infoPanel.Rating.children().not(":radio").hide();infoPanel.Rating.stars({callback:function(a,d,c){var b=currentSearchIndex;ratingMouseOut();infoPanel.Rating.unbind("mouseover",ratingMouseOver);infoPanel.Rating.unbind("mouseout",ratingMouseOut);$.getJSON("/Rating/Rate/?nocache="+(new Date()).getTime(),{photoSubmissionID:infoPanel.PhotoSubmissionID,rating:c},function(f,e){updateRating(b,f)});infoPanel.RatingLabel.fadeTo("fast",0,function(){infoPanel.RatingLabel.text("THANKS FOR RATING").fadeTo("slow",1,function(){setTimeout(function(){infoPanel.RatingLabel.fadeTo("slow",0)},800)})});infoPanel.Rating.stars("select").data("stars").disable()}});$(".ui-stars-star","#ratings").show();omniture=new OmnitureProto("Ajax")});function ratingMouseOver(){$("#ratingsTitle,#ratingsLabel").css("color","#EEC229");$("#ratingsTitle").text("YOUR RATING")}function ratingMouseOut(){$("#ratingsTitle,#ratingsLabel").css("color","#ffffff");$("#ratingsTitle").text("AVG. RATING")}function updateRating(a,b){photoSubmission=cachedMosaicTiles[searchMosaicIDs[a]];photoSubmission.AverageRating=b;photoSubmission.Rating=b;photoSubmission.canRate=false;if(a==currentSearchIndex){infoPanel.Rating.stars("select",Math.round(b))}}function setInfoPanelToggleImage(){if(slideshowState=="stop"){$("img","#infoPanelToggle").attr("src","/Content/images/pic-play.png")}else{$("img","#infoPanelToggle").attr("src","/Content/images/pic-stop.png")}}function setupReferences(){$("#mosaic").mousedown(function(){searchMosaicIDs=[];cachedMosaicTiles=[];hideSearchResults()});favoriteShoe=$("#fav_shoe");favoriteShoe.PopupWindow=$("#shoe_selector");favoriteShoe.PopupWindow.css("left",favoriteShoe.position().left);favoriteShoe.PopupWindow.css("bottom",favoriteShoe.outerHeight(true));$("#shoes_scrollable").click(function(){favoriteShoe.removeClass("fav_shoe_on");favoriteShoe.PopupWindow.hide("fast")});country=$("#country");country.PopupWindow=$("#country_selector");country.PopupWindow.css("left",country.position().left);country.PopupWindow.css("bottom",country.outerHeight(true));$("#country_scrollable").click(function(){country.removeClass("country_on");country.PopupWindow.hide("fast")});ratingSelect=$("#rating_drop");ratingSelect.PopupWindow=$("#rating_selector");ratingSelect.PopupWindow.css("left",ratingSelect.position().left);ratingSelect.PopupWindow.css("bottom",ratingSelect.outerHeight(true));ratingSelect.PopupWindow.click(function(){ratingSelect.removeClass("rating_on");ratingSelect.PopupWindow.hide("fast")});infoPanel=$("#img_info");infoPanel.Code=$("#SubmissionCode",infoPanel);infoPanel.Name=$("#SubmissionName",infoPanel);infoPanel.City=$("#SubmissionCity",infoPanel);infoPanel.Country=$("#SubmissionCountry",infoPanel);infoPanel.FavoriteShoe=$("#SubmissionFavoriteShoe",infoPanel);infoPanel.Image=$("#SubmissionImage",infoPanel);infoPanel.Rating=$("#ratings");infoPanel.RatingLabel=$("#ratingsLabel");$("#infoPanelHide").click(hideSearchResults);$("#infoPanelBack").click(function(){slideshow("back");cancelPendingSlide();slideshowState="stop";setInfoPanelToggleImage()});$("#infoPanelToggle").click(function(){slideshow()});$("#infoPanelToggle").click(function(){setInfoPanelToggleImage()});$("#infoPanelForward").click(function(){nextSlideClick();cancelPendingSlide();slideshowState="stop";setInfoPanelToggleImage()});searchPanel=$("#SearchPanel");searchPanel.Index=$("#SearchIndex",searchPanel);searchPanel.Count=$("#SearchCount",searchPanel);lastSearchTerm=$("#lastSearchTerm");noPhotosFound=$("#noPhotosFound");textField=$("#textfield");textField.keypress(function(a){if(a.which==13){generalSearch();return false}});zoomLevelPanel=$("#zoom_level")}function initSeadragon(){viewer=new Seadragon.Viewer("mosaic");viewer.setDashboardEnabled(false);zoomLevelPanel.remove();viewer.addControl(zoomLevelPanel[0],Seadragon.ControlAnchor.TOP_RIGHT);viewer.addEventListener("open",function(){Seadragon.Config.maxZoomPixelRatio=2;Seadragon.Config.minZoomImageRatio=1;Seadragon.Config.imageLoaderLimit=11;Seadragon.Config.animationTime=2;Seadragon.Config.blendTime=0.25;homeZoom=viewer.viewport.getZoom();OnAnimation()});viewer.addEventListener("animationstart",OnAnimationStart);viewer.addEventListener("animationfinish",OnAnimationFinish);Seadragon.Config.autoHideControls=false;Seadragon.userMouseCallback=function(){hideSearchResults();searchMosaicIDs=null};Seadragon.userClickZoom=function(){hideSearchResults();omniture.logZoomIn("click")};Seadragon.userMouseWheelZoom=function(a){if(a){omniture.logZoomIn("scroll")}else{omniture.logZoomOut("scroll");var b=viewer.viewport.getZoom()/viewer.viewport.getNativeSizeZoom();if(searchMosaicIDs!=null||b<0.5&&!infoPanel.is(":hidden")){hideSearchResults()}}};viewer.openDzi(dziSource,dziContents)}function ratingsLabelClick(a){if(infoPanel.RatingLabel.canRate){infoPanel.RatingLabel.fadeTo("fast",0,function(){infoPanel.RatingLabel.text("SELECT RATE ABOVE").fadeIn("fast");infoPanel.RatingLabel.canRate=false;infoPanel.Rating.stars("select").data("stars").disable()})}}function logSearch(a,c,b){omniture.logSearch(lastSearchType,c,b)}function shoeSearch(c,a){textField.val("");var b=c+" "+a;lastSearchTerm.text(b);lastSearchType="Favorite Shoe";$.getJSON("/Search/SearchByShoe/?nocache="+(new Date()).getTime(),{shoeID:c,mosaicID:mosaicID},searchCompleted)}function countrySearch(a,b){textField.val("");lastSearchTerm.text(b);lastSearchType="Country";$.getJSON("/Search/SearchByCountry/?nocache="+(new Date()).getTime(),{countryID:a,mosaicID:mosaicID},searchCompleted)}function ratingSearch(a){textField.val("");lastSearchTerm.text("");lastSearchType="Top Rated";$.getJSON("/Search/SearchByRating/?nocache="+(new Date()).getTime(),{rating:a,mosaicID:mosaicID},searchCompleted)}function generalSearch(){var a=textField.val();lastSearchTerm.text(a);lastSearchType="Keyword";$.getJSON("/Search/search/?nocache="+(new Date()).getTime(),{q:a,mosaicID:mosaicID},searchCompleted)}function showNoPhotosFound(){noPhotosFound.fadeOut("slow");if(!!noPhotosFoundHandle){clearInterval(noPhotosFoundHandle);noPhotosFoundHandle=null}}function searchCompleted(a){logSearch(lastSearchType,lastSearchTerm.text(),a.length);if(a.length==0){hideSearchResults();noPhotosFound.fadeIn();noPhotosFoundHandle=setTimeout("showNoPhotosFound()",3500);if(lastSearchType=="Keyword"){textField.focus()[0].select()}currentSearchIndex=-1;cachedMosaicTiles=[];searchPanel.hide();searchMosaicIDs=null;cancelPendingSlide();slideshowState="stop";return}currentSearchIndex=-1;cachedMosaicTiles=[];searchMosaicIDs=a;searchPanel.Count.text(a.length);searchPanel.show("normal",function(){slideshow("forward")})}function cancelPendingSlide(){if(slideshowTimeoutHandle!=null){clearTimeout(slideshowTimeoutHandle);slideshowTimeoutHandle=null}}function slideshow(a){cancelPendingSlide();if(arguments.length==0){if(slideshowState=="stop"){a="forward"}else{a="stop"}}slideshowState=a;setInfoPanelToggleImage();if(a!="stop"){nextSlide()}else{cancelPendingSlide()}}function searchExpandCompleted(a,b){if(searchMosaicIDs==null||searchMosaicIDs.length<=a){return}cachedMosaicTiles[searchMosaicIDs[a]]=b;document.getElementById("SearchIndex").innerHTML=a+1;searchPanel.Index.text(a+1);showTile(b)}function showTile(c){c.Rating=c.AverageRating;omniture.logPhotoViewed(c);var b=(c.canRate==undefined||c.canRate==null?true:!!c.canRate);infoPanel.Code.text(c.Code);infoPanel.Name.text(c.Name);infoPanel.City.text(c.City);infoPanel.Country.text(c.Country);infoPanel.FavoriteShoe.text(c.FavoriteShoe);if(!!c.ShoeImageUri){infoPanel.Image.attr("src",c.ShoeImageUri);$(infoPanel.Image).css("display","block")}else{$(infoPanel.Image).css("display","none")}infoPanel.PhotoSubmissionID=c.PhotoSubmissionID;infoPanel.Rating.stars("select",Math.round(c.AverageRating));infoPanel.RatingLabel.show();infoPanel.RatingLabel.canRate=b;infoPanel.RatingLabel.text("RATE THIS");infoPanel.RatingLabel.fadeTo("fast",b?1:0);if(b){infoPanel.Rating.stars("select").data("stars").enable();infoPanel.Rating.hover(ratingMouseOver,ratingMouseOut)}else{infoPanel.Rating.stars("select").data("stars").disable()}if(infoPanel.is(":hidden")){infoPanel.fadeIn()}setInfoPanelToggleImage();zoomToTile(viewer,c.X-triangleOffset,c.Y,c.Width,c.Height);var a=parseInt(searchPanel.Count.text());if(slideshowState!="stop"&&!!a&&a>1){slideshowTimeoutHandle=setTimeout("nextSlide()",slideshowInterval)}}function nextSlide(){cancelPendingSlide();if(slideshowState=="forward"){goForward()}else{if(slideshowState=="back"){goBack()}}}function goForward(){if(searchMosaicIDs==null){return}currentSearchIndex++;if(currentSearchIndex>=searchMosaicIDs.length||currentSearchIndex<0){currentSearchIndex=0}expandSearchResult(currentSearchIndex)}function goBack(){if(searchMosaicIDs==null){return}currentSearchIndex--;if(currentSearchIndex<0||currentSearchIndex>=searchMosaicIDs.length){currentSearchIndex=searchMosaicIDs.length-1}expandSearchResult(currentSearchIndex)}function expandSearchResult(a){if(typeof cachedMosaicTiles[searchMosaicIDs[a]]=="undefined"){$.getJSON("/Search/ExpandSearchResult/"+searchMosaicIDs[a]+"/?nocache="+(new Date()).getTime(),function(b){searchExpandCompleted(a,b)})}else{searchExpandCompleted(a,cachedMosaicTiles[searchMosaicIDs[a]])}}function hideSearchResults(){infoPanel.fadeOut();slideshow("stop")}function OnAnimation(b){var c=viewer.viewport;var a=Math.round(1/c.getBounds(true).width*100);document.getElementById("zoom_percent").innerHTML=a+"%";if(infoPanel.is(":visible")&&viewer.viewport.getZoom()<35.3460972017673){hideSearchResults()}}function OnAnimationStart(a){}function OnAnimationFinish(a){animationFinish_Omniture();var d=viewer.viewport;if(!!homeZoom&&d.getZoom()<=homeZoom){d.goHome()}var c=viewer.viewport.getZoom();if(!!searchMosaicIDs&&searchMosaicIDs.length>0||c<48.7715500019977){return}var b=getPixelCoordinatesAtArrow();$.getJSON("/Search/SearchByCoordinates/?nocache="+(new Date()).getTime(),{mosaicID:mosaicID,x:Math.round(b.x),y:Math.round(b.y)},function(g){var f=Math.abs(b.x-(g.X+g.Width));var e=Math.abs(b.y-(g.Y+g.Height/2));if(f<3&&e<3){return}currentSearchIndex=0;searchMosaicIDs=[0];cachedMosaicTiles=[g];searchPanel.hide();slideshow("stop");showTile(g)})}function animationFinish_Omniture(){omniture.logFirstInteraction()}function getPixelCoordinatesAtArrow(){var e=viewer.source.getPixelRatio(viewer.source.maxLevel);var b=viewer.viewport.getContainerSize();var g=$("#img_info");var f=viewer.elmt;var h=g.is(":hidden");if(h){g.show()}var c=(Seadragon.Utils.getElementPosition(f).x+Seadragon.Utils.getElementSize(f).x)-g.offset().left;if(h){g.hide()}var a=new Seadragon.Point(b.x-c,b.y/2);var d=viewer.viewport.pointFromPixel(a,true);return new Seadragon.Point(d.x/e.x,y=d.y/e.x)}function nextSlideClick(){omniture.logSearchNextResult(lastSearchType);slideshow("forward")}function selectionFix(){if($.browser.mozilla){$("html").css("MozUserSelect","-moz-none");$("input").css("MozUserSelect","text")}else{if($.browser.msie){$("html").bind("selectstart",function(a){if($(a.target).is(":input")){return true}else{return false}})}}};