// The ice moon prison awaits Internet Explorer. But until then...

// Browser detection
Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;
Prototype.Browser.iPhone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))




document.observe('dom:loaded', function() {
  // The curly things next to the H1 can't fill an unspecified remaining width. It's impossible in CSS. Helllllo, JS. 
  
  $$('h1').each(function(it) {
    
    it.style.display = "inline-block";
    widthOfText = it.getWidth();
    it.style.display = "block";
    it.style.backgroundPosition = widthOfText + 10 +"px";
    
  });
  
  
  // box-sizing: border-box support for IE7,
  if ( Prototype.Browser.IE6 || Prototype.Browser.IE7 ) {
    
    // For every box (todo: make this generic)
    $$('.box').each(function(box) {
      box.layout = box.getLayout();
      // get its padding, border
      box.paddingLeft = box.layout.get('padding-left');
      box.paddingRight = box.layout.get('padding-right');
      box.borderLeft = parseInt(box.getStyle('border-left-width'),10);
      box.borderRight = parseInt(box.getStyle('border-right-width'),10);
      // get its width
      box.width = box.layout.get('width');
      box.width = box.width - box.paddingLeft - box.paddingRight - box.borderLeft - box.borderRight;
      // set the new width (multiply ems by 10 to convert them to pixels)
      box.setStyle({width: box.width+'px'});
    });
  }
  
  
  // Testimonial byline positioning
  
  $$('.testimonial.small article').each(function(it) {
    it.height = it.getHeight();
    it.byline = it.next('.byline');
    it.byline.height = it.byline.getHeight();
    // Try to centre byline to testimonal's height.
    it.byline.marginTop = (it.height - it.byline.height - 20) / 2;
    it.byline.style.marginTop = it.byline.marginTop + 'px';
  });
  
  
  // Box shadow for IE
  
  if (Prototype.Browser.IE) {
  
    var bodyWidth = $$('section.body').first().measure('border-box-width');
    var bodyHeight = $$('section.body').first().measure('border-box-height');
    
    $('ie_shadow').setStyle({
      width: bodyWidth-1+'px',
      height: bodyHeight+'px'
    });
  
  }
  

});


