/*

shared-javascript.js

Shared JavaScript functions.

Except where stated otherwise:

(C) 2011 Spoton.net Limited - http://spoton.net/
Created by Stephen Morley - http://stephenmorley.org/

*/

// prevent framing
if (window.top!=window.self&&(window.location.href.indexOf('itseeze.co.uk')!=-1||window.location.href.indexOf('spotonnet.co.uk')!=-1||window.location.href.indexOf('spotoncorporation.co.uk')!=-1)){window.top.location.replace('http://spotonnet.co.uk/frames/?url='+encodeURIComponent(window.location.href));}

// old lightbox implementation
function webeditLightbox(_1,_2,_3){var _4=0;var _5=0;if(window.innerWidth){_4=window.innerWidth;_5=window.innerHeight;}else{if(document.documentElement&&document.documentElement.clientWidth){_4=document.documentElement.clientWidth;_5=document.documentElement.clientHeight;}else{if(document.body&&document.body.clientWidth){_4=document.body.clientWidth;_5=document.body.clientHeight;}}}if(_4&&_5){var _6=_4-48;var _7=_5-76;if(_6>_2&&_7>_3){_6=_2;_7=_3;}else{if(_6*_3>_2*_7){_6=Math.round(_7*_2/_3);}else{_7=Math.round(_6*_3/_2);}}var _8=document.createElement("div");_8.id="webeditCoreLightbox";_8.onclick=function(){document.body.removeChild(document.getElementById("webeditCoreLightbox"));};_8.innerHTML="<div style=\"top:"+Math.floor((_5-_7)/2-26)+"px;left:"+Math.floor((_4-_6)/2-12)+"px;\">"+"<img src=\""+_1.replace(/%%width%%/g,_6).replace(/%%height%%/g,_7)+"\" width=\""+_6+"\" height=\""+_7+"\">"+(window.XMLHttpRequest?"<br><span>Click to close this box</span>":"")+"</div>";if(!window.XMLHttpRequest){_8.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+WebEdit.ROOT_PATH+"_webedit/images/semitransparent-black-block.png\",sizingMethod=\"scale\")";_8.style.width=document.documentElement.scrollWidth;_8.style.height=document.documentElement.scrollHeight;_8.firstChild.style.top=document.documentElement.scrollTop+12;}document.body.appendChild(_8);}};

