(function($){function log(){if(window.console&&window.console.log){window.console.log(Array.prototype.join.call(arguments,""));
}}PhotoGalleryType={ALL:0,EXTERIOR:1,INTERIOR:2,PHOTOS:3};$.fn.photogallery=function(options){var defaults={Exterior:[],Interior:[],Photos:[],Type:PhotoGalleryType.ALL,HashId:"123456789",ThumbsNumber:4,ThumbsJump:false,DotsJump:false,classControlsContainer:"controlsContainer",classControls:"slideshowControls",classFwd:"btnforward",classRew:"btnrewind",classPlay:"btnplay",classFwdDisabled:"btnforwardDisabled",classRewDisabled:"btnrewindDisabled",classPause:"btnpause",classDotsJump:"dotImageGalleryJump",classDotsJumpDisabled:"dotImageGalleryJumpDisabled",classThumbFwd:"btnSkipForward",classThumbRew:"btnSkipRewind",classThumbFwdDisabled:"btnSkipForwardDisabled",classThumbRewDisabled:"btnSkipRewindDisabled",classTxtNotActual:"txtNotActual",classImageTypeSelection:"imageTypeSelection",classCurrentImage:"currentImage",classImageMain:"imageMain",classThumbsContainer:"thumbsContainer",classThumbImageSelected:"thumbImageSelected",classTypeSelected:"typeSelected",classTypeLink:"typeLink",classPLSlideShowControls:"pLSlideShowControls",link360:"",linkVideo:"",linkOverviewPricing:"",classLinks:"mainhublinks",aboutUsDivId:"",showLinks:true,showTopLinks:false,showNumberOf:true,showHubLinks:true,showNotActualText:false,showControls:true,showImageControls:false,showThumbs:true,timer:null,playslideshow:false,playtimeout:3000,doAdOmnitureUpdate:true,imageCount:0,pagename:s_pageName,currentIndex:0,startIndex:0,triggerElementId:"",AdRefreshRate:0,isShowcase:false,callPNGfix:false,showPlayButton:false,refreshOnLinks:false,refreshOnPlay:false,LogWebEventPlay:"",LogWebEventScroll:"",LogWebSubEventSubPlayAll:"",LogWebEventThumb:"",LogWebSubEventThumb:""};
var opts=$.extend(defaults,options);if(opts.Exterior==null){opts.Exterior=[];}if(opts.Interior==null){opts.Interior=[];
}if(opts.Photos==null){opts.Photos=[];}return this.each(function(){init($(this),opts);
});};function setPhotos(opts){if(opts.Type==PhotoGalleryType.ALL){if(opts.Interior.length>0&&opts.Exterior.length>0){opts.Photos=opts.Exterior.slice(0).concat(opts.Interior);
}else{if(opts.Interior.length<=0&&opts.Exterior.length>0){opts.Photos=opts.Exterior.slice(0);
}else{if(opts.Interior.length>0&&opts.Exterior.length<=0){opts.Photos=opts.Interior.slice(0);
}}}}if(opts.Type==PhotoGalleryType.EXTERIOR){if(opts.Exterior.length>0){opts.Photos=opts.Exterior.slice(0);
}}if(opts.Type==PhotoGalleryType.INTERIOR){if(opts.Interior.length>0){opts.Photos=opts.Interior.slice(0);
}}}function triggerEvent(opts){if(opts.triggerElementId!=""&&opts.triggerElementId!=null){$("#"+opts.triggerElementId).click();
}}function resetControls(opts){if(((opts.Photos.length>1)||((opts.Exterior.length+opts.Interior.length)>1))&&(opts.showControls==true)){$("#mainControls"+opts.HashId).html('<div id="controls'+opts.HashId+'" class="'+opts.classControls+'"><a id="rew'+opts.HashId+'" class="'+opts.classRewDisabled+'" href="javascript:void(0);"><span> </span></a><a id="playpause'+opts.HashId+'" class="'+opts.classPlay+'" href="javascript:void(0);"><span> </span></a><a id="fwd'+opts.HashId+'" class="'+opts.classFwd+'" href="javascript:void(0);"><span> </span></a></div>');
setplaypause(opts);}}function preloader(opts){if(opts.Photos.length>0){var imgbox=document.createElement("div");
$(imgbox).css({display:"none"});$("body").append(imgbox);$.each(opts.Photos,function(ind,item){var img=document.createElement("img");
$(img).attr("src",item.Url);$(imgbox).append(img);var imgt=document.createElement("img");
$(imgt).attr("src",item.ThumbUrl);$(imgbox).append(imgt);});}}function init(othis,opts){opts.container=this;
setPhotos(opts);if(opts.showTopLinks==true){ShowINTEXTLinks(opts,othis,"imageTypesTop","typeExteriorTop","typeInteriorTop","typeAllTop",true);
}if(opts.Photos.length>0){othis.append('<div class="mainImageContainer" id="mainImageContainer'+opts.HashId+'"></div>');
if(opts.showImageControls&&opts.Photos.length>1){$("#mainImageContainer"+opts.HashId).append("<div class='btnPrevContainer'><a id='imageBtnPrev"+opts.HashId+"' class='"+opts.classRewDisabled+"' href='javascript:void(0);'><span></span></a></div");
}if(opts.isShowcase){if(opts.showPlayButton==true){$("#mainImageContainer"+opts.HashId).append('<div id="showcaseBanner"><span>SHOWCASE DEALER</span></div><div class="mainImageContainerInner" id="mainImageContainerInner'+opts.HashId+'"><div class="showcaseBannerSlice"></div></div>');
$("#mainImageContainerInner"+opts.HashId).append('<div id="mainImageWithButton"><img id="mainImage'+opts.HashId+'"/><div id="mainButton'+opts.HashId+'" class="mainButton play" style="display: none"><div class="play"></div><div class="pause"></div></div></div>');
if(opts.playslideshow){$("#mainButton"+opts.HashId+" .play").hide();$("#mainButton"+opts.HashId+" .pause").hide();
}}else{$("#mainImageContainer"+opts.HashId).append('<div id="showcaseBanner"><span>SHOWCASE DEALER</span></div><div class="mainImageContainerInner" id="mainImageContainerInner'+opts.HashId+'"><div class="showcaseBannerSlice"></div></div>');
$("#mainImageContainerInner"+opts.HashId).append('<img id="mainImage'+opts.HashId+'"/>');
}}else{if(opts.showPlayButton==true){$("#mainImageContainer"+opts.HashId).append('<div id="mainImageWithButton"><img id="mainImage'+opts.HashId+'"/><div id="mainButton'+opts.HashId+'" class="mainButton play" style="display: none"><div class="play"></div><div class="pause"></div></div></div>');
if(opts.playslideshow){$("#mainButton"+opts.HashId+" .play").hide();$("#mainButton"+opts.HashId+" .pause").hide();
}}else{$("#mainImageContainer"+opts.HashId).append('<img id="mainImage'+opts.HashId+'"/>');
}}ShowMainImage(opts,0,0);if(opts.showImageControls&&opts.Photos.length>1){$("#mainImageContainer"+opts.HashId).append("<div class='btnNextContainer'><a id='imageBtnNext"+opts.HashId+"' class='"+opts.classFwdDisabled+"' href='javascript:void(0);'><span></span></a></div");
}}if(opts.showNotActualText){othis.append('<br><span id="txtNotActual'+opts.HashId+'" class="'+opts.classTxtNotActual+'">Not Actual Vehicle Photo</span>');
}if(opts.aboutUsDivId!=""){othis.append($("#"+opts.aboutUsDivId).html());}othis.append("<br/>");
if(opts.Photos.length>0){$("#mainImage"+opts.HashId).addClass(opts.classImageMain).attr("meta:selectid",0).attr("meta:index",0);
}othis.append('<div id="mainControls'+opts.HashId+'" class="'+opts.classControlsContainer+'"></div');
if(((opts.Photos.length>1)||(opts.Type!=PhotoGalleryType.PHOTOS&&(opts.Exterior.length+opts.Interior.length)>1))&&(opts.showControls==true)){$("#mainControls"+opts.HashId).html('<div id="controls'+opts.HashId+'" class="'+opts.classControls+'"><a id="rew'+opts.HashId+'" class="'+opts.classRewDisabled+'" href="javascript:void(0);"><span> </span></a><a id="playpause'+opts.HashId+'" class="'+opts.classPlay+'" href="javascript:void(0);"><span> </span></a><a id="fwd'+opts.HashId+'" class="'+opts.classFwd+'" href="javascript:void(0);"><span> </span></a></div>');
}if(opts.showLinks==true){ShowINTEXTLinks(opts,othis,"imageTypes","typeExterior","typeInterior","typeAll",false);
}if(opts.showImageControls&&opts.Photos.length<=1){opts.showNumberOf=false;}if(opts.showNumberOf){othis.append('<div class="'+opts.classCurrentImage+'"><span id="lblCurrentImage'+opts.HashId+'" class="body_01"></span></div>');
}if(opts.playslideshow){start(opts);$("#mainButton"+opts.HashId).removeClass("pause").addClass("play").hide();
$("#mainButton"+opts.HashId+" .play").hide();$("#mainButton"+opts.HashId+" .pause").show();
}if(opts.showThumbs){if(opts.Photos.length>0){othis.append("");othis.append('<div class="'+opts.classThumbsContainer+'Header" ><div class="left"></div><div class="middle"></div><div class="right"></div></div><div id="thumbImages'+opts.HashId+'" class="'+opts.classThumbsContainer+'"></div><div class="'+opts.classThumbsContainer+'Footer" ><div class="left"></div><div class="middle"></div><div class="right"></div></div>');
var oothis=$("#thumbImages"+opts.HashId);$(oothis).html("");InitThumbs(opts);}}if(opts.showHubLinks){var olnkOverviewPricing="";
var olnkVideo="";var olnk360="";var cssVideoDisabled="";var cssOverviewPricingDisabled="";
var css360Disabled="";if(opts.linkVideo==""){olnkVideo=' disabled="disabled" ';cssVideoDisabled=" disabled";
}else{olnkVideo=' href="'+opts.linkVideo+'"';}if(opts.linkOverviewPricing==""){olnkOverviewPricing=' disabled="disabled" ';
cssOverviewPricingDisabled=" disabled";}else{olnkOverviewPricing=' href="'+opts.linkOverviewPricing+'"';
}if(opts.link360==""){olnk360=' disabled="disabled" ';css360Disabled=" disabled";
}else{olnk360=' href="'+opts.link360+'"';}othis.append('<div class="'+opts.classLinks+'" id="links'+opts.HashId+'"><a '+olnk360+' class="link_circle_arrow_blue fL ml15'+css360Disabled+'" id="lnk360View'+opts.HashId+'">360&deg; View</a><a '+olnkVideo+' class="link_circle_arrow_blue fL ml15'+cssVideoDisabled+'" id="lnkVideo'+opts.HashId+'">Video</a><a '+olnkOverviewPricing+' class="link_circle_arrow_blue fL ml5'+cssOverviewPricingDisabled+'" id="lnkOverviewAndPricing'+opts.HashId+'">Overview & Pricing</a></div>');
}setplaypause(opts);if(opts.startIndex>0&&opts.Type==PhotoGalleryType.ALL&&opts.Photos.length>opts.startIndex){$("#mainImage"+opts.HashId).addClass(opts.classImageMain).attr("src",opts.Photos[opts.startIndex].Url).attr("meta:selectid",opts.startIndex).attr("meta:index",opts.startIndex);
if(opts.Photos[opts.startIndex].AlternateTxt){$("#mainImage"+opts.HashId).attr("alt",opts.Photos[opts.startIndex].AlternateTxt);
}$("#thumbImage"+opts.HashId+"_0").removeClass(opts.classThumbImageSelected);$("#thumbImage"+opts.HashId+"_"+opts.startIndex).addClass(opts.classThumbImageSelected);
setControls(opts.startIndex,opts.startIndex,opts);}else{setControls(0,0,opts);}preloader(opts);
if(opts.Photos.length<=0){$("#photoSlideShow").hide();}}function ShowMainImage(opts,idx,sid){$("#mainImage"+opts.HashId).attr("src",opts.Photos[sid].Url).attr("meta:index",idx).attr("meta:selectid",sid);
if(opts.Photos[sid].AlternateTxt){$("#mainImage"+opts.HashId).attr("alt",opts.Photos[sid].AlternateTxt);
}}function InitThumbs(opts){var oothis=$("#thumbImages"+opts.HashId);$(oothis).html("");
ShowPrevJump(opts,oothis);if(opts.Type==PhotoGalleryType.PHOTOS){for(i=0;i<opts.Photos.length;
i++){AddImage(opts,oothis,i,i);if(((i+1)%(opts.ThumbsNumber))==0){oothis.append("<br/>");
}}}else{for(i=0;i<opts.ThumbsNumber;i++){if(i<opts.Photos.length){AddImage(opts,oothis,i,i);
}}}ShowNextJump(opts,oothis);ShowDotsJump(opts,oothis);}function ShowINTEXTLinks(opts,othis,imageTypes,typeExterior,typeInterior,typeAll,isTop){var exteriorDisabled=' disabled="disabled"';
var interiorDisabled=' disabled="disabled"';var allDisabled=' disabled="disabled"';
if(opts.Exterior.length>0){exteriorDisabled="";}if(opts.Interior.length>0){interiorDisabled="";
}if(opts.Exterior.length>0&&opts.Interior.length>0){allDisabled="";}if(isTop){classImageTypeSelection="imageTypeSelection noborder";
}else{classImageTypeSelection=opts.classImageTypeSelection;}othis.append('<div id="'+imageTypes+opts.HashId+'" class="'+classImageTypeSelection+'"><a class="'+opts.classTypeLink+" "+opts.classTypeSelected+'" href="javascript:void(0);" id="'+typeExterior+opts.HashId+'" '+exteriorDisabled+'>Exterior</a><span class="body_01"> | </span><a class="'+opts.classTypeLink+'" href="javascript:void(0);" id="'+typeInterior+opts.HashId+'" '+interiorDisabled+'>Interior</a><span class="body_01"> | </span><a class="'+opts.classTypeLink+'" href="javascript:void(0);" id="'+typeAll+opts.HashId+'" '+allDisabled+">All</a></div>");
if(opts.showTopLinks&&isTop){$("#imageTypesTop"+opts.HashId+" ."+opts.classTypeLink).bind("click",function(){$("#imageTypes"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
$("#imageTypesTop"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
return false;});}$("#imageTypes"+opts.HashId+" ."+opts.classTypeLink).bind("click",function(){$("#imageTypes"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#imageTypesTop"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
}return false;});if(opts.Exterior.length>0){if(opts.refreshOnLinks){var url=replaceQueryString(location.href,"MediaView","Exterior");
url=url.replace(/&PlaySlideShow=true/i,"");url=replaceQueryString(url,"StartIndex","");
$("#"+typeExterior+opts.HashId).unbind("click").attr("href",url);}else{$("#"+typeExterior+opts.HashId).bind("click",function(){$("#typeExterior"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeExteriorTop"+opts.HashId).addClass(opts.classTypeSelected);
}opts.currentIndex=0;opts.Type=PhotoGalleryType.EXTERIOR;setPhotos(opts);resetControls(opts);
ShowSelectedImages(opts);return false;});}}else{$("#"+typeExterior+opts.HashId).addClass("typeDisabled").unbind("click");
}if(opts.Interior.length>0){if(opts.refreshOnLinks){var url=replaceQueryString(location.href,"MediaView","Interior");
url=url.replace(/&PlaySlideShow=true/i,"");url=replaceQueryString(url,"StartIndex","");
$("#"+typeInterior+opts.HashId).unbind("click").attr("href",url);}else{$("#"+typeInterior+opts.HashId).bind("click",function(){$("#typeInterior"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeInteriorTop"+opts.HashId).addClass(opts.classTypeSelected);
}opts.currentIndex=0;opts.Type=PhotoGalleryType.INTERIOR;setPhotos(opts);resetControls(opts);
ShowSelectedImages(opts);return false;});}}else{$("#"+typeInterior+opts.HashId).addClass("typeDisabled").unbind("click");
}if(allDisabled.length<=0){if(opts.refreshOnLinks){var url=replaceQueryString(location.href,"MediaView","All");
url=url.replace(/&PlaySlideShow=true/i,"");url=replaceQueryString(url,"StartIndex","");
$("#"+typeAll+opts.HashId).unbind("click").attr("href",url);}else{$("#"+typeAll+opts.HashId).bind("click",function(){$("#typeAll"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeAllTop"+opts.HashId).addClass(opts.classTypeSelected);
}opts.currentIndex=0;opts.Type=PhotoGalleryType.ALL;setPhotos(opts);resetControls(opts);
opts.currentIndex=0;ShowSelectedImages(opts);return false;});}}else{$("#"+typeAll+opts.HashId).addClass("typeDisabled").unbind("click");
}$("#typeAll"+opts.HashId).removeClass(opts.classTypeSelected);$("#typeExterior"+opts.HashId).removeClass(opts.classTypeSelected);
$("#typeInterior"+opts.HashId).removeClass(opts.classTypeSelected);if(opts.showTopLinks){$("#typeAllTop"+opts.HashId).removeClass(opts.classTypeSelected);
$("#typeExteriorTop"+opts.HashId).removeClass(opts.classTypeSelected);$("#typeInteriorTop"+opts.HashId).removeClass(opts.classTypeSelected);
}switch(opts.Type){case (PhotoGalleryType.ALL):$("#typeAll"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeAllTop"+opts.HashId).addClass(opts.classTypeSelected);
}break;case (PhotoGalleryType.EXTERIOR):$("#typeExterior"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeExteriorTop"+opts.HashId).addClass(opts.classTypeSelected);
}break;case (PhotoGalleryType.INTERIOR):$("#typeInterior"+opts.HashId).addClass(opts.classTypeSelected);
if(opts.showTopLinks){$("#typeInteriorTop"+opts.HashId).addClass(opts.classTypeSelected);
}break;}}function ShowDotsJump(opts,oothis){if(opts.DotsJump){var numDots=parseInt((opts.Photos.length-1)/opts.ThumbsNumber)+1;
if(numDots>1){oothis.append("<hr>");for(i=0;i<numDots;i++){var pos=(opts.ThumbsNumber*i)-1;
var className=((pos==-1&&opts.currentIndex==0)||pos==opts.currentIndex)?opts.classDotsJumpDisabled:opts.classDotsJump;
oothis.append('<div id="dotsJump" class="'+opts.classPLSlideShowControls+'"><a class="'+className+'" href="javascript:void(0);" id="dotJump'+i+"_"+opts.HashId+'" x:pg="'+i+'">&nbsp;&nbsp;&nbsp;</a></div>');
$("#dotJump"+i+"_"+opts.HashId).bind("click",function(){stop(opts);pageJump(opts,$(this).attr("x:pg"));
return false;});}}}}function ShowNextJump(opts,oothis){if(opts.ThumbsJump){oothis.append('<div id="btnThumbFwd" class="'+opts.classPLSlideShowControls+'"><a class="'+opts.classThumbFwd+'" href="javascript:void(0);" id="btnThumbForward'+opts.HashId+'"><span></span></a></div>');
$("#btnThumbForward"+opts.HashId).bind("click",function(){stop(opts);nextJump(opts);
return false;});}}function ShowPrevJump(opts,oothis){if(opts.ThumbsJump){oothis.append('<div id="btnThumbRwd" class="'+opts.classPLSlideShowControls+'"><a class="'+opts.classThumbRew+'" href="javascript:void(0);" id="btnThumbRewind'+opts.HashId+'"><span></span></a></div>');
$("#btnThumbRewind"+opts.HashId).bind("click",function(){stop(opts);prevJump(opts);
return false;});}}function AddImage(opts,oothis,i,nextid){var imgId="thumbImage"+opts.HashId+"_"+i;
oothis.append('<img id="'+imgId+'" src="'+opts.Photos[nextid].ThumbUrl+'"/>');$("#"+imgId).addClass("thumbImage");
$("#"+imgId).css({opacity:0.2});var posx=opts.currentIndex%opts.ThumbsNumber;if((opts.Type==PhotoGalleryType.PHOTOS)&&(i==opts.currentIndex)){$("#"+imgId).addClass(opts.classThumbImageSelected);
$("#mainImage"+opts.HashId).attr("meta:index",i).attr("meta:selectid",nextid);}else{if((i==posx)&&(opts.Type!=PhotoGalleryType.PHOTOS)){$("#"+imgId).addClass(opts.classThumbImageSelected);
$("#mainImage"+opts.HashId).attr("meta:index",i).attr("meta:selectid",nextid);}}if(opts.Photos[nextid].AlternateTxt){$("#"+imgId).attr("alt",opts.Photos[nextid].AlternateTxt);
}if(opts.Photos[nextid].OnClientClick!=null){$("#"+imgId).attr("meta:index",i).attr("meta:selectid",nextid).attr("meta:type",opts.Photos[nextid].Type).bind("click",function(){if(opts.LogWebEventThumb!=""){logwebEvent(opts.LogWebEventThumb,opts.LogWebSubEventThumb);
}ShowSelectedImage($(this),opts);LogImageClick(opts.Photos[nextid].OnClientClick);
return false;});}else{$("#"+imgId).attr("meta:index",i).attr("meta:selectid",nextid).attr("meta:type",opts.Photos[nextid].Type).bind("click",function(){if(opts.LogWebEventThumb!=""){logwebEvent(opts.LogWebEventThumb,opts.LogWebSubEventThumb);
}ShowSelectedImage($(this),opts);return false;});}$("#"+imgId).animate({opacity:1},1000);
}function LogImageClick(method){eval(method);}function ShowSelectedImages(opts){var oothis=$("#thumbImages"+opts.HashId);
if((oothis!=undefined)&&(opts.Photos!=undefined)){$(oothis).html("");ShowPrevJump(opts,oothis);
if(opts.Type==PhotoGalleryType.PHOTOS){for(i=0;i<opts.Photos.length;i++){AddImage(opts,oothis,i,i);
if(((i+1)%(opts.ThumbsNumber))==0){oothis.append("<br/>");}}}else{for(i=0;i<opts.ThumbsNumber;
i++){if(i<opts.Photos.length){AddImage(opts,oothis,i,i);}}}ShowNextJump(opts,oothis);
ShowDotsJump(opts,oothis);ShowMainImage(opts,0,0);setControls(0,0,opts);updateADsAndOmniture(opts);
triggerEvent(opts);setplayhref(opts);}}function pageJump(opts,page){var pos=(opts.ThumbsNumber*page)-1;
opts.currentIndex=pos;next(opts,pos,0);}function nextJump(opts){var pos=parseInt(opts.currentIndex/opts.ThumbsNumber)*opts.ThumbsNumber;
pos=pos+opts.ThumbsNumber-1;opts.currentIndex=pos;next(opts,pos,0);}function prevJump(opts){var pos=parseInt(opts.currentIndex/opts.ThumbsNumber)*opts.ThumbsNumber;
opts.currentIndex=pos-opts.ThumbsNumber;prev(opts,pos,opts.ThumbsNumber-1);ShowSelectedImage($("#thumbImage"+opts.HashId+"_0"),opts);
}function ShowSelectedImage(obj,opts){var oothiss=$("#mainImage"+opts.HashId);if((oothiss!=undefined)&&(opts.Photos!=undefined)){var sid=$(obj).attr("meta:selectid");
var idx=$(obj).attr("meta:index");if(sid<opts.Photos.length){ShowMainImage(opts,idx,sid);
if(!opts.Type==PhotoGalleryType.ALL){if(opts.Photos[sid].Type==PhotoGalleryType.EXTERIOR){$("#imageTypes"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
$("#typeExterior"+opts.HashId).addClass(opts.classTypeSelected);if(opts.showTopLinks){$("#imageTypesTop"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
$("#typeExteriorTop"+opts.HashId).addClass(opts.classTypeSelected);}}else{if(opts.Photos[sid].Type==PhotoGalleryType.INTERIOR){$("#imageTypes"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
$("#typeInterior"+opts.HashId).addClass(opts.classTypeSelected);if(opts.showTopLinks){$("#imageTypesTop"+opts.HashId+" ."+opts.classTypeLink).removeClass(opts.classTypeSelected);
$("#typeInteriorTop"+opts.HashId).addClass(opts.classTypeSelected);}}}}setControls(sid,idx,opts);
updateADsAndOmniture(opts);$("#thumbImages"+opts.HashId+" ."+opts.classThumbImageSelected).removeClass(opts.classThumbImageSelected);
$(obj).addClass(opts.classThumbImageSelected);triggerEvent(opts);setplayhref(opts);
}}}function setplayhref(opts){if(opts.refreshOnPlay&&opts.playslideshow==false&&opts.Type!=PhotoGalleryType.ALL){var url=replaceQueryString(location.href,"MediaView","All");
url=replaceQueryString(url,"PlaySlideShow","true");var pix=$("#mainImage"+opts.HashId).attr("meta:selectid");
var id=parseInt(pix);if(opts.Type==PhotoGalleryType.INTERIOR&&opts.Exterior.length>0){id=id+opts.Exterior.length;
}url=replaceQueryString(url,"StartIndex",id);$("#playpause"+opts.HashId).unbind("click").attr("href",url);
$("#mainButton"+opts.HashId).unbind("click").bind("click",function(){location.href=url;
return false;});}}function setplaypause(opts){if(opts.refreshOnPlay&&opts.playslideshow==false&&opts.Type!=PhotoGalleryType.ALL){setplayhref(opts);
}else{$("#playpause"+opts.HashId).unbind("click").bind("click",function(){PhotoGallerySlideShow(opts);
if(opts.playslideshow==true&&opts.LogWebEventPlay!=""){logwebEvent(opts.LogWebEventPlay,"NA");
}return false;});if(opts.showPlayButton==true){$("#mainButton"+opts.HashId).unbind("click").bind("click",function(){PhotoGallerySlideShow(opts);
if(opts.playslideshow==true&&opts.LogWebEventPlay!=""){logwebEvent(opts.LogWebEventPlay,opts.LogWebSubEventSubPlayAll);
}return false;});}}}function setControls(currentIndex,index,opts){opts.currentIndex=parseInt(currentIndex,10);
var nopagex=parseInt((opts.Photos.length-1)/opts.ThumbsNumber);var pagex=parseInt(opts.currentIndex/opts.ThumbsNumber);
$("#rew"+opts.HashId).removeClass(opts.classRew).removeClass(opts.classRewDisabled).addClass(opts.classRew).unbind("click").bind("click",function(){prev(opts,opts.currentIndex,index);
if(opts.LogWebEventScroll!=""){logwebEvent(opts.LogWebEventScroll,"NA");}return false;
});$("#btnThumbRewind"+opts.HashId).removeClass(opts.classThumbRew).removeClass(opts.classThumbRewDisabled).addClass(opts.classThumbRew).unbind("click").bind("click",function(){prevJump(opts);
return false;});$("#fwd"+opts.HashId).removeClass(opts.classFwd).removeClass(opts.classFwdDisabled).addClass(opts.classFwd).unbind("click").bind("click",function(){next(opts,opts.currentIndex,index);
if(opts.LogWebEventScroll!=""){logwebEvent(opts.LogWebEventScroll,"NA");}return false;
});$("#btnThumbForward"+opts.HashId).removeClass(opts.classThumbFwd).removeClass(opts.classThumbFwdDisabled).addClass(opts.classThumbFwd).unbind("click").bind("click",function(){nextJump(opts);
return false;});$("#imageBtnPrev"+opts.HashId).removeClass(opts.classRew).removeClass(opts.classRewDisabled).addClass(opts.classRew).unbind("click").bind("click",function(){prev(opts,opts.currentIndex,index);
return false;});$("#imageBtnNext"+opts.HashId).removeClass(opts.classFwd).removeClass(opts.classFwdDisabled).addClass(opts.classFwd).unbind("click").bind("click",function(){next(opts,opts.currentIndex,index);
return false;});if((opts.Photos.length<=1)&&(opts.Type!=PhotoGalleryType.PHOTOS&&(opts.Exterior.length+opts.Interior.length)<=1)){$("#controls"+opts.HashId).hide();
}if(currentIndex==0){$("#rew"+opts.HashId).removeClass(opts.classRew).addClass(opts.classRewDisabled).unbind("click").click(function(){return false;
});}if(currentIndex==(opts.Photos.length-1)){$("#fwd"+opts.HashId).removeClass(opts.classFwd).addClass(opts.classFwdDisabled).unbind("click").click(function(){return false;
});}if(opts.ThumbsJump){if(currentIndex==0||pagex==0){$("#btnThumbRewind"+opts.HashId).removeClass(opts.classThumbRew).addClass(opts.classThumbRewDisabled).unbind("click").click(function(){return false;
});}if(pagex>=nopagex){$("#btnThumbForward"+opts.HashId).removeClass(opts.classThumbFwd).addClass(opts.classThumbFwdDisabled).unbind("click").click(function(){return false;
});}}if(opts.showNumberOf){var lblIndex=currentIndex;$("#lblCurrentImage"+opts.HashId).html((++lblIndex)+" of "+opts.Photos.length);
}if(opts.showImageControls){if(currentIndex==0){$("#imageBtnPrev"+opts.HashId).removeClass(opts.classRew).addClass(opts.classRewDisabled).unbind("click").click(function(){return false;
});}if(currentIndex==(opts.Photos.length-1)){$("#imageBtnNext"+opts.HashId).removeClass(opts.classFwd).addClass(opts.classFwdDisabled).unbind("click").click(function(){return false;
});}}}function next(opts,id,index){var nid=++id;if(opts.showImageControls){ShowMainImage(opts,nid,nid);
setControls(nid,nid,opts);}else{if((nid%opts.ThumbsNumber==0)&&((opts.Type==PhotoGalleryType.ALL)||(opts.Type==PhotoGalleryType.EXTERIOR)||(opts.Type==PhotoGalleryType.INTERIOR))){var oothis=$("#thumbImages"+opts.HashId);
$(oothis).html("");ShowPrevJump(opts,oothis);for(i=0;i<opts.ThumbsNumber;i++){var nextid=id+i;
if(opts.Photos.length>nextid){AddImage(opts,oothis,i,nextid);}}ShowNextJump(opts,oothis);
ShowDotsJump(opts,oothis);ShowSelectedImage($("#thumbImage"+opts.HashId+"_0"),opts);
}else{var idx=parseInt(index,10)+1;ShowSelectedImage($("#thumbImage"+opts.HashId+"_"+idx),opts);
}}}function prev(opts,id,index){var pid=id-1;if(opts.showImageControls){ShowMainImage(opts,pid,pid);
setControls(pid,pid,opts);}else{if((id%opts.ThumbsNumber==0)&&(opts.Type!=PhotoGalleryType.PHOTOS)){var oothis=$("#thumbImages"+opts.HashId);
$(oothis).html("");ShowPrevJump(opts,oothis);for(i=0;i<opts.ThumbsNumber;i++){var previd=id-opts.ThumbsNumber+i;
AddImage(opts,oothis,i,previd);}ShowNextJump(opts,oothis);ShowDotsJump(opts,oothis);
var lastindex=opts.ThumbsNumber-1;ShowSelectedImage($("#thumbImage"+opts.HashId+"_"+lastindex),opts);
}else{var idx=parseInt(index,10)-1;ShowSelectedImage($("#thumbImage"+opts.HashId+"_"+idx),opts);
}}}function start(opts){if(opts.Photos.length>1){var ix=$("#mainImage"+opts.HashId).attr("meta:index");
var pix=$("#mainImage"+opts.HashId).attr("meta:selectid");if(pix==opts.Photos.length-1){InitThumbs(opts);
setControls(0,0,opts);next(opts,0,-1);}else{next(opts,pix,ix);}$("#playpause"+opts.HashId).removeClass(opts.classPlay).addClass(opts.classPause);
opts.playslideshow=true;createTimer(opts);}}function stop(opts){$("#playpause"+opts.HashId).removeClass(opts.classPause).addClass(opts.classPlay);
clearTimeout(opts.timer);opts.playslideshow=false;opts.timer=0;}function createTimer(opts){var vis=$("#mainImage"+opts.HashId).parent().parent().css("display");
if(vis=="block"){AddPartner("kbb",s_pageName+"_autoplay","");var sid=$("#mainImage"+opts.HashId).attr("meta:selectid");
var idx=$("#mainImage"+opts.HashId).attr("meta:index");setControls(sid,idx,opts);
opts.timer=setTimeout(function(){start(opts);},opts.playtimeout);}else{opts.playslideshow=false;
stop(opts);}}function PhotoGallerySlideShow(opts){if(opts.playslideshow==false){$("#playpause"+opts.HashId).removeClass(opts.classPlay).addClass(opts.classPause);
if(opts.showPlayButton==true){$("#mainButton"+opts.HashId).removeClass("pause").addClass("play").hide();
$("#mainButton"+opts.HashId+" .play").hide();$("#mainButton"+opts.HashId+" .pause").show();
}opts.playslideshow=true;clearTimeout(opts.timer);opts.timer=0;var oothis=$("#thumbImages"+opts.HashId);
$(oothis).html("");if(opts.Type==PhotoGalleryType.INTERIOR){var id=opts.Exterior.length+opts.currentIndex;
opts.currentIndex=id;}if((opts.Type==PhotoGalleryType.EXTERIOR)||(opts.Type==PhotoGalleryType.INTERIOR)){opts.Type=PhotoGalleryType.ALL;
}setPhotos(opts);ShowPrevJump(opts,oothis);var sid=$("#mainImage"+opts.HashId).attr("meta:selectid");
var idx=$("#mainImage"+opts.HashId).attr("meta:index");if(opts.Type==PhotoGalleryType.PHOTOS){for(i=0;
i<opts.Photos.length;i++){AddImage(opts,oothis,i,i);if(((i+1)%(opts.ThumbsNumber))==0){oothis.append("<br/>");
}}}else{var pos=parseInt(opts.currentIndex/opts.ThumbsNumber)*opts.ThumbsNumber;for(var i=pos,j=0;
i<parseInt(opts.ThumbsNumber)+pos;i++,j++){if(i<opts.Photos.length){AddImage(opts,oothis,j,i);
}}}ShowNextJump(opts,oothis);ShowDotsJump(opts,oothis);createTimer(opts);}else{opts.playslideshow=false;
if(opts.showPlayButton==true){$("#mainButton"+opts.HashId).removeClass("play").addClass("pause").hide();
$("#mainButton"+opts.HashId+" .pause").hide();$("#mainButton"+opts.HashId+" .play").show();
}stop(opts);}}function updateADsAndOmniture(opts){if(opts.doAdOmnitureUpdate){opts.imageCount++;
if((opts.AdRefreshRate>0)&&((opts.imageCount%opts.AdRefreshRate)==0)){try{updateOmniture(opts);
reloadLeaderboard();reloadSkyscraper();}catch(e){}}}}function updateOmniture(opts){reSubmitOmniture(opts.pagename,"","");
}function replaceQueryString(a,k,v){var re=new RegExp("([?|&])"+k+"=.*?(&|$)","i");
if(a.match(re)){return a.replace(re,"$1"+k+"="+v+"$2");}else{if(v!=""){if(a.indexOf("?")>0){return a+"&"+k+"="+v;
}else{return a+"?"+k+"="+v;}}else{return a;}}}})(jQuery);