/*
IE-CSS3.js v0.9.6b - (c) 2009 by Keith Clark, freely distributable under the terms of the MIT license.
www.keithclark.co.uk/labs/ie-css3/
*/
(function(){function G(){var a=location.hash.substring(1);l(t,function(b){k(b,m+"target",a!=""&&b.id==a)})}function w(){k(event.srcElement,m+"hover",event.type=="mouseenter")}function x(){k(event.srcElement,m+"focus",event.type=="focus")}function H(a){u(a,"disabled",true)}function I(a){u(a,"disabled",false,"enabled")}function J(a){u(a,"checked",true)}function u(a,b,d,c){if(a=a.nodeType?a:a.propertyName==b?a.srcElement:null)k(a,m+(c||b),a[b]===d)}function v(a,b,d){for(var c in b){a.attachEvent(c,b[c]);d&&b[c](a)}}function l(a,b){for(var d=a.length-1;d>=0;d--)b(a[d])}function y(a,b){if(/^https?:\/\//.test(a))return b.substring(0,b.indexOf("/",8))==a.substring(0,a.indexOf("/",8))?a:null;if(a.charAt(0)=="/")return b.substring(0,b.indexOf("/",8))+a;if(b.charAt(b.length-1)!="/")b=b.substring(0,b.lastIndexOf("/")+1);return b+a}function p(a){try{return z(a)||[]}catch(b){return[]}}function k(a,b,d){var c=" "+a.className+" ",e=" "+b+" ";if(d){if(c.indexOf(e)>-1)return;a.className+=" "+b}else{if(c.indexOf(e)==-1)return;b=c.replace(e," ").replace(A,"$1");a.className=b}if(a.parentNode)a.parentNode.className+=""}function B(a){var b,d=[];n.open("GET",a,false);n.send();for(var c=K(n.status==200?n.responseText:""),e=0;e<c.imports.length;e++)if(b=y(c.imports[e],a)){b=B(b);d=d.concat(b)}return d.concat(c.a)}function K(a){var b,d,c,e,g,o,C,q,i,f,D=[];a=a.replace(L,"");a=a.replace(M,function(h,U,N){D.push(N);return""});if(e=a.match(O))for(var r=0;r<e.length;r++){ruleSet=P.exec(e[r]);o=ruleSet[1].split(",");C=ruleSet[2];for(var s=0;s<o.length;s++){g=o[s].replace("::",":");if(g.indexOf(":not(")==-1){if(b=E.exec(g))for(;b;){a=b[0];b=b.index;d=a.length;d=b+d;q=g.substring(0,d).replace(A,"$1");i=q.substring(0,q.length-a.length);if(i==""||i.charAt(i.length-1)==" ")i+="*";c=m+a.replace(Q,"").replace(R,"-");switch(a){case ":target":l(p(i),function(h){t.push(h)});break;case ":hover":f={onmouseenter:w,onmouseleave:w};case ":focus":f||(f={onfocus:x,onblur:x});l(p(i),function(h){v(h,f)});f=null;break;case ":checked":f=J;case ":disabled":f||(f=H);case ":enabled":f||(f=I);l(p(i),function(h){S.test(h.tagName)&&v(h,{onpropertychange:f},true)});f=null;break;case ":root":k(document.documentElement,c,true);break;default:l(p(q),function(h){k(h,c,true)});break}g=g.substring(0,b)+"."+c+g.substring(d);b=E.exec(g)}o[s]=g}}e[r]=o.join(" ,")+" {"+C+"}"}return{imports:D,a:e||[]}}var T=/*@cc_on!@*/false,j=/MSIE ([\d])/.exec(navigator.userAgent),n=function(){if(window.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}return null}();if(!(!T||!j||!n||(j=parseInt(j[1]))>8)){var O=/\s*([a-zA-Z\.#@*:\[][\w\W]*?{[^{}]*(}|{[\w\W]*?}\s*}))/g,M=/@import\s*url\(\s*(["'])?(.*?)\1\s*\)[\w\W]*?;/g,L=/\/\*[^*]*\*+([^\/][^*]*\*+)*\//g,P=/^([\w\W]*?)\s*{\s*([\w\W]*?)\s*}$/,Q=/[):\s]/g,R=/[(+]/g,E=new RegExp(":(?:(?:(?:"+(j<7?"first|":"")+"last|only)-child|(?:only|first|last)-of-type|empty|root|checked|enabled|disabled"+(j<7?"|hover":"")+(j<8?"|focus":"")+(j==8?"|target":"")+")|(?:(?:nth-(?:last-)?(?:child|of-type))\\(([^)]*?)\\)))","g"),A=/^\s*((?:[\S\s]*\S)?)\s*$/,S=/^(INPUT|SELECT|BUTTON)$/,z,m="iecss3-",t=[],F={NW:"NW.Dom.select",DOMAssistant:"DOMAssistant.$",Prototype:"$$",YAHOO:"YAHOO.util.Selector.query",MooTools:"$$",Sizzle:"Sizzle",jQuery:"jQuery",dojo:"dojo.query"};document.write("<script id=iecss3DOMReady defer src='//:'><\/script>");document.getElementById("iecss3DOMReady").onreadystatechange=function(){if(this.readyState=="complete"){var a;a:{for(a in F)if(window[a])if(z=eval(F[a])){a=true;break a}a=false}if(a){var b;a=document.getElementsByTagName("BASE");for(var d=a.length>0?a[0].href:document.location.href,c=0;c<document.styleSheets.length;c++){a=document.styleSheets[c];if(a.href!="")if(b=y(a.href,d))a.cssText=B(b).join("\n")}t.length>0&&v(window,{onhashchange:G},true);this.parentNode.removeChild(this)}}}}})();



window.onscroll = function()
{
  if (!Prototype.Browser.IE && !Prototype.Browser.Gecko && !Prototype.Browser.iPhone && $('secondary')) // avoid IE
  {
    it = $('secondary');
    space = $('secondary_spaceholder');
    s = document.documentElement.scrollTop;
    x = self.pageYOffset;
    if (s > 186 || x > 186)
    {
      it.style.position = 'fixed';
      it.style.top = '10px';
      // e is now floating, doesn't wrap, so create something that fills its space
      space.show();
    }
    else
    {
      it.style.position = 'relative';
      space.hide();
    }
  }
}

  
// After all images are loaded,  
Event.observe(window, 'load', function() {
  
  // Masonry for the price list
  // HAVE TO do this after all the images load!
  if ($('as'))
    new Masonry($('as'),{itemSelector: '.item'});
  
  // Masonry for workshops
  if ($$('.workshop').first()) {
    //new Masonry($('minor_workshops'),{itemSelector: '.workshop.minor'});
  }
  
  
  // Box shadow for IE
  
  if (Prototype.Browser.IE) {
  
    var bodyWidth = $$('section.body').first().measure('border-box-width');
    var bodyHeight = $$('section.body').first().measure('border-box-height');
    
    $('ie_shadow').setStyle({
      width: bodyWidth-1+'px',
      height: bodyHeight+'px'
    });
  
  }
    
});