// new lightbox implementation
WebEdit.Lightbox=new function(){var _1={};var _2=null;var _3=null;var _4=0;var _5=20;var _6=null;this.register=function(id,_7,_8,_9,_a){_1[id]={url:_7,width:_8,height:_9,caption:_a};};function _b(){var _c=[];for(id in _1){var x=0;var y=0;var _d=document.getElementById(id);if(_d){do{x+=_d.offsetLeft;y+=_d.offsetTop;_d=_d.offsetParent;}while(_d&&_d.nodeName!="BODY");}_c.push({id:id,x:x,y:y});}_c.sort(function(_e,_f){return (_e.y==_f.y?_e.x-_f.x:_e.y-_f.y);});for(var _10=0;_10<_c.length;_10++){_1[_c[_10].id].previous=_c[(_10+_c.length-1)%_c.length].id;_1[_c[_10].id].next=_c[(_10+1)%_c.length].id;}};this.show=function(id){if(!("next" in _1[id])){_b();}_6=id;var _11=(_1[id].next==id);var _12=document.createElement("div");_12.id="webeditLightboxToolbar";_12.style.marginLeft=(_11?"-29px":"-85px");var _13=document.createElement("div");_12.appendChild(_13);if(!_11){_13.appendChild(_14("\u25c0",_15));}_13.appendChild(_14("\u00d7",_16));if(!_11){_13.appendChild(_14("\u25b6",_17));}_2=document.createElement("div");_2.id="webeditLightboxCover";_2.style.width=document.documentElement.scrollWidth+"px";_2.style.height=document.documentElement.scrollHeight+"px";_2.appendChild(_12);document.body.appendChild(_2);if(document.addEventListener){document.addEventListener("keydown",_18,false);document.addEventListener("mousedown",_19,false);}else{document.attachEvent("onkeydown",_18);document.attachEvent("onselectstart",_19);}_1a();_1b();};function _14(_1c,_1d){var _1e=document.createElement("span");_1e.appendChild(document.createTextNode(_1c));if(_1e.addEventListener){_1e.addEventListener("click",_1d,false);}else{_1e.attachEvent("onclick",_1d);}return _1e;};function _18(e){switch((e?e:window.event).keyCode){case 27:_16();break;case 37:_15();break;case 39:_17();break;}};function _19(e){if(!e){e=window.event;}if(e.preventDefault){e.preventDefault();}else{e.returnValue=false;}};function _1f(id){var _20={showCaption:(_1[id].caption&&_1[id].caption.length>0),viewportWidth:document.documentElement.clientWidth,viewportHeight:document.documentElement.clientHeight};_20.width=_20.viewportWidth-52;_20.height=_20.viewportHeight-(_20.showCaption?132:108);if(_1[id].width<=_20.width&&_1[id].height<=_20.height){_20.width=_1[id].width;_20.height=_1[id].height;}else{var _21=_1[id].width/_1[id].height;if(_20.width/_20.height>_21){_20.width=Math.round(_20.height*_21);}else{_20.height=Math.round(_20.width/_21);}}_20.url=_1[id].url.replace(/<width>/g,_20.width).replace(/<height>/g,_20.height);return _20;};this.preload=function(id){var _22=_1f(id);var _23=document.createElement("img");_23.setAttribute("src",_22.url);};function _1a(){WebEdit.Lightbox.preload(_1[_6].previous);WebEdit.Lightbox.preload(_1[_6].next);var _24=_1f(_6);_3=document.createElement("div");_3.id="webeditLightboxFrame";_3.style.width=(_24.width+18)+"px";_3.style.top=Math.round((_24.showCaption?6:18)+(_24.viewportHeight-_24.height)/2)+"px";_3.style.left="50%";_3.style.marginLeft="-"+(_24.width/2+10)+"px";var _25=document.createElement("div");_3.appendChild(_25);_2.appendChild(_3);var _26=document.createElement("img");_26.setAttribute("src",_24.url);_26.setAttribute("width",_24.width);_26.setAttribute("height",_24.height);_25.appendChild(_26);if(_24.showCaption){var _27=document.createElement("span");_27.appendChild(document.createTextNode(_1[_6].caption));_25.appendChild(_27);}};function _16(){if(_4==10){_28();}};function _28(){_4--;_2.style.opacity=_4/10;if(!Array.prototype.indexOf){_4=0;}if(_4>0){window.setTimeout(_28,20);}else{document.body.removeChild(_2);if(document.removeEventListener){document.removeEventListener("keydown",_18,false);document.removeEventListener("mousedown",_19,false);}else{document.detachEvent("onkeydown",_18);document.detachEvent("onselectstart",_19);}}};function _1b(){_4++;_2.style.opacity=_4/10;if(!Array.prototype.indexOf){_4=10;}if(_4<10){window.setTimeout(_1b,20);}};function _15(e){if(_5==20){_6=_1[_6].previous;_29();}};function _17(){if(_5==20){_6=_1[_6].next;_29();}};function _29(){_5--;_3.style.opacity=_5/20;if(!Array.prototype.indexOf){_5=0;}if(_5>0){window.setTimeout(_29,20);}else{_2.removeChild(_3);_1a(_6);_2a();}};function _2a(){_5++;_3.style.opacity=_5/20;if(!Array.prototype.indexOf){_5=20;}if(_5<20){window.setTimeout(_2a,20);}};}();

// shows and hides drop-downs
WebEdit.DropDown={lastShow:0,hide:function(){var _1=document.getElementById("webeditDropDownCover");if(_1){document.body.removeChild(_1);var _2=document.getElementsByTagName("ul");for(var _3=0;_3<_2.length;_3++){if(_2[_3].parentNode.className=="webeditDropdownChildren"){_2[_3].style.display="none";}}}},show:function(_4){WebEdit.DropDown.hide();var _5=document.createElement("div");_5.id="webeditDropDownCover";_5.style.width=document.documentElement.scrollWidth+"px";_5.style.height=document.documentElement.scrollHeight+"px";_5.onclick=WebEdit.DropDown.hide;_5.onmouseover=WebEdit.DropDown.hide;document.body.appendChild(_5);var _6=_4.getElementsByTagName("ul");if(_6.length>0){_6[0].style.display="block";}WebEdit.DropDown.lastShow=(new Date()).getTime();},showOrGo:function(_7){if((new Date()).getTime()<WebEdit.DropDown.lastShow+100){return false;}var _8=_7.getElementsByTagName("ul");if(_8.length>0&&_8[0].style.display!="block"){WebEdit.DropDown.show(_7);return false;}else{return true;}}};

