/* Copyright (C) YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

(function(nav,win,doc){if(win.matchMedia&&!nav.userAgent.match(/(iPhone|iPod|iPad)/i)){return}var bool,docElem=doc.documentElement,refNode=docElem.firstElementChild||docElem.firstChild,fakeBody=doc.createElement("body"),div=doc.createElement("div");div.id="mq-test-1";div.style.cssText="position:absolute;top:-100em";fakeBody.style.background="none";fakeBody.appendChild(div);function check(q){div.innerHTML='&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';docElem.insertBefore(fakeBody,refNode);bool=div.offsetWidth==42;docElem.removeChild(fakeBody);return bool}function update(query){var matches=check(query.media);if(query._listeners&&query.matches!=matches){query.matches=matches;for(var i=0,len=query._listeners.length;i<len;i++){query._listeners[i](query)}}}function debounce(func,wait,immediate){var timeout;return function(){var context=this,args=arguments;var later=function(){timeout=null;if(!immediate)func.apply(context,args)};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args)}}win.matchMedia=function(q){var query,ls=[];query={matches:check(q),media:q,_listeners:ls,addListener:function(listener){if(typeof listener==="function")ls.push(listener)},removeListener:function(listener){for(var i=0,len=ls.length;i<len;i++)if(ls[i]===listener)delete ls[i]}};if(win.addEventListener){win.addEventListener("resize",debounce(function(){update(query)},150),false)}if(doc.addEventListener){doc.addEventListener("orientationchange",function(){update(query)},false)}return query}})(navigator,window,document);(function($,win,doc){if($["onMediaQuery"])return;var queries={},supported=win.matchMedia&&win.matchMedia("only all").matches;$(doc).ready(function(){for(var q in queries){var query=$(queries[q]).trigger("init");if(queries[q].matches){$(queries[q]).trigger("valid")}}});$(win).bind("load",function(){for(var q in queries){if(queries[q].matches){$(queries[q]).trigger("valid")}}});$.onMediaQuery=function(q,events){var query=q&&queries[q];if(!query){query=queries[q]=win.matchMedia(q);query.supported=supported;query.addListener(function(){$(query).trigger(query.matches?"valid":"invalid")})}$(query).bind(events);return query}})(jQuery,window,document);