/*
autodemo.js - Script for Autodemo display
(c) Copyright 2011 Autodemo LLC <code@autodemo.com>
*/
if(!window.autodemo)window.autodemo=new function(l,p){var j=this,h,A=null,D=null,F=0,B=/youtube\.com\//i,M=/youtube\.com\/embed\/([^\?]+)/i,C=/.*(iPad|iPhone).*AppleWebKit.*/i.test(l.navigator.userAgent),o="/";o+="";j.ready=false;j.deferAutoPlay=false;var y=function(b,d){for(var e in d)b.setAttribute(e,d[e])},N=function(){for(var b=arguments,d=0,e=b.length,a="",c;d<e;d++){c=b[d];if(c.indexOf(o)==0||/^(http|https):/.test(c))a="";a+=d==e-1?c:c+o}var f=a;if(/^(http|https):/i.test(f))b=f;else{b=f.split(o);
d=[];e=0;a=b.length;c=f.indexOf(o)==0;for(f=f.indexOf(o)==f.length-1;e<a;e++)switch(b[e]){case "..":d.length>0&&d.splice(d.length-1,1);break;case ".":case "":continue;default:d.push(b[e])}b=(c?o:"")+d.join(o)+(f?o:"")}return b},G=function(b){l.location.href=b;return false},H=function(){var b=h(this),d=/^(.+)#(\d+),(\d+)(?:,(.+))?/i,e=function(a){a=b.attr(a||"href");var c,f=true,g,i,q,k={};if(d.test(a)){c=d.exec(a);g=c[1];i=parseInt(c[2],10);q=parseInt(c[3],10);if(c[4])if(c=c[4]){c=c.split("&");k=
0;for(var t=c.length,z={},v;k<t;k++){v=c[k].split("=",2);z[v[0]]=v.length==1?null:v[1]}k=z}else k={};c=j.popup;if(C&&k.v){g=/^\.[^\.]+$/.test(k.v)?g.replace(/\.[^\.]+$/,k.v):N(g.substr(0,g.lastIndexOf(o)+1),k.v);c=G}else if(/\.swf/i.test(g)||B.test(g)&&!C)c=j.overlay.show;else if(B.test(g)&&C){M.exec(g);g="http://www.youtube.com/watch?v="+g+"&autoplay=1&hd=1"}}if(c)f=c(g,i,q);D&&D(a);return f};if(A&&typeof A=="function")return A(this,e);return e()},I=function(b,d){b=h(b);if(b.attr("href").indexOf(d)!=
-1)return true;return false};j.autoPlaySearch=I;var O=function(b){var d,e;b=decodeURIComponent(b);h.each(h(".autodemo"),function(a,c){if(j.autoPlaySearch(c,b))d=h(c)});if(d){e=function(){d.trigger("click")};h.browser.mozilla?h(l).load(e):e()}},E=function(){if(p.body){h(p).delegate(".autodemo","click",H);j.ready=true;j.deferAutoPlay||j.autoplay()}else setTimeout(E,10)},J=function(){if(l.autodemo_jQuery){h=l.autodemo_jQuery;E()}else if(!(F>1E3)){++F;l.setTimeout(J,10)}};j.flembed=new function(){var b=
this,d=null;b.useActiveX=l.ActiveXObject?true:false;b.flashVersion=null;var e=function(){if(b.flashVersion==null){var a;a=0;if(b.useActiveX)b.flashVersion=eval('(function(){try{var plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");return plugin.GetVariable("$version").split(" ")[1].split(",")[0];}catch(err){};})();');else if((a=navigator.plugins["Shockwave Flash"])&&a.description)b.flashVersion=a.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split(".")[0];
a=parseInt(b.flashVersion,10);b.flashVersion=isNaN(a)?0:a}return b.flashVersion};b.setAltContent=function(a){d=typeof a=="string"?h(a)[0]:a};b.object=function(a){var c=e();if(typeof a!="object")return null;if(!a.src)return null;if(!a.width)a.width="100%";if(!a.height)a.height="100%";if(!a.version)a.version=10;if(a.version>c){if(typeof d=="function")return d(c,a);if(!d){a='<div style="text-align: center;"><p style="margin-top: 20px;">This page requires Adobe<sup>&reg;</sup> Flash<sup>&reg;</sup> Player '+
a.version+".</p>";if(c>4)a+="<p>You currently have Flash "+c+" installed.</p>";a+='<p><a href="http://www.adobe.com/go/getflashplayer" target="_blank">Get Adobe Flash Player</a></p></div>';return h(a)[0]}return d}var f,g;if(a.flashVars&&a.flashVars&&a.flashVars.constructor==Object){c=[];for(g in a.flashVars)c.push(g+"="+escape(a.flashVars[g]));a.flashVars=c.join("&")}if(!a.wmode)a.wmode="opaque";c=a.src;var i=a.width,q=a.height;delete a.src;delete a.width;delete a.height;delete a.version;var k="autodemo_flash",
t="application/x-shockwave-flash";f="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";k+="";t+="";f+="";if(b.useActiveX){i='<object id="'+k+'" name="'+k+'" classid="'+f+'" type="'+t+'" width="'+i+'" height="'+q+'">';if(parseInt(h.browser.version,10)<9)f=p.createElement(i);else{f=p.createElement("div");f.innerHTML=i;f=f.firstChild}a.movie=c;for(g in a){c=p.createElement("param");y(c,{name:g,value:a[g]});f.appendChild(c)}}else{f=p.createElement("embed");y(f,{id:k,name:k,type:t,src:c,width:i,height:q});y(f,
a)}return f};e()};j.overlay=new function(){var b,d,e,a,c,f,g,i,q,k=false,t,z=false,v="control_6.swf",K=function(){var m=h(l),r=0;if(e.is(":visible"))r=e.outerHeight();var n=m.width();m=m.height();var w=f.outerWidth()-f.width(),x=f.outerHeight()-f.height()+r,s;s=q-32;w=n-w;x=m-x-32;var u=1;if(w>x){if(i>w)u=w/i}else if(s>x)u=x/s;if(i*u>w)u=w/i;else if(s*u>x)u=x/s;s=[u,i*u,s*u];b.css({width:n,height:m});h(c).css({width:Math.round(s[1]),height:Math.round(s[2])+32});f.css({width:Math.round(s[1]),height:Math.round(s[2])+
r+32});f.css({left:Math.max(0,Math.round((n-f.outerWidth())/2)),top:Math.max(0,Math.round((m-f.outerHeight())/2))})},L=function(){var m,r,n;if(!z){t=h("body");z=true;d=h("<div/>");d.addClass("autodemo-overlay");d.css({position:"fixed",left:0,top:0,"z-index":500});d.hide();b=h("<div/>");b.attr("class","autodemo-background");e=h("<div/>");e.attr("class","autodemo-bar");a=h('<a href="#">Close</a>');a.css({"font-family":"Verdana","font-size":"8pt",color:"#fff","text-decoration":"none"});a.click(function(){autodemo.overlay.hide();
return false});e.append(a);e.css({"background-color":"#003a70","text-align":"right",padding:"3px 10px 3px 3px"});f=h("<div/>");f.attr("class","autodemo-container");f.append(e);d.append(b);d.append(f);t.append(d);b.css({position:"absolute",left:0,top:0,opacity:0.9,"background-color":"#444"});f.css({position:"absolute",left:0,top:0,border:"2px solid #003a70","border-top":"none","background-color":"#fff"});h(l).resize(K);if(/msie/i.test(navigator.userAgent)){m=0;for(r=p.childNodes.length;m<r;m++){n=
p.childNodes[m];if(n.nodeType==8){n=n.nodeValue.toLowerCase();if(n.indexOf("doctype")==0&&n.indexOf("strict")!=-1){k=true;break}}}k&&h(l).scroll(function(){d.css("top",t.scrollTop())})}}};this.controlFile=function(m){m||(m="control_6.swf");v=m};this.hide=function(){L();d.hide();if(c){h(c).remove();c=null}};this.show=function(m,r,n){L();r=parseInt(r,10);n=parseInt(n,10);d.show();g=m;i=r;q=n;f.css({width:r,height:n});if(c){h(c).remove();c=null}if(B.test(g)){c=p.createElement("iframe");y(c,{title:"YouTube video player",
src:g,allowfullscreen:"allowfullscreen",frameborder:"0",border:"0"})}else c=autodemo.flembed.object({src:g.substr(0,g.lastIndexOf(o)+1)+v,allowScriptAccess:"always",flashVars:{demo_url:g.substr(g.lastIndexOf(o)+1),"controls.overlayMode":"true","demo.closeJS":"autodemo.overlay.hide"}});f.append(c);K();return false}};j.clickable=function(b){h(b).click(H)};j.popup=function(b,d,e,a,c,f,g){var i,q;if(C)if(B.test(b)){G(b);return false}else return true;d=parseInt(d,10);e=parseInt(e,10);if(/Macintosh.+Chrome.+Safari/.test(navigator.userAgent))if(i=
/Chrome\/([\d\.]+)/.exec(navigator.userAgent))if(i[1]<"008.000.552.028")e+=50;if(d&&e){i=Math.round((screen.availWidth-d)/2);q=Math.round((screen.availHeight-e)/2);b=l.open(b,!a?"":a,"left="+i+",top="+q+",screenX="+i+",screenY="+q+",width="+d+",height="+e+",resizable="+(f?"yes":"no")+",scrollbars="+(c?"yes":"no")+",toolbar=no,menubar=no,status=no,location=no,directories=no")}else b=l.open(b,!a?"":a);if(g)return b;return false};j.launch=function(b,d,e,a,c,f,g){return j.popup(b,d,e,a,c,f,g)};j.setPreClick=
function(b){A=b};j.setPostClick=function(b){D=b};j.setAutoPlaySearch=function(b){j.autoPlaySearch=b||I};j.autoplay=function(){var b=l.location.hash;b&&b.indexOf("#play:")==0&&O(b.substr(6))};(function(){var b="",d,e,a;if(l.jQuery)if(l.jQuery.fn.offset&&l.jQuery.fn.jquery>="1.4"){h=l.jQuery;E();return}d=p.getElementsByTagName("script");e=0;for(a=d.length;e<a;e++)if(/autodemo\.(?:min\.)?js(?:\?.*)?$/i.test(d[e].getAttribute("src"))){b=d[e].getAttribute("src");b=b.substr(0,b.lastIndexOf(o)+1);break}d=
p.getElementsByTagName("head").item(0);e=p.createElement("script");y(e,{src:b+"jquery.js",type:"text/javascript"});d.appendChild(e);J()})()}(window,document);