// dynamically resizes components on mobile devices
WebEdit.MobileResizer={iframes:{},colourblocks:{},initialise:function(_1){this.scaleFactor=_1;this.resize();if(window.addEventListener){window.addEventListener("resize",this.resize,false);}else{if(window.attachEvent){window.attachEvent("onresize",this.resize);}}},resize:function(){for(var _2 in WebEdit.MobileResizer.iframes){var _3=WebEdit.MobileResizer.iframes[_2];var _4=document.getElementById(_2);var _5=_4.clientWidth;var _4=_4.getElementsByTagName("iframe")[0];var _6=Math.floor(_3.width*_5);var _7=Math.floor(_3.height*_5);_4.style.width=_6+"px";if(_7){_4.style.height=_7+"px";}var _8=_3.url;_8=_8.replace("<width>",_6);if(_7){_8=_8.replace("<height>",_7-_3.adjust);}_4.setAttribute("src",_8);}document.body.style.fontSize=Math.round(document.documentElement.scrollWidth*WebEdit.MobileResizer.scaleFactor)+"px";for(var _2 in WebEdit.MobileResizer.colourblocks){var _9=WebEdit.MobileResizer.colourblocks[_2];var _4=document.getElementById(_2);var _6=_4.clientWidth;var _4=_4.getElementsByTagName("div")[2];if(_9.border>0){_4.style.borderWidth=Math.max(1,Math.floor(_9.border*_6))+"px";}if(_9.radius>0){_4.style.borderRadius=Math.floor(_9.radius*_6)+"px";}}},registerIframe:function(_a,_b,_c,_d,_e){this.iframes[_a]={"url":_b,"width":_c,"height":_d,"adjust":(_e?_e:0)};},registerColourblock:function(_f,_10,_11){this.colourblocks[_f]={"border":_10,"radius":_11};}};

/*

The following code was written by Stephen Morley independently from his
employment at Spoton.net Limited, and he retains copyright. The code is
available from http://code.stephenmorley.org/ and is released under the
terms of the CC0 1.0 Universal legal code:

http://creativecommons.org/publicdomain/zero/1.0/legalcode

*/

var OnloadScheduler=new function(){this.allTasksExecuted=false;var _1=false;var _2=new Array();var _3=new Array();this.executeAllTasks=function(){if(!OnloadScheduler.allTasksExecuted){OnloadScheduler.allTasksExecuted=true;for(var i=_2.length-1;i>0;i--){_4(_2[i]);}for(var i=0;i<_3.length;i++){_4(_3[i]);}}};function _4(_5){if(_5){for(var i=0;i<_5.length;i++){try{_5[i]();}catch(e){}}}};function _6(){if(!_1){_1=true;if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){document.removeEventListener("DOMContentLoaded",arguments.callee,false);OnloadScheduler.executeAllTasks();},false);}else{if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState=="complete"){document.detachEvent("onreadystatechange",arguments.callee);OnloadScheduler.executeAllTasks();}});if(document.documentElement.doScroll&&window==window.top){(function(){if(!OnloadScheduler.allTasksExecuted){try{document.documentElement.doScroll("left");OnloadScheduler.executeAllTasks();}catch(error){setTimeout(arguments.callee,0);}}})();}window.onload=function(){OnloadScheduler.executeAllTasks();};}}}};this.schedule=function(_7,_8){_6();if(_7 instanceof Function){if(!_8){_8=0;}if(_8<0){if(_2[-_8]){_2[-_8].push(_7);}else{_2[-_8]=[_7];}}else{if(_3[_8]){_3[_8].push(_7);}else{_3[_8]=[_7];}}}else{this.schedule(function(){eval(_7);},_8);}};};

var ImagePreloader=new function(){var _1=[];this.schedule=function(_2,_3,_4,_5){OnloadScheduler.schedule(createPreloadClosure(_2,_4,_5),_3);};function createPreloadClosure(_6,_7,_8){return function(){var _9=new Image();if(_7 instanceof Function){_9.onload=_7();}if(_8 instanceof Function){_9.onerror=_8();}_9.src=_6;_1.push(_9);};}}();

// see http://code.stephenmorley.org/javascript/using-cookies/
var Cookies={get:function(_1,_2){
var _3=[];
var _4=document.cookie.split(/; */);
for(var _5=0;_5<_4.length;_5++){
var _6=_4[_5].split("=");
if(_6[0]==_1){
_3.push(decodeURIComponent(_6[1]));
}
}
return (_2?_3:_3[0]);
},set:function(_7,_8,_9,_a,_b,_c){
var _d=[_7+"="+encodeURIComponent(_8)];
if(typeof _9=="number"){
_9=new Date((new Date()).getTime()+_9*86400000);
}
if(_9){
_d.push("expires="+_9.toGMTString());
}
if(_a){
_d.push("path="+_a);
}
if(_b){
_d.push("domain="+_b);
}
if(_c){
_d.push("secure");
}
document.cookie=_d.join("; ");
},clear:function(_e){
this.set(_e,"",-1);
}};

