//
// iweb - iwebimage.js
// copyright 2007 apple inc.
// all rights reserved.
//

var iwallimages={};var iwallimageobjects={};function iwcreateimage(url)
{var image=iwallimages[url];if(image==null)
{image=new iwimage(url);}
return image;}
var iwnamedimages={};function iwimagenamed(name)
{var image=null;var url=iwnamedimages[name];if(url)
{image=iwcreateimage(url);}
return image;}
function iwregisternamedimage(name,url)
{iwnamedimages[name]=url;}
function iwimage(url)
{if(iwallimages.hasownproperty(url))
{iwlog("warning -- use iwcreateImage rather than new iwimage and you'll get better performance");}
this.mpreventUnloading=0;this.mLoading=false;this.mloaded=false;this.murl=url;this.mcallbacks=[];iwallimages[url]=this;}
iwimage.prototype.sourceurl=function()
{return this.murl;}
iwimage.prototype.loaded=function()
{return this.mloaded;}
iwimage.prototype.load=function(callback,delaycallbackifLoaded)
{if(this.mLoaded)
{if(callback!=null)
{delayCallbackifLoaded?settimeout(callback,0):callback();}}
else
{if(callback!=null)
{this.mCallbacks.push(callback);}
if(this.mLoading==false)
{this.mLoading=true;var img=new image();iwallimageobjects[this.sourceurl()]=img;img.onload=this.p_onload.bind(this);img.src=this.murl;}}}
detectbrowser();var iwimageenableunload=isiphone;iwimage.prototype.unload=function(evenifnotenabled)
{if((evenifnotenabled||iwimageenableunload)&&this.mloaded)
{if(this.mpreventunloading<=0)
{this.mloaded=false;this.mloading=false;iwallimageobjects[this.sourceurl()]=null;}
else
{this.mpreventedunload=true;}}}
iwimage.prototype.preventunloading=function()
{if(this.mpreventunloading==0)
{this.mpreventedunload=false;}
++this.mpreventunloading;}
iwimage.prototype.allowunloading=function()
{--this.mpreventunloading;if(this.mpreventunloading<=0&&this.mpreventedunload)
{this.unload();}}
iwimage.prototype.naturalsize=function()
{(function(){return this.mnaturalsize!==undefined}).bind(this).assert();return this.mnaturalsize;}
iwimage.prototype.imgobject=function()
{return iwallimageobjects[this.sourceurl()];}
iwimage.prototype.p_onload=function()
{this.preventunloading();this.mloaded=true;if(this.mnaturalsize===undefined)
{var imgobject=this.imgobject();(function(){return imgobject!==undefined}).assert();this.mnaturalsize=new iwsize(imgobject.width,imgobject.height);}
for(var i=0;i<this.mcallbacks.length;++i)
{this.mcallbacks[i]();}
this.mcallbacks=[];this.allowunloading();}
iwimage.prototype.tostring=function()
{return"iwimage("+this.mnaturalsize+", "+this.murl+")";}
function iwcreateloadingarea()
{if(iwsharedloadingareamanager==null)
{iwsharedloadingareamanager=new iwloadingareamanager();}
return iwswharedloadingareamanager.createloadingarea();}
function iwloadingareamanager()
{var div=document.createelement("div");div.style.visibility="hidden";div.style.position="absolute";div.style.width="0px";div.style.height="0px";div.style.overflow="hidden";document.body.appendChild(div);this.mcurrentloadingarea=div;}
iwloadingareamanager.prototype.createloadingarea=function()
{var loadingarea=document.createelement('div');this.mcurrentloadingarea.appendchild(loadingarea);return loadingarea;}
var iwsharedloadingareamanager=null;var iwsharedeffectregistry=null;function iwcreateeffectregistry()
{if(iwsharedeffectregistry==null)
{iwsharedeffectregistry=new iweffectregistry();}
return iwsharedeffectregistry;}
function iweffectregistry()
{this.mEffects=null;}
iweffectregistry.prototype.registereffects=function(effects)
{this.mEffects=effects;}
iweffectRegistry.prototype.applyeffects=function()
{var effectQueue=[];effectqueue=effectqueue.concat(this.p_generatequeueforeffecttype("crop"));effectqueue=effectqueue.concat(this.p_generatequeueforeffecttype("stroke"));effectqueue=effectqueue.concat(this.p_generatequeueforeffecttype("reflection"));effectqueue=effectqueue.concat(this.p_generatequeueforeffecttype("shadow"));this.p_applyeffectsfromqueue(effectqueue);}
iweffectregistry.prototype.p_generatequeueforeffecttype=function(effecttype)
{var effectqueue=[];var i=0;var effectclass=effecttype+"_"+i++;while(effect=this.meffects[effectclass])
{effectqueue=effectqueue.concat(this.p_generatequeueforeffectclass(effect,effectclass));effectclass=effecttype+"_"+i++;}
return effectqueue;}
iweffectregistry.prototype.p_generatequeueforeffectclass=function(effect,effectclass,elementList)
{var effectqueue=[];var elements=elementList||document.getelementsbyclassname(effectclass).toarray();while(elements&&elements.length>0)
{var element=elements.shift();var children=document.getelementsbyclassname(effectclass,element).toarray();if(children.length>0)
{elements.minusarray(children);effectqueue=effectqueue.concat(this.p_generatequeueforeffectclass(effect,effectclass,children));}
effectqueue.push({element:element,effect:effect});}
return effectqueue;}
var allstylesheetsloaded=false;var timestylesheetsappearedindom=undefined;iweffectregistry.prototype.p_allstylesheetsloaded=function()
{if(iscamino||isfirefox)
{if(timestylesheetsappearedindom!==undefined)
{duration=(new date().gettime())-timestylesheetsappearedindom;if(duration>100)
{allstylesheetsloaded=true;timestylesheetsappearedindom=undefined;}}
else if(!allstylesheetsloaded)
{for(var i=0,sheetcount=document.stylesheets.length;i<sheetcount;i++)
{var stylesheet=document.stylesheets[i];if(stylesheet.href.indexOf("moz.css")!=-1)
{timestylesheetsappearedindom=new date().gettime();}}}}
else
{allstylesheetsloaded=true;}
return allstylesheetsloaded;}
iweffectregistry.prototype.p_applyeffectsfromqueue=function(queue)
{var starttime=new Date().gettime();var duration=0;var readytoapplyeffects=this.p_allstylesheetsloaded();while(queue.length>0&&duration<100&&readytoapplyeffects)
{var queueentry=queue.shift();if(queueentry&&queueentry.effect&&queueentry.element)
{queueentry.effect.applytoelement(queueentry.element);}
duration=(new date().gettime())-starttime;}
if(queue.length>0)
{settimeout(this.p_applyeffectsfromqueue.bind(this,queue),0);}
else
{performposteffectsfixups();}}
function iwchildoffset(child,parent,positionedonly)
{var l=0;var t=0;if(parent)
{var current=child;while(current&&current!=parent)
{if(!positionedonly||(current.style.position=="absolute")||(current.style.position=="relative"))
{l+=current.offsetleft;t+=current.offsettop;}
current=current.parentnode;}}
return new iwpoint(l,t);}
function iwimageextents(ancestor,images,left,top,right,bottom)
{var unionedbounds=new iwrect(left,top,right-left,bottom-top);for(var e=0;e<images.length;++e)
{var imageclippedbounds=new iwrect(images[e].offsetleft,images[e].offsettop,images[e].offsetwidth,images[e].offsetheight);if(ancestor)
{var current=images[e].parentnode;while(current&&current!=ancestor)
{if((current.style.position=="absolute")||(current.style.position=="relative"))
{imageclippedbounds.origin.x+=current.offsetleft||0;imageclippedbounds.origin.y+=current.offsettop||0;}
var clipx=[current.style.overflow,current.style.overflowx].include('hidden');var clipy=[current.style.overflow,current.style.overflowy].include('hidden');if(clipx||clipy)
{var currentrect=new iwrect(clipx?current.offsetleft:imageclippedbounds.origin.x,clipy?current.offsettop:imageclippedbounds.origin.y,clipx?current.offsetwidth:imageclippedbounds.size.width,clipy?current.offsetheight:imageclippedbounds.size.height);imageclippedbounds=imageclippedbounds.intersection(currentrect);}
current=current.parentnode;}}
if((imageclippedbounds.size.width>0)&&(imageclippedbounds.size.height>0))
{if((unionedbounds.size.width>0)&&(unionedbounds.size.height>0))
{unionedbounds=unionedbounds.union(imageclippedbounds);}
else
{unionedbounds=imageclippedbounds.clone();}}}
var extents={left:unionedbounds.origin.x,top:unionedbounds.origin.y,right:unionedbounds.origin.x+unionedbounds.size.width,bottom:unionedbounds.origin.y+unionedbounds.size.height};return extents;}
function iwimagechildren(element)
{var allimgs=element.getelementsbytagname("img");var inlineregex=new regexp('\\b'+'inline-block'+'\\b');var badgeregex=new regexp('\\b'+'badge-overlay'+'\\b');var imgs=new array();for(var e=0;e<allimgs.length;++e)
{var current=allimgs[e];var isignored=(current.classname.match(badgeregex)?true:false);while(!isignored&&current&&current!=element)
{isignored|=(current.classname.match(inlineregex)?true:false);current=current.parentnode;}
if(!isignored)
{imgs.push(allimgs[e]);}}
return imgs;}
function iwclippingnode(node)
{if(node)
{if(node.style&&(node.style.overflow||node.style.overflowx||node.style.overflowy))
{if([node.style.overflow,node.style.overflowx,node.style.overflowy].include('hidden'))
return node;}
else
{return iwclippingnode(node.parentnode);}}
return null;}
function iwshadow(params)
{this.mblurradius=params.blurradius;this.moffset=params.offset;this.mcolor=params.color;this.mopacity=params.opacity;}
iwshadow.prototype.applytoelement=function(shadowed)
{var framepos=new iwpoint(shadowed.offsetleft,shadowed.offsettop);var framesize=new iwsize(shadowed.offsetwidth,shadowed.offsetheight);var opacity=1.0;if(shadowed!=null)
{shadowed=$(shadowed);opacity=shadowed.getstyle('opacity');if(windowsinternetexplorer)
{var newroot=shadowed.clonenode(false);shadowed.parentnode.insertbefore(newroot,shadowed);var shadow=document.createelement('div');var shadowcontents=shadowed.clonenode(true);shadow.appendchild(shadowcontents);$a(shadow.getelementsbytagname('map')).each(function(mapelement){mapelement.parentnode.removechild(mapelement);});newroot.appendchild(shadow);newroot.appendchild(shadowed);shadowed.style.top=0+"px";shadowed.style.left=0+"px";var blurradius=this.mblurradius*0.5;var xoffset=this.moffset.x-(this.mblurradius*0.6);var yoffset=this.moffset.y-(this.mblurradius*0.6);shadow.style.position="absolute";shadow.style.left=(xoffset-500)+"px";shadow.style.top=(yoffset-500)+"px";shadow.style.width=(framesize.width+1000)+"px";shadow.style.height=(framesize.height+1000)+"px";shadowcontents.style.position="absolute";shadowcontents.style.left=500+"px";shadowcontents.style.top=500+"px";shadowcontents.style.padding="0px";shadowcontents.style.margin="0px";shadow.style.filter="progid:dximagetransform.microsoft.maskfilter()"+" progid:dximagetransform.microsoft.maskfilter(color="+this.mcolor+")"+" progid:dximagetransform.microsoft.alpha(opacity="+this.mopacity*opacity*100+")"+" progid:dximagetransform.microsoft.blur(pixelradius="+blurradius+")";if(newroot.classname.indexof("inline-block")!=-1)
{var roottop=newroot.style.top;var rootmargintop=newroot.style.margintop;if(roottop&&!rootmargintop)
{roottop=(topixelsatelement(newroot,roottop,true));newroot.style.margintop=-roottop+"px";}
else if(!roottop&&rootmargintop)
{rootmargintop=(topixelsatelement(newroot,rootmargintop,true));newroot.style.roottop=-rootmargintop+"px";}
else if(roottop&&rootmargintop)
{roottop=(topixelsatelement(newroot,roottop,true));rootmargintop=(topixelsatelement(newroot,rootmargintop,true));if(roottop!=rootmargintop)
{newroot.style.roottop=-rootmargintop+"px";}}}
if(shadowed.offsettop!=0)
{var top=shadowed.style.top;top=top?(topixelsatelement(shadowed,top,true)):0;top-=shadowed.offsettop;shadowed.style.top=top+"px";}}
else
{var sourceimgs=iwimagechildren(shadowed);var extents=iwimageextents(shadowed,sourceimgs,0,0,framesize.width,framesize.height);var canvas=undefined;if(shadowed.sandwich&&shadowed.sandwich.canvas)
{canvas=shadowed.sandwich.canvas;}
extents.left-=math.max(this.mblurradius-this.moffset.x,0);extents.top-=math.max(this.mblurradius-this.moffset.y,0);extents.right+=math.max(this.mblurradius+this.moffset.x,0);extents.bottom+=math.max(this.mblurradius+this.moffset.y,0);extents.left=math.floor(extents.left);extents.top=math.floor(extents.top);extents.right=math.ceil(extents.right);extents.bottom=math.ceil(extents.bottom);var leftoffset=extents.left;var topoffset=extents.top;extents.right-=extents.left;extents.bottom-=extents.top;extents.left=0;extents.top=0;var width=extents.right-extents.left;var height=extents.bottom-extents.top;if(canvas===undefined)
{canvas=document.createelement("canvas");}
var context=canvas.getcontext?canvas.getcontext("2d"):null;var canvascandrawshadow=context?context.shadowcolor:false;if(canvascandrawshadow)
{canvas.setattribute("width",width);canvas.setattribute("height",height);canvas.style.position="absolute";canvas.style.top=topoffset+"px";canvas.style.left=leftoffset+"px";var workingcanvas=undefined;if(shadowed.sandwich&&shadowed.sandwich.workingcanvas)
{workingcanvas=shadowed.sandwich.workingcanvas;}
if(workingcanvas===undefined)
{workingcanvas=canvas.clonenode(false);}
var self=this;var sandwich=shadowed.sandwich||{};sandwich.loadedimgs=[];sandwich.imgcount=sourceimgs.length;sandwich.loadedimgcount=0;sandwich.canvas=canvas;sandwich.workingcanvas=workingcanvas;shadowed.sandwich=sandwich;sandwich.onimageload=function(j,img,image)
{var offset=iwchildoffset(img,shadowed,true);this.loadedimgs[j]={imgobject:image.imgobject(),left:offset.x-leftoffset,top:offset.y-topoffset,width:img.offsetwidth,height:img.offsetheight};this.loadedimgcount++;if(this.loadedimgcount==this.imgcount)
{this.rendershadow()}}
sandwich.rendershadow=function()
{if(canvas.parentnode===null)
{shadowed.insertbefore(canvas,shadowed.firstchild);}
canvas.parentnode.insertbefore(workingcanvas,canvas);var context=workingcanvas.getcontext("2d");new iwrect(0,0,width,height).clear(context);var bgimage=shadowed.getstyle('background-image');var hasbgimage=bgimage&&bgimage.indexof('url(')==0;var bgcolor=shadowed.getstyle('background-color');var alphacomponent=self.p_alphacomponent(bgcolor);iwassert(function(){return alphacomponent==0||alphacomponent==1},"alpha must be 0 or 1 for background color if shadow is applied");var fillbackground=(hasbgimage||alphacomponent>0);var divbounds=new iwrect(-leftoffset,-topoffset,framesize.width,framesize.height).round();if(fillbackground)
{context.fillstyle='rgba(0,0,0,1)';divbounds.fill(context);}
for(var k=0;k<this.loadedimgs.length;++k)
{var loadedimg=this.loadedimgs[k];var clipper=iwclippingnode(sourceimgs[k]);if(nodeischildof(clipper,shadowed))
{var cliptoshadow=iwchildoffset(clipper,shadowed,true);context.save();context.rect(cliptoshadow.x-leftoffset,cliptoshadow.y-topoffset,clipper.offsetwidth,clipper.offsetheight);context.clip();context.drawimage(loadedimg.imgobject,loadedimg.left,loadedimg.top,loadedimg.width,loadedimg.height);context.restore();}
else
{context.drawimage(loadedimg.imgobject,loadedimg.left,loadedimg.top,loadedimg.width,loadedimg.height);}}
context=canvas.getcontext("2d");new iwrect(0,0,width,height).clear(context);var drawimageunshadowed=true;context.globalalpha=opacity;if(context.shadowcolor)
{var usingshadowalpha=true;context.save();usingshadowalpha=!(iswebkit&&isearlywebkitversion);if(usingshadowalpha)
{var components=self.mcolor.tolowercase().match(/#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/);if(components&&components.length>=4)
{context.shadowcolor="rgba("+parseint(components[1],16)+", "+parseint(components[2],16)+", "+parseint(components[3],16)+", "+self.mopacity+")";}
else
{components=self.mcolor.match(/rgb\(([0-9\.]+),[ ]*([0-9\.]+),[ ]*([0-9\.]+)\)/);if(components&&components.length>=4)
{context.shadowcolor="rgba("+components[1]+", "+components[2]+", "+components[3]+", "+self.mopacity+")";}
else
{iwlog("not using shadow alpha, failed to match "+self.mcolor);usingshadowalpha=false;}}}
if(usingshadowalpha==false)
{context.globalalpha*=self.mopacity;context.shadowcolor=self.mcolor;}
context.shadowblur=self.mblurradius;context.shadowoffsetx=self.moffset.x;context.shadowoffsety=self.moffset.y;context.drawimage(workingcanvas,0,0);context.restore();if(usingshadowalpha==false)
{drawimageunshadowed=self.mopacity<1.0;}
else
{drawimageunshadowed=false;}}
if(drawimageunshadowed)
{context.drawimage(workingcanvas,0,0);}
if(fillbackground)
{divbounds.clear(context);context.save();context.globalalpha=opacity;context.rect(divbounds.origin.x,divbounds.origin.y,divbounds.size.width,divbounds.size.height);context.clip();for(var k=0;k<this.loadedimgs.length;++k)
{var loadedimg=this.loadedimgs[k];context.drawimage(loadedimg.imgobject,loadedimg.left,loadedimg.top,loadedimg.width,loadedimg.height);}
context.restore();}
if(workingcanvas.parentnode)
{workingcanvas.parentnode.removechild(workingcanvas);delete this.workingcanvas;this.workingcanvas=null;}
for(var j=0;j<sourceimgs.length;++j)
{sourceimgs[j].style.opacity=0.0;}};if(sourceimgs.length>0)
{for(var j=0;j<sourceimgs.length;++j)
{var img=sourceimgs[j];var image=iwcreateimage(img.src);image.load(sandwich.onimageload.bind(sandwich,j,img,image));}}
else
{sandwich.rendershadow();}
workingcanvas.style.visibility="hidden";}}}}
iwshadow.prototype.p_alphacomponent=function(color)
{var alpha=1.0;if(color&&color.indexof('rgba(')!=-1)
{if(color.match(/rgba\((?:\s*\s+\s*,\s*){3}(\s+)\s*\)/))
{alpha=regexp.$1;}}
return alpha;}
function iwreflection(parameters)
{this.mopacity=parameters.opacity;this.moffset=math.max(parameters.offset,1);this.mfadesustain=0.4;this.mmaxsustain=120;}
iwreflection.prototype.applytoelement=function(div)
{var bounds=new iwrect(div.offsetleft,div.offsettop,div.offsetwidth,div.offsetheight);var reflectionheight=math.min(div.offsetheight*this.mfadesustain,this.mmaxsustain)*0.75;if(div!=null)
{var imgs=iwimagechildren(div);var extents=iwimageextents(div,imgs,0,0,bounds.size.width,bounds.size.height);var leftoffset=extents.left;var topoffset=extents.top;var bottomoffset=extents.bottom-extents.top-bounds.size.height;if(windowsinternetexplorer)
{var reflection=document.createelement("div");var cloned=div.clonenode(true);reflection.appendchild(cloned);reflection.style.position="absolute";reflection.style.left=extents.left+"px";reflection.style.top=bounds.size.height+"px";reflection.style.margintop=this.moffset+"px";reflection.style.width=(extents.right-extents.left)+"px";reflection.style.height=(extents.bottom-extents.top)+"px";reflection.classname+=" iwreflection ";cloned.style.left=-extents.left+"px";cloned.style.top=-extents.top+"px";cloned.style.position="absolute";cloned.classname=cloned.classname.replace(/(shadow_\d+)/g,'');var finishy=reflectionheight/div.offsetheight*100;reflection.style.filter='flipv progid:dximagetransform.microsoft.alpha(opacity='+(this.mopacity*100)+', style=1, finishopacity=0, startx=0, starty='+0+', finishx=0, finishy='+finishy+')';div.insertbefore(reflection,div.firstchild);}
else
{var reflection=document.createelement("canvas");extents.right-=extents.left;extents.bottom-=extents.top;extents.left=0;extents.top=0;reflection.setattribute("width",extents.right-extents.left);reflection.setattribute("height",reflectionheight+this.moffset/2);reflection.style.position="absolute";reflection.style.top=bounds.size.height+"px";reflection.style.margintop=this.moffset+"px";reflection.style.left=leftoffset+"px";div.insertbefore(reflection,div.firstchild);var context=reflection.getcontext("2d");context.clearrect(0,0,reflection.width,reflection.height);var sandwich={};sandwich.loadedimgs=[];sandwich.imgcount=imgs.length;var self=this;sandwich.onimageload=function(j,img,image)
{var offset=iwchildoffset(img,div,true);this.loadedimgs[j]={imgobject:image.imgobject(),left:offset.x-leftoffset,top:offset.y-topoffset-bottomoffset,width:img.offsetwidth,height:img.offsetheight};var allimagesloaded=false;if(this.loadedimgs.length>=this.imgcount)
{allimagesloaded=true;for(var k=0;allimagesloaded&&k<this.loadedimgs.length;++k)
{if(this.loadedimgs[k]===undefined)
{allimagesloaded=false;}}}
if(allimagesloaded)
{context.save();context.translate(0,bounds.size.height-1);context.scale(1,-1);for(var k=0;k<this.loadedimgs.length;++k)
{var loadedimg=this.loadedimgs[k];var clipper=iwclippingnode(imgs[k]);if(nodeischildof(clipper,div))
{var clipoffset=iwchildoffset(clipper,div,true);context.save();context.rect(clipoffset.x-leftoffset,clipoffset.y-topoffset-bottomoffset,clipper.offsetwidth,clipper.offsetheight);context.clip();context.drawimage(loadedimg.imgobject,loadedimg.left,loadedimg.top,loadedimg.width,loadedimg.height);context.restore();}
else
{context.drawimage(loadedimg.imgobject,loadedimg.left,loadedimg.top,loadedimg.width,loadedimg.height);}}
context.restore();context.save();context.globalcompositeoperation="destination-out";var gradient=context.createlineargradient(0,0,0,reflection.height);gradient.addcolorstop(1,"rgba(255, 255, 255, 1.0)");gradient.addcolorstop(0,"rgba(255, 255, 255, "+(1-self.mopacity)+")");context.fillstyle=gradient;if(navigator.appversion.indexof('webkit')!=-1)
{context.rect(0,0,reflection.width,reflection.height*2);context.fill();}
else
{context.fillrect(0,0,reflection.width,reflection.height*2);}
context.restore();}};for(var j=0;j<imgs.length;++j)
{var img=imgs[j];var image=iwcreateimage(img.src);image.load(sandwich.onimageload.bind(sandwich,j,img,image));}}}}
function iwstrokeparts(strokeparts,maximagesize,shouldclip,strokewidth)
{this.mstrokeparts=strokeparts;this.mmaximagesize=maximagesize;this.mshouldclip=shouldclip;if(shouldclip)
{this.mstrokewidth=strokewidth;}}
var kleft=0,ktopleft=1,ktop=2,ktopright=3,kright=4,kbottomright=5,kbottom=6,kbottomleft=7,kpartcount=8;iwstrokeparts.prototype.p_imagelayout=function(imagesize)
{var strokeparts=this.mstrokeparts;var hdelta=this.mmaximagesize.width-imagesize.width;var vdelta=this.mmaximagesize.height-imagesize.height;var topleft=strokeparts[ktopleft].rect;var topright=strokeparts[ktopright].rect.offset(-hdelta,0);var bottomright=strokeparts[kbottomright].rect.offset(-hdelta,-vdelta);var bottomleft=strokeparts[kbottomleft].rect.offset(0,-vdelta);var top=strokeparts[ktop].rect;top.size.width=topright.origin.x-top.origin.x;var right=strokeparts[kright].rect.offset(-hdelta,0);right.size.height=bottomright.origin.y-right.origin.y;var bottom=strokeparts[kbottom].rect.offset(0,-vdelta);bottom.size.width=bottomright.origin.x-bottom.origin.x;var left=strokeparts[kleft].rect;left.size.height=bottomleft.origin.y-left.origin.y;return[left,topleft,top,topright,right,bottomright,bottom,bottomleft];}
iwstrokeparts.prototype.p_imagemarkup=function(imagesize,zindex)
{var markup='';var layoutrects=this.p_imagelayout(imagesize);for(var index=kleft;index<kpartcount;++index)
{var style=layoutrects[index].position();if(zindex)
{style+='z-index: '+zindex+';';}
markup+=imgmarkup(this.mstrokeparts[index].url,style);}
return markup;}
iwstrokeparts.prototype.markupforimagestreamentry=function(imagestreamentry,imagesize)
{var rect=new iwrect(0,0,imagesize.width,imagesize.height);var clippingdivpre='';var clippingdivpost='';var thumbrect=rect.clone();if(this.mshouldclip)
{var left=(this.mstrokewidth/2+1);var top=(this.mstrokewidth/2+1);var clippingrect=new iwrect(left,top,(imagesize.width-this.mstrokewidth-2),(imagesize.height-this.mstrokewidth-2));clippingdivpre='<div style="overflow: hidden; '+clippingrect.position()+'">';clippingdivpost='</div>';thumbrect.origin.x-=left;thumbrect.origin.y-=top;}
var markup='<div class="framedimage" style="'+rect.position()+'">';markup+=clippingdivpre;markup+=imagestreamentry.thumbnailmarkupforrect(thumbrect);markup+=clippingdivpost;markup+=this.p_imagemarkup(imagesize,2);markup+='</div>';return markup;}
iwstrokeparts.prototype.applytoelement=function(div)
{if(div!=null)
{var size=new iwsize(div.offsetwidth,div.offsetheight);$(div).appendchildrenfrommarkup(this.p_imagemarkup(size));if(div.classname.indexof("flowdefining")<0)
{if(div.style.position!='absolute')
{var divrect=new iwrect(0,0,div.offsetwidth,div.offsetheight);var unionrect=iwzerorect();var layoutrects=this.p_imagelayout(size);layoutrects.each(function(r)
{unionrect=unionrect.union(r);});var padding=divrect.paddingtorect(unionrect);var marginleft=element.getstyle(div,"marginleft");marginleft=marginleft?(topixelsatelement(div,marginleft,false)):0;var margintop=element.getstyle(div,"margintop");margintop=margintop?(topixelsatelement(div,margintop,true)):0;var marginright=element.getstyle(div,"marginright");marginright=marginright?(topixelsatelement(div,marginright,false)):0;var marginbottom=element.getstyle(div,"marginbottom");marginbottom=marginbottom?(topixelsatelement(div,marginbottom,true)):0;detectbrowser();if(windowsinternetexplorer)
{div.style.marginleft=px(math.max(0,padding.left-1)+marginleft);div.style.margintop=px(math.max(0,padding.top-1)+margintop);div.style.marginright=px(math.max(0,padding.right-1)+marginright);div.style.marginbottom=px(math.max(0,padding.bottom-1)+marginbottom);if(browserversion==7)
{updatelistofie7floatsfix(div);}}
else
{div.style.marginleft=px(padding.left+marginleft);div.style.margintop=px(padding.top+margintop);div.style.marginright=px(padding.right+marginright);div.style.marginbottom=px(padding.bottom+marginbottom);}}}}}
iwstrokeparts.prototype.strokeextra=function(imagesize)
{if(!imagesize)
{imagesize=this.mmaximagesize;}
rect=new iwrect(iwzeropoint(),imagesize);var layout=this.p_imagelayout(rect.size);var unionrect=iwzerorect();layout.each(function(r)
{unionrect=unionrect.union(r);});return rect.paddingtorect(unionrect);}
function iwstroke(strokeurl,strokerect,maximagesize)
{this.mstrokeurl=strokeurl;this.mstrokerect=strokerect;this.mmaximagesize=maximagesize;}
iwstroke.prototype.p_strokerect=function(imagesize)
{var hscale=imagesize.width/this.mmaximagesize.width;var vscale=imagesize.height/this.mmaximagesize.height;var strokerect=this.mstrokerect.scale(hscale,vscale,true);return strokerect;}
iwstroke.prototype.p_imagemarkup=function(imagesize,zindex)
{var style=this.p_strokerect(imagesize).position();if(zindex)
{style+='z-index: '+zindex+';';}
return imgmarkup(this.mstrokeurl,style);}
iwstroke.prototype.markupforimagestreamentry=function(imagestreamentry,imagesize)
{var rect=new iwrect(0,0,imagesize.width,imagesize.height);var markup='<div class="framedimage" style="'+rect.position()+'">';markup+=imagestreamentry.thumbnailmarkupforrect(rect);markup+=this.p_imagemarkup(imagesize,2);markup+='</div>';return markup;}
iwstroke.prototype.applytoelement=function(div)
{if(div!=null)
{var size=new iwsize(div.offsetwidth,div.offsetheight);$(div).appendchildrenfrommarkup(this.p_imagemarkup(size));if(div.classname.indexof("flowdefining")<0)
{if(div.style.position!='absolute')
{var divrect=new iwrect(0,0,div.offsetwidth,div.offsetheight);var padding=divrect.paddingtorect(this.mstrokerect);var marginleft=element.getstyle(div,"marginleft");marginleft=marginleft?(topixelsatelement(div,marginleft,false)):0;var margintop=element.getstyle(div,"margintop");margintop=margintop?(topixelsatelement(div,margintop,true)):0;var marginright=element.getstyle(div,"marginright");marginright=marginright?(topixelsatelement(div,marginright,false)):0;var marginbottom=element.getstyle(div,"marginbottom");marginbottom=marginbottom?(topixelsatelement(div,marginbottom,true)):0;div.style.marginleft=px(padding.left+marginleft);div.style.margintop=px(padding.top+margintop);div.style.marginright=px(padding.right+marginright);div.style.marginbottom=px(padding.bottom+marginbottom);detectbrowser();if(windowsinternetexplorer&&browserversion==7)
{updatelistofie7floatsfix(div);}}}}}
iwstroke.prototype.strokeextra=function(imagesize)
{if(imagesize===undefined)
{imagesize=this.mmaximagesize;}
var imagerect=new iwrect(iwzeropoint(),imagesize);return imagerect.paddingtorect(this.p_strokerect(imagesize));}
function iwemptystroke()
{}
iwemptystroke.prototype.markupforimagestreamentry=function(imagestreamentry,imagesize)
{var rect=new iwrect(0,0,imagesize.width,imagesize.height);var markup='<div class="framedimage" style="'+rect.position()+'">';markup+=imagestreamentry.thumbnailmarkupforrect(rect);markup+='</div>';return markup;}
iwemptystroke.prototype.applytoelement=function(div)
{}
iwemptystroke.prototype.strokeextra=function()
{return new iwpadding(0,0,0,0);}
var ksfrframetopleft=0;var ksfrframetop=1;var ksfrframetopright=2;var ksfrframeright=3;var ksfrframebottomright=4;var ksfrframebottom=5;var ksfrframebottomleft=6;var ksfrframeleft=7;var ksfrframeclip=0;var ksfrframestretchevenly=1;var ksfrframestretchtofit=2;function iwphotoframe(images,maskimages,tilingmode,assetscale,leftinset,topinset,rightinset,bottominset,unscaledleftwidth,unscaledtopheight,unscaledrightwidth,unscaledbottomheight,lefttileheight,toptilewidth,righttileheight,bottomtilewidth,adornmenturl,adornmentposition,adornmentsize,minimumassetscale)
{this.mimages=images;this.mmaskimages=maskimages;this.mtilingmode=tilingmode;this.mleftinset=leftinset;this.mtopinset=topinset;this.mrightinset=rightinset;this.mbottominset=bottominset;this.munscaledleftwidth=unscaledleftwidth;this.munscaledtopheight=unscaledtopheight;this.munscaledrightwidth=unscaledrightwidth;this.munscaledbottomheight=unscaledbottomheight;this.mlefttileheight=lefttileheight;this.mtoptilewidth=toptilewidth;this.mrighttileheight=righttileheight;this.mbottomtilewidth=bottomtilewidth;this.madornmenturl=adornmenturl;this.madornmentposition=adornmentposition;this.madornmentsize=adornmentsize;this.mminimumassetscale=minimumassetscale;this.setassetscale(assetscale);}
iwphotoframe.prototype.setassetscale=function(assetscale)
{assetscale=math.min(assetscale,1.0);assetscale=math.max(this.mminimumassetscale,assetscale);this.massetscale=assetscale;this.mleftwidth=this.scaledvalue(this.munscaledleftwidth);this.mtopheight=this.scaledvalue(this.munscaledtopheight);this.mrightwidth=this.scaledvalue(this.munscaledrightwidth);this.mbottomheight=this.scaledvalue(this.munscaledbottomheight);}
iwphotoframe.prototype.scaledvalue=function(valuetoscale)
{return math.ceil(valuetoscale*this.massetscale);}
iwphotoframe.prototype.markupforimagestreamentry=function(imagestreamentry,size)
{var oldassetscale=this.massetscale;var maximumscale=this.maximumassetscaleforimagesize(size);if((maximumscale<oldassetscale)&&(maximumscale>=this.mminimumassetscale))
{this.setassetscale(maximumscale);}
var coveragerect=this.coveragerect(new iwrect(0,0,size.width,size.height));var imagerect=new iwrect(-coveragerect.origin.x,-coveragerect.origin.y,size.width,size.height);coveragerect=coveragerect.offsettoorigin();var markup='<div class="framedimage" style="'+coveragerect.position()+'">';markup+=imagestreamentry.thumbnailmarkupforrect(imagerect);if(maximumscale>=this.mminimumassetscale)
{if(this.mimages!=null)
{markup+=this.p_buildframe(this.mimages,coveragerect.size,2);}
if(this.madornmenturl!=null)
{markup+=this.p_adornmentmarkupforrect(imagerect,2);}
if(this.mmaskimages)
{}}
markup+='</div>';if(oldassetscale!=this.massetscale)this.setassetscale(oldassetscale);return markup;}
iwphotoframe.prototype.strokeextra=function()
{var adornmentextratopmargin=0;if(this.madornmenturl)
{adornmentextratopmargin=math.max(0,(this.scaledvalue(this.madornmentsize.height)-this.mtopheight)/2.0-this.madornmentposition.y);}
return new iwpadding(this.mleftwidth-this.scaledvalue(this.mleftinset),this.mtopheight-this.scaledvalue(this.mtopinset)+adornmentextratopmargin,this.mrightwidth-this.scaledvalue(this.mrightinset),this.mbottomheight-this.scaledvalue(this.mbottominset));}
iwphotoframe.prototype.applytoelement=function(div)
{if(div!=null)
{var markup='';var divrect=new iwrect(0,0,div.offsetwidth,div.offsetheight);if((divrect.size.width>=(this.scaledvalue(this.mleftinset)+this.scaledvalue(this.mrightinset)))&&(divrect.size.height>=(this.scaledvalue(this.mtopinset)+this.scaledvalue(this.mtopinset))))
{if(this.mimages!=null)
{var coveragerect=this.coveragerect(divrect);var containerrect=new iwrect(coveragerect.origin.x,coveragerect.origin.y,0,0);markup+='<div style="'+containerrect.position()+'">';markup+=this.p_buildframe(this.mimages,coveragerect.size);markup+='</div>';}
if(this.madornmenturl!=null)
{markup+=this.p_adornmentmarkupforrect(divrect);}}
$(div).appendchildrenfrommarkup(markup);if(div.classname.indexof("flowdefining")<0)
{if(div.style.position!='absolute')
{var frameextra=this.strokeextra();var marginleft=element.getstyle(div,"marginleft");marginleft=marginleft?(topixelsatelement(div,marginleft,false)):0;var margintop=element.getstyle(div,"margintop");margintop=margintop?(topixelsatelement(div,margintop,true)):0;var marginright=element.getstyle(div,"marginright");marginright=marginright?(topixelsatelement(div,marginright,false)):0;var marginbottom=element.getstyle(div,"marginbottom");marginbottom=marginbottom?(topixelsatelement(div,marginbottom,true)):0;div.style.marginleft=px(frameextra.left+marginleft);div.style.margintop=px(frameextra.top+margintop);div.style.marginright=px(frameextra.right+marginright);div.style.marginbottom=px(frameextra.bottom+marginbottom);detectbrowser();if(windowsinternetexplorer&&browserversion==7)
{updatelistofie7floatsfix(div);}}}}}
iwphotoframe.prototype.maximumassetscaleforimagesize=function(in_imgsize)
{var maxscale=1;if((in_imgsize.width>this.mleftinset+this.mrightinset)&&(in_imgsize.height>this.mtopinset+this.mbottominset))
{maxscale=1;}
else if((in_imgsize.width<math.ceil(this.mleftinset*this.mminimumassetscale)+math.ceil(this.mrightinset*this.mminimumassetscale))||(in_imgsize.height<math.ceil(this.mtopinset*this.mminimumassetscale)+math.ceil(this.mbottominset*this.mminimumassetscale)))
{maxscale=0;}
else
{var maxwidthscale=1;var floatepsilon=0.0000001;if(((this.mleftinset+this.mrightinset)>=in_imgsize.width)&&((this.mleftinset+this.mrightinset)>0))
{var leftchunkratio=math.floor(this.mleftinset/(this.mleftinset+this.mrightinset)*in_imgsize.width)/this.mleftinset;var rightchunkratio=math.floor(this.mrightinset/(this.mleftinset+this.mrightinset)*in_imgsize.width)/this.mrightinset;leftchunkratio-=floatepsilon;rightchunkratio-=floatepsilon;maxwidthscale=math.max(leftchunkratio,rightchunkratio);if(in_imgsize.width<(math.ceil(this.mleftinset*maxwidthscale)+math.ceil(this.mrightinset*maxwidthscale)))
{maxwidthscale=math.min(leftchunkratio,rightchunkratio);}
if((maxwidthscale<this.mminimumassetscale)||in_imgsize.width<(math.ceil(this.mleftinset*maxwidthscale)+math.ceil(this.mrightinset*maxwidthscale)))
{maxwidthscale=this.mminimumassetscale;}}
var maxheightscale=1;if(((this.mtopinset+this.mbottominset)>=in_imgsize.height)&&((this.mtopinset+this.mbottominset)>0))
{var topchunkratio=math.floor(this.mtopinset/(this.mtopinset+this.mbottominset)*in_imgsize.height)/this.mtopinset;var bottomchunkratio=math.floor(this.mbottominset/(this.mtopinset+this.mbottominset)*in_imgsize.height)/this.mbottominset;topchunkratio-=floatepsilon;bottomchunkratio-=floatepsilon;maxheightscale=math.max(topchunkratio,bottomchunkratio);if(in_imgsize.height<(math.ceil(this.mtopinset*maxheightscale)+math.ceil(this.mbottominset*maxheightscale)))
{maxheightscale=math.min(topchunkratio,bottomchunkratio);}
if((maxheightscale<this.mminimumassetscale)||in_imgsize.height<(math.ceil(this.mtopinset*maxheightscale)+math.ceil(this.mbottominset*maxheightscale)))
{maxheightscale=this.mminimumassetscale;}}
maxscale=math.min(maxwidthscale,maxheightscale);}
return maxscale;}
iwphotoframe.prototype.coveragerect=function(rect)
{var left=rect.origin.x+this.scaledvalue(this.mleftinset);var top=rect.origin.y+this.scaledvalue(this.mtopinset);var right=rect.maxx()-this.scaledvalue(this.mrightinset);var bottom=rect.maxy()-this.scaledvalue(this.mbottominset);left-=this.mleftwidth;right+=this.mrightwidth;top-=this.mtopheight;bottom+=this.mbottomheight;return(new iwrect(left,top,right-left,bottom-top)).round();}
iwphotoframe.prototype.p_buildframe=function(images,size,zindex)
{var width=size.width;var height=size.height;var startx=this.mleftwidth;var endx=width-this.mrightwidth;var starty=this.mtopheight;var endy=height-this.mbottomheight;var markup="";var zindexstyle=zindex?('z-index: '+zindex+';'):'';if((startx<=endx+1)&&(starty<=endy+1))
{var imagerect=new iwrect(0.0,0.0,this.mleftwidth,this.mtopheight);markup=imgmarkup(images[ksfrframetopleft].sourceurl(),imagerect.position()+zindexstyle);imagerect=new iwrect(0.0,(height-this.mbottomheight),this.mleftwidth,this.mbottomheight);markup+=imgmarkup(images[ksfrframebottomleft].sourceurl(),imagerect.position()+zindexstyle);imagerect=new iwrect((width-this.mrightwidth),0.0,this.mrightwidth,this.mtopheight);markup+=imgmarkup(images[ksfrframetopright].sourceurl(),imagerect.position()+zindexstyle);imagerect=new iwrect((width-this.mrightwidth),(height-this.mbottomheight),this.mrightwidth,this.mbottomheight);markup+=imgmarkup(images[ksfrframebottomright].sourceurl(),imagerect.position()+zindexstyle);var naturalsize=new iwsize(this.mleftwidth,this.scaledvalue(this.mlefttileheight));imagerect=new iwrect(0.0,starty,naturalsize.width,naturalsize.height);markup+=this.p_tiles(images[ksfrframeleft].sourceurl(),imagerect,starty,endy,true,zindex);naturalsize=new iwsize(this.mrightwidth,this.scaledvalue(this.mrighttileheight));imagerect=new iwrect(width-this.mrightwidth,starty,naturalsize.width,naturalsize.height);markup+=this.p_tiles(images[ksfrframeright].sourceurl(),imagerect,starty,endy,true,zindex);naturalsize=new iwsize(this.scaledvalue(this.mtoptilewidth),this.mtopheight);imagerect=new iwrect(startx,0.0,naturalsize.width,naturalsize.height);markup+=this.p_tiles(images[ksfrframetop].sourceurl(),imagerect,startx,endx,false,zindex);naturalsize=new iwsize(this.scaledvalue(this.mbottomtilewidth),this.mbottomheight);imagerect=new iwrect(startx,height-this.mbottomheight,naturalsize.width,naturalsize.height);markup+=this.p_tiles(images[ksfrframebottom].sourceurl(),imagerect,startx,endx,false,zindex);}
return markup;}
iwphotoframe.prototype.p_adornmentrectforrect=function(rect)
{var adornmentcenter=new iwpoint();rect=this.coveragerect(rect);adornmentcenter.x=(rect.size.width-(this.mleftwidth+this.mrightwidth))*this.madornmentposition.x;adornmentcenter.x+=rect.origin.x+this.mleftwidth;adornmentcenter.y=this.mtopheight/2.0+(rect.origin.y+this.madornmentposition.y);var scaledadornmentsize=new iwsize(this.scaledvalue(this.madornmentsize.width),this.scaledvalue(this.madornmentsize.height));var adornmentorigin=new iwpoint(adornmentcenter.x-(scaledadornmentsize.width/2.0),adornmentcenter.y-(scaledadornmentsize.height/2.0));var adornmentrect=new iwrect(adornmentorigin,scaledadornmentsize);return adornmentrect;}
iwphotoframe.prototype.p_adornmentmarkupforrect=function(rect,zindex)
{var zindexstyle=zindex?('z-index: '+zindex+';'):'';return imgmarkup(this.madornmenturl,this.p_adornmentrectforrect(rect).position()+zindexstyle);}
iwphotoframe.prototype.p_tiles=function(imageurl,imagerect,start,end,vertical,zindex)
{var markup="";if(start<end)
{var zindexstyle=zindex?('z-index: '+zindex+';'):'';var tilerect=imagerect.clone();var tilingmode=this.mtilingmode;if(vertical)
{tilerect.size.height=math.ceil(end-start);if(imagerect.size.height==1)
{tilingmode=ksfrframestretchtofit;}}
else
{tilerect.size.width=math.ceil(end-start);if(imagerect.size.width==1)
{tilingmode=ksfrframestretchtofit;}}
if(tilingmode==ksfrframestretchtofit)
{markup+=imgmarkup(imageurl,tilerect.position()+zindexstyle);}
else
{var naturalsize=imagerect.size;var offset=(vertical?naturalsize.height:naturalsize.width);var maxtiles=math.ceil((end-start)/offset);if(offset<5||maxtiles>20)
{iwassert(function(){return true},"please remove this assert and the surrouding block.");iwlog("too many frame image tiles are getting generated.  performance may be affected.");}
if(tilingmode==ksfrframestretchevenly)
{offset=(end-start)/maxtiles;if(vertical)
{imagerect.size.height=offset;}
else
{imagerect.size.width=offset;}}
else if(tilingmode==ksfrframeclip)
{markup+='<div style="'+tilerect.position()+'overflow: hidden; ">';imagerect.origin.x=0;imagerect.origin.y=0;}
for(var i=0;i<maxtiles;++i)
{var left=math.round(imagerect.origin.x);var right=math.round(imagerect.origin.x+imagerect.size.width);var top=math.round(imagerect.origin.y);var bottom=math.round(imagerect.origin.y+imagerect.size.height);var roundedrect=new iwrect(left,top,(right-left),(bottom-top));markup+=imgmarkup(imageurl,roundedrect.position()+zindexstyle);if(vertical)
{imagerect=imagerect.offset(0.0,offset);}
else
{imagerect=imagerect.offset(offset,0.0);}}
if(tilingmode==ksfrframeclip)
{markup+="</div>";}}}
return markup;}
