(function(window){if(window.viewsurf){return;}
var viewsurf={};var head=document.head||document.getElementsByTagName("head")[0]||document.documentElement;var vsjQuery=null;var ha_url="http://ha.viewsurf.com/";var version="1.0.1";var readyList=[];viewsurf.xhrs={};viewsurf.version=function(){return version;}
var ajax_hack=function(url,options,callback,useVsXHRs){var script=document.createElement("script");script.type="text/javascript";script.src=url;if(url.indexOf('?')==-1){script.src+="?";}
if(typeof options=="object"){for(var index in options){script.src+="&"+encodeURIComponent(index)+"="+encodeURIComponent(options[index]);}}
var xhr_index=parseInt(Math.random()*1000000);if(useVsXHRs){script.src+="&ajaxvar="+encodeURIComponent("viewsurf.xhrs['"+xhr_index+"']");}
script.onload=script.onreadystatechange=function(_,isAbort){if(isAbort||!script.readyState||/loaded|complete/.test(script.readyState)){script.onload=script.onreadystatechange=null;if(head&&script.parentNode){head.removeChild(script);}
script=undefined;if(!isAbort){if(!useVsXHRs||typeof(viewsurf.xhrs[xhr_index])=="undefined")
callback();else{if(typeof(viewsurf.xhrs[xhr_index])!="object")
viewsurf.xhrs[xhr_index]=decodeURIComponent(viewsurf.xhrs[xhr_index].replace(/\+/g," "));callback(viewsurf.xhrs[xhr_index]);delete viewsurf.xhrs[xhr_index];}}}};head.insertBefore(script,head.firstChild);}
jQueryLoad=function(){if(vsjQuery!=null)
return;ajax_hack("https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js",{},function(data){vsjQuery=jQuery.noConflict(true);for(var index in readyList){readyList[index]();}},false);}
if(typeof(jQuery)!="undefined"){vsjQuery=jQuery;}
else{if(window.document.addEventListener){window.addEventListener("load",jQueryLoad,false);}else if(document.attachEvent){window.attachEvent("onload",jQueryLoad);}}
viewsurf.WeatherReport=function(user_options){var default_options={weatherStationId:null,token:null,idDom:null,mode:null,width:null,height:null,windspeedunit:null,temperatureunit:null,rainunit:null,temperature:null,wind:null,humidity:null,barometry:null,rain:null,c1:null,c2:null,c3:null,lang:null};var options={};for(var index in default_options){if(typeof user_options[index]=="undefined"){if(default_options[index]!=null)
options[index]=default_options[index];}
else if(user_options[index]!=null)
options[index]=user_options[index];}
var me=this;this.drawIn=function(objId){var me=this;if(!vsjQuery){readyList.push(function(){me.drawIn(objId);});return;}
if(options.token==null||options.weatherStationId==null||(options.mode!="flash"&&options.mode!="html")){vsjQuery("#"+objId).html("Invalid parameters");return;}
vsjQuery.ajax({url:ha_url,dataType:'html',type:'post',data:options,success:function(data,textStatus,jqXHR){vsjQuery("#"+objId).html(data);},error:function(jqXHR,textStatus,errorThrown){if(textStatus!="error"){return;}
ajax_hack(ha_url,options,function(data){vsjQuery("#"+objId).html(data);},true);}});}
this.json=function(callback){if(!vsjQuery){readyList.push(function(){me.json(callback);});return;}
if(options.token==null||options.weatherStationId==null||options.mode!="json"){vsjQuery("#"+objId).html("Invalid parameters");return;}
vsjQuery.ajax({url:ha_url,dataType:'json',type:'post',data:options,success:function(data,textStatus,jqXHR){callback(data);},error:function(jqXHR,textStatus,errorThrown){if(textStatus!="error"){return;}
ajax_hack(ha_url,options,function(data){callback(data)},true);}});}}
viewsurf.Media=function(user_options){var default_options={captureId:null,clientId:null,thumbnail:null,token:null,width:null,height:null,liveUser:null}
var options={};for(var index in default_options){if(typeof user_options[index]=="undefined"){if(default_options[index]!=null)
options[index]=default_options[index];}
else if(user_options[index]!=null)
options[index]=user_options[index];}
options["mode"]="ajax";var me=this;this.drawIn=function(objId){if(!vsjQuery){readyList.push(function(){me.drawIn(objId);});return;}
vsjQuery.ajax({url:ha_url,dataType:'html',type:'post',data:options,success:function(data,textStatus,jqXHR){vsjQuery("#"+objId).html(data);},error:function(jqXHR,textStatus,errorThrown){if(textStatus!="error"){return;}
ajax_hack(ha_url,options,function(data){vsjQuery("#"+objId).html(data);},true);}});}}
window.viewsurf=viewsurf;})(window);