// see http://code.stephenmorley.org/javascript/fading-transition-effects/
function Fader(_1,_2){
if(typeof _1=="string"){
_1=document.getElementById(_1);
}
this.rate=0.05/(_2?_2:0.5);
_1.style.position="relative";
var _3=0;
var _4=0;
this.panels=[];
this.target=0;
var _5=_1.firstChild;
do{
if(_5.nodeType==1){
_3=Math.max(_3,_5.offsetWidth);
_4=Math.max(_4,_5.offsetHeight);
_5.style.position="absolute";
_5.style.top=0;
_5.style.left=0;
this.panels.push({node:_5,opacity:(this.panels.length==0?1:0)});
}
}while(_5=_5.nextSibling);
_1.style.minWidth=_3+"px";
_1.style.minHeight=_4+"px";
this.useOpacity="opacity" in document.documentElement.style;
this.setTarget(0);
var _6=this;
window.setInterval(function(){
_6.setPanelOpacity(_6.target,_6.panels[_6.target].opacity+_6.rate);
},50);
};
Fader.prototype.setTarget=function(_7){
if("timeout" in this){
window.clearTimeout(this.timeout);
}
this.panels[this.target].contribution=this.panels[this.target].opacity;
var _8=1-this.panels[this.target].opacity;
for(var _9=0;_9<this.panels.length;_9++){
if(_9!=this.target){
this.panels[_9].contribution=_8*this.panels[_9].opacity;
_8*=(1-this.panels[_9].opacity);
}
}
this.setPanelOpacity(_7,this.panels[_7].contribution);
this.panels[_7].node.style.zIndex=this.panels.length;
_8=1-this.panels[_7].opacity;
var _a=this.panels.length;
for(var _9=0;_9<this.panels.length;_9++){
if(_9!=_7){
this.setPanelOpacity(_9,this.panels[_9].contribution/_8);
_8-=this.panels[_9].contribution;
_a--;
this.panels[_9].node.style.zIndex=_a;
}
}
this.target=_7;
if("timeout" in this){
if(this.listener){
this.listener();
}
this.setInterval(this.interval,this.listener);
}
};
Fader.prototype.setPanelOpacity=function(_b,_c){
if(isNaN(_c)){
_c=0;
}
if(_c>1){
_c=1;
}
this.panels[_b].opacity=_c;
if(this.useOpacity){
this.panels[_b].node.style.opacity=_c;
}else{
this.panels[_b].node.style.filter="alpha(opacity="+(100*_c)+")";
}
};
Fader.prototype.setInterval=function(_d,_e){
this.interval=_d;
this.listener=_e;
var _f=this;
this.timeout=window.setTimeout(function(){
_f.setTarget((_f.target+1)%_f.panels.length);
},_d*1000);
};
Fader.prototype.clearInterval=function(){
if("timeout" in this){
window.clearTimeout(this.timeout);
delete this.timeout;
}
};

// see http://code.stephenmorley.org/javascript/smooth-movement/
function SmoothMovement(_1,_2){
this.position=_1;
this.target=_2;
this.velocity=0;
this.animationInterval=null;
};
SmoothMovement.prototype.update=function(){
if(this.velocity<0){
if(this.target>this.position-this.velocity*(this.velocity-1)/2){
this.velocity++;
}else{
if(this.target<=this.position-(this.velocity-1)*(this.velocity-2)/2){
this.velocity--;
}
}
}else{
if(this.target<this.position+this.velocity*(this.velocity+1)/2){
this.velocity--;
}else{
if(this.target>=this.position+(this.velocity+1)*(this.velocity+2)/2){
this.velocity++;
}
}
}
this.position+=this.velocity;
return this.position;
};
SmoothMovement.prototype.hasStopped=function(){
return (this.position==this.target&&this.velocity==0);
};
SmoothMovement.prototype.animate=function(_3,_4,_5){
if(this.animationInterval){
window.clearInterval(this.animationInterval);
}
this.animationInterval=window.setInterval(this.createAnimationClosure(_4,_5),_3);
};
SmoothMovement.prototype.createAnimationClosure=function(_6,_7){
var _8=this;
return function(){
_8.update();
_6(_8.position,_8);
if(_8.hasStopped()){
window.clearInterval(_8.animationInterval);
_8.animationInterval=null;
if(_7){
_7(_8);
}
}
};
};

