$("#s").css("color","#ccc")
swap_val=[];$("#s").each(function(i){swap_val[i]=$(this).val();$(this).focusin(function(){$(this).css("color","black");if($(this).val()==swap_val[i]){$(this).val("");}}).focusout(function(){if($.trim($(this).val())==""){$(this).val(swap_val[i]);$(this).css("color","#ccc");}});});

var searchwait = 0;
var msgonce = false;
var lasttip = false;
var tips = {};
var tooltipwait = 0;
var cv = false;
var oun = '';
var unok = true;



var is_iphone = ((navigator.userAgent.toLowerCase().indexOf("iphone") > -1) || (navigator.userAgent.toLowerCase().indexOf("ipod") > -1));
var is_ipad = ((navigator.userAgent.toLowerCase().indexOf("ipad") > -1));

jQdefer = function(delay, callback) {
	var timer;

	// Return the callback proxy
	return function() {
		// Save the vars for the real callback
		var that = this, args = arguments;

		// Reset the delay
		window.clearTimeout(timer);

		// Delay the real callback
		timer = window.setTimeout(function() {
			callback.apply(that, args);
		}, delay);
	};
};


$(document).ready(function(){
  
if ($('#js-settings-form').length) {

  oun = $('#sched-username').val();
  $('#sched-username').focus(function(){unnotify('un-ok', 'Type to change your username.')});
  $('#sched-username').keyup(function(){validateusername($(this).val())}).blur(function(){validateusername($(this).val())});
  
  $('#js-settings-form').submit(function() {
    if (!cv) {
      cv = true;
      $('.js-confirm-settings').slideDown(200, function(){$('#pass-confirm').focus()});
      return false;
    }
    
    if (cv) {
      if (!unok) {
        alert('Correct your username'); window.location = '#un-label'; return false;
      } else if ($.trim($('#pass-confirm').val())) return true;
      else { 
        conotify('un-no', 'Enter your password to save profile');
        $('#pass-confirm').focus();
        return false;
      }
    }
  });
   
}
  
$('.js-disconnect-profile').click(
      function() {
        $.get('/profile?disconnect=me', {}, function(d) {
          if ('ok' == d) {
            window.location = '/profile';
          } else {
            alert("Oops, we couldn't disconnect your profiles\nPlease try again");
          }
        });
        
      }
    ).css({'text-decoration': 'underline', 'cursor': 'pointer'}); 
  
  
$("span.outer-links a").attr('target', '_blank');
$(".past_block").addClass('clickable')
.click(function(){
	var idx = $(this).attr('rel');
	var status = $(this).attr('rev');

	if(status != 'hidden'){
		$(this).attr('rev','hidden');
		$("tr[rel='past_"+idx+"']").hide();
	} else {
		$(this).attr('rev','');
		$("tr[rel='past_"+idx+"']").show();
	}

})
.click();
});

var delayedHideTooltipTimer = false;
function delayedHideTooltip() {
    if (delayedHideTooltipTimer)
        clearTimeout(delayedHideTooltipTimer);

    delayedHideTooltipTimer = setTimeout(function() {
        $("#tip").hide();
    }, 0);
}
function delayedHideTooltipCancel() {
    if (delayedHideTooltipTimer) {
        clearTimeout(delayedHideTooltipTimer);
        delayedHideTooltipTimer = false;
    }
}


// main
$(function() {

    if(!is_iphone && !is_ipad) {
        $("#tip").hover(delayedHideTooltipCancel, delayedHideTooltip);
        $("body").click(function() { lasttip = false; delayedHideTooltipCancel(); $("#tip").hide(); });
    }
    
    if (!is_iphone) {
        // load all tooltips, and store them to the cache
        if (!showfull && ci != 'austin2011') {
          $.getJSON("/event-get-all-tooltips?page="+page, function(data, textStatus) { tips = data; });
        }
    }
    
/*  if($.browser.msie)
  {
    $("ul.lev1 li:has(ul)").hover(function() { $(this).addClass("over"); }, function() { $(this).removeClass("over"); });
    $("ul.lev1 li:has(.scr)").hover(function() { $(this).addClass("over"); }, function() { $(this).removeClass("over"); });
    $("ul#menu li:has(ul)").hover(function() { $(this).addClass("over"); }, function() { $(this).removeClass("over"); });
  }

  if((typeof(no_resize) == "undefined" || !no_resize) && !is_iphone && !$.browser.msie) // all except ie/iphone
  {
    $(window).resize(function() {
      $("#pagetext").css("margin-top", $("#header").height() - 70 + 10); // -(padding-top) + gap
    });
    $(window).resize();
  }
*/
});

function saveEvent(lnk) {
  if(username != "")
  {
    
    if ($('span.interested_no').length) {
      if ($('.sub').length && $('span.interested_no').text() == '1') {
        $('span.interested_no').text('0');
      } else {
        $('span.interested_no').text('1');
      }
    }
    
    if ($('#page-event').length) {
      if ($('.sub').length) {
        $('#sched-page-event-attendees').prepend('<p class="sched-bethefirst"><a href="#" onclick="saveEvent(\''+lnk+'\');return false;">Be the first one to attend.</a></p>');      } else {
        if ($('p.sched-bethefirst').length) {
          $('p.sched-bethefirst').remove();
        }
      }
    }
    
    if(lnk.id)
    {
      if($(lnk).hasClass("sub"))
      {
        $(lnk).removeClass("sub");
        if (is_ipad) {
          //$(lnk).css('background', 'url("/img/mobile-check-small.png") no-repeat scroll 0 3px transparent');
        }
        //lnk.innerHTML = "ATTEND";
        //lnk.innerHTML = g_abl;
        $.get("/event-set?del=" + lnk.id);
      }
      else
      {
        $(lnk).addClass("sub");
        //lnk.innerHTML = "LEAVE";
        //lnk.innerHTML = g_lbl;
        $.get("/event-set?add=" + lnk.id);
      }
    }
    else
    {
      var id = lnk;
      var prli = $("#" + id).parent();
      if(prli.hasClass("sub"))
      {
        prli.removeClass("sub");
        $.get("/event-set?del=" + id);
      }
      else
      {
        prli.addClass("sub");
        $.get("/event-set?add=" + id);
      }
    }
  }
  else if(!msgonce)
  {
    alert(L10n['js::login']);
    msgonce = true;
  }
}

// date picker related
function setupDatePicker(es, ed)
{
  var cal;
  var $this;

  var checkForMouseout = function(event)
  {
    var el = event.target;
    while (true){
      if (el == cal || el == document.getElementById("toolbar")) {
        return true;
      } else if (el == document) {
        $this.dpClose();
        return false;
      } else {
        el = $(el).parent()[0];
      }
    }
  };

  Date.format = 'mm/dd/yyyy';

  $('.date-pick').datePicker({
    startDate:es,
    endDate:ed
  }).bind("dateSelected", function(e, sd, td) {
    document.location.href = "/cal/" + sd.getFullYear() + (sd.getMonth()+1 < 10 ? "0" : "") + (sd.getMonth()+1) + (sd.getDate() < 10 ? "0" : "") + sd.getDate();
  }).bind(
    'dpDisplayed',
    function(event, datePickerDiv)
    {
      cal = datePickerDiv;
      $this = $(this);
      $(document).bind(
        'mouseover',
        checkForMouseout
      );
    }
  ).bind(
    'dpClosed',
    function(event, selected)
    {
      $(document).unbind(
        'mouseover',
        checkForMouseout
      );
    }
  ).dpSetOffset($("#header").height(), 0);
  $("#caldatebtn").click(function() { $('#caldate').dpDisplay(); return false; }).mouseover(function() { $('#caldate').dpDisplay(); });
  $("#toolbar li.lev1").mouseout(function() {
    if(!$(this).hasClass("ldate"))
      $('#caldate').dpClose();
  });
}

function showToolTip(lnk)
{
  
  var el = $(lnk);
  var tx = el.offset().left + 7;
  tx = Math.min(tx, $(window).width() - 400);
  
  if (el.hasClass('sched-page-grid-event')) {
    var strng = el.find('p');
    var ty = strng.offset().top + el.height()/* + parseInt(el.css('margin-top'))*/;
    var id = el.find(".sched-page-grid-event-name").attr("id");
  } else {
    var ty = el.offset().top + el.height() + 4;
    var id = el.find(".name").attr("id");
  }
  
  
  if (!is_ipad) {
    delayedHideTooltipCancel();
  }
  
  if(tips[id] == undefined)
  {
    clearTimeout(tooltipwait);
    tooltipwait = setTimeout(function() {
      $("#tip").html("<img id=\"tip-loading\" src=\"http:\/\/wpc.3CFB.edgecastcdn.net\/003CFB\/loading.gif\" \/>").show().css({left: tx + "px", top: ty + "px"});
      $.get("/event-get?page="+page+"&tooltip=" + id, function(ret) { tips[id] = ret; $("#tip").html(ret); });
    }, 400);
     
  }
  else
  {
    $("#tip").html(tips[id]).show().css({left: tx + "px", top: ty + "px"});
    //var nh = parseInt($('#tip').css('top')) - $('#tip').height() + 30;
    //$("#tip").css({top: nh + "px", visibility: 'visible'});
    $("#tip span.outer-links a").attr('target', '_blank');
  }
}

function showToolTipMobile(lnk)
{
  var el = $(lnk);
  var id = el.find("a.name").attr("id");
  if(lasttip == id)
  {
    lasttip = false;
    $("#tip").hide();
    return;
  }

  lasttip = id;
  var tx = el.offset().left + 1;
  tx = Math.min(tx, $(window).width() - 440) + 130;
  var ty = el.offset().top + el.height() + 22;

  if(tips[id] == undefined)
  {
    $("#tip").html(L10n['loading']).show().css({left: tx + "px", top: ty + "px"});
    $.get("/event-get?page="+page+"&tooltip=" + id, function(ret) { tips[id] = ret; $("#tip").html(ret); });
  }
  else
  {
    $("#tip").html(tips[id]).show().css({left: tx + "px", top: ty + "px"});
  }
}

function toggleInfo(lnk, id)
{
  if($(lnk).html().substr(0, 4) == L10n['more'])
  {
    $(lnk).html("<< " + L10n['less']);
    if($("#infobox_" + id).html() == "")
    {
      $("#infobox_" + id).html("<b>" + L10n['loading'] + "</b>");
      $("#inforow_" + id).show();
      $.get("/event-get?more=" + id, function(ret) { $("#infobox_" + id).html(ret); });
    }
    else
    {
      $("#inforow_" + id).show();
    }
  }
  else
  {
    $(lnk).html(L10n['more'] + " >>");
    $("#inforow_" + id).hide();
  }

  return false;
}

function printme(text)
{
  text=document;
  print(text);
}

$(document).ready(function() {
  $('#embed').hide();
  $('a#embed-toggle').click(function() {
    $('#embed').toggle(100);
    return false;
  });
});


/*
 * Thickbox 3 - Cody Lindley http://codylindley.com
 * used for .ics popup
*/

var tb_pathToImage = "http://static.sched.org/img/loadingAnimation.gif";

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(o).2S(9(){1u(\'a.18, 3n.18, 3i.18\');1w=1p 1t();1w.L=2H});9 1u(b){$(b).s(9(){6 t=X.Q||X.1v||M;6 a=X.u||X.23;6 g=X.1N||P;19(t,a,g);X.2E();H P})}9 19(d,f,g){3m{3(2t o.v.J.2i==="2g"){$("v","11").r({A:"28%",z:"28%"});$("11").r("22","2Z");3(o.1Y("1F")===M){$("v").q("<U 5=\'1F\'></U><4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}n{3(o.1Y("B")===M){$("v").q("<4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}3(1K()){$("#B").1J("2B")}n{$("#B").1J("2z")}3(d===M){d=""}$("v").q("<4 5=\'K\'><1I L=\'"+1w.L+"\' /></4>");$(\'#K\').2y();6 h;3(f.O("?")!==-1){h=f.3l(0,f.O("?"))}n{h=f}6 i=/\\.2s$|\\.2q$|\\.2m$|\\.2l$|\\.2k$/;6 j=h.1C().2h(i);3(j==\'.2s\'||j==\'.2q\'||j==\'.2m\'||j==\'.2l\'||j==\'.2k\'){1D="";1G="";14="";1z="";1x="";R="";1n="";1r=P;3(g){E=$("a[@1N="+g+"]").36();25(D=0;((D<E.1c)&&(R===""));D++){6 k=E[D].u.1C().2h(i);3(!(E[D].u==f)){3(1r){1z=E[D].Q;1x=E[D].u;R="<1e 5=\'1X\'>&1d;&1d;<a u=\'#\'>2T &2R;</a></1e>"}n{1D=E[D].Q;1G=E[D].u;14="<1e 5=\'1U\'>&1d;&1d;<a u=\'#\'>&2O; 2N</a></1e>"}}n{1r=1b;1n="1t "+(D+1)+" 2L "+(E.1c)}}}S=1p 1t();S.1g=9(){S.1g=M;6 a=2x();6 x=a[0]-1M;6 y=a[1]-1M;6 b=S.z;6 c=S.A;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}n 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}13=b+30;1a=c+2G;$("#8").q("<a u=\'\' 5=\'1L\' Q=\'1o\'><1I 5=\'2F\' L=\'"+f+"\' z=\'"+b+"\' A=\'"+c+"\' 23=\'"+d+"\'/></a>"+"<4 5=\'2D\'>"+d+"<4 5=\'2C\'>"+1n+14+R+"</4></4><4 5=\'2A\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4>");$("#Z").s(G);3(!(14==="")){9 12(){3($(o).N("s",12)){$(o).N("s",12)}$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1D,1G,g);H P}$("#1U").s(12)}3(!(R==="")){9 1i(){$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1z,1x,g);H P}$("#1X").s(1i)}o.1h=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}n 3(I==3k){3(!(R=="")){o.1h="";1i()}}n 3(I==3j){3(!(14=="")){o.1h="";12()}}};16();$("#K").C();$("#1L").s(G);$("#8").r({Y:"T"})};S.L=f}n{6 l=f.2r(/^[^\\?]+\\??/,\'\');6 m=2p(l);13=(m[\'z\']*1)+30||3h;1a=(m[\'A\']*1)+3g||3f;W=13-30;V=1a-3e;3(f.O(\'2j\')!=-1){1E=f.1B(\'3d\');$("#15").C();3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4></4><U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\' > </U>")}n{$("#B").N();$("#8").q("<U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\'> </U>")}}n{3($("#8").r("Y")!="T"){3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\'>1l</a> 1k 1j 1s</4></4><4 5=\'F\' J=\'z:"+W+"p;A:"+V+"p\'></4>")}n{$("#B").N();$("#8").q("<4 5=\'F\' 3c=\'3b\' J=\'z:"+W+"p;A:"+V+"p;\'></4>")}}n{$("#F")[0].J.z=W+"p";$("#F")[0].J.A=V+"p";$("#F")[0].3a=0;$("#1H").11(d)}}$("#Z").s(G);3(f.O(\'37\')!=-1){$("#F").q($(\'#\'+m[\'26\']).1T());$("#8").24(9(){$(\'#\'+m[\'26\']).q($("#F").1T())});16();$("#K").C();$("#8").r({Y:"T"})}n 3(f.O(\'2j\')!=-1){16();3($.1q.35){$("#K").C();$("#8").r({Y:"T"})}}n{$("#F").34(f+="&1y="+(1p 33().32()),9(){16();$("#K").C();1u("#F a.18");$("#8").r({Y:"T"})})}}3(!m[\'1A\']){o.21=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}}}}31(e){}}9 1m(){$("#K").C();$("#8").r({Y:"T"})}9 G(){$("#2Y").N("s");$("#Z").N("s");$("#8").2X("2W",9(){$(\'#8,#B,#1F\').2V("24").N().C()});$("#K").C();3(2t o.v.J.2i=="2g"){$("v","11").r({A:"1Z",z:"1Z"});$("11").r("22","")}o.1h="";o.21="";H P}9 16(){$("#8").r({2U:\'-\'+20((13/2),10)+\'p\',z:13+\'p\'});3(!(1V.1q.2Q&&1V.1q.2P<7)){$("#8").r({38:\'-\'+20((1a/2),10)+\'p\'})}}9 2p(a){6 b={};3(!a){H b}6 c=a.1B(/[;&]/);25(6 i=0;i<c.1c;i++){6 d=c[i].1B(\'=\');3(!d||d.1c!=2){39}6 e=2a(d[0]);6 f=2a(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}H b}9 2x(){6 a=o.2M;6 w=1S.2o||1R.2o||(a&&a.1Q)||o.v.1Q;6 h=1S.1P||1R.1P||(a&&a.2n)||o.v.2n;1O=[w,h];H 1O}9 1K(){6 a=2K.2J.1C();3(a.O(\'2I\')!=-1&&a.O(\'3o\')!=-1){H 1b}}',62,211,'|||if|div|id|var||TB_window|function||||||||||||||else|document|px|append|css|click||href|body||||width|height|TB_overlay|remove|TB_Counter|TB_TempArray|TB_ajaxContent|tb_remove|return|keycode|style|TB_load|src|null|unbind|indexOf|false|title|TB_NextHTML|imgPreloader|block|iframe|ajaxContentH|ajaxContentW|this|display|TB_closeWindowButton||html|goPrev|TB_WIDTH|TB_PrevHTML|TB_iframeContent|tb_position||thickbox|tb_show|TB_HEIGHT|true|length|nbsp|span|Math|onload|onkeydown|goNext|Esc|or|close|tb_showIframe|TB_imageCount|Close|new|browser|TB_FoundURL|Key|Image|tb_init|name|imgLoader|TB_NextURL|random|TB_NextCaption|modal|split|toLowerCase|TB_PrevCaption|urlNoQuery|TB_HideSelect|TB_PrevURL|TB_ajaxWindowTitle|img|addClass|tb_detectMacXFF|TB_ImageOff|150|rel|arrayPageSize|innerHeight|clientWidth|self|window|children|TB_prev|jQuery|frameborder|TB_next|getElementById|auto|parseInt|onkeyup|overflow|alt|unload|for|inlineId||100||unescape|1000|round|hspace|TB_closeAjaxWindow|TB_title|undefined|match|maxHeight|TB_iframe|bmp|gif|png|clientHeight|innerWidth|tb_parseQuery|jpeg|replace|jpg|typeof|which|keyCode|event|tb_getPageSize|show|TB_overlayBG|TB_closeWindow|TB_overlayMacFFBGHack|TB_secondLine|TB_caption|blur|TB_Image|60|tb_pathToImage|mac|userAgent|navigator|of|documentElement|Prev|lt|version|msie|gt|ready|Next|marginLeft|trigger|fast|fadeOut|TB_imageOff|hidden||catch|getTime|Date|load|safari|get|TB_inline|marginTop|continue|scrollTop|TB_modal|class|TB_|45|440|40|630|input|188|190|substr|try|area|firefox'.split('|'),0,{}))

/*
// date dropdowns
$(document).ready(function(){
 $('.sched-toggle').hide();
 $('.sched-show').click(function(){
  var t = $(this);
  if (t.parent().hasClass('sched-menu-dates')) {
      if ($(this).css('display') == 'block') {
        t.parent().addClass('opened');
      } else {
        t.parent().removeClass('opened');
      }
    }    
  // toggle hidden div  
  t.parent().find('.sched-toggle').slideToggle('fast');
 })
})
// used to hide dropdown menu on click
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
*/

// sidebar filter menus
$(document).ready(
  function() {
    $('#sched-sidebar-filters-custom .li-filter a').click(
      function() {
        var self = $(this);
        $('#sched-sidebar-filters-list div').each(function(i,e) {
            if ($(e).attr('id') == self.attr('rel')) {
              if ($(e).css('display') == 'block') {
                $(e).hide();
              } else {
                $(e).show();
              }
            } else {
              $(e).hide();
            }
          }
        );
        return false;
      }
    );
  }
);

function validateusername(val) {
  if (oun == val) {
    unok = true;
    return unnotify('un-ok', 'Your current username');
  }

  if (_valun(val)) {
    isUnameAvailable(val);
  } else {
    unok = false;
    unnotify('un-no', 'English letters, numbers and periods. No spaces.');
  }
}

function _valun(uname) {  
  if ($.trim(uname).length < 3) return false;
  var regex = new RegExp(/[^0-9a-zA-Z_\.]+/);
  if(uname.match(regex)) return false;
  else return true;
}

function isUnameAvailable(uname) {
  unnotify('un-ok', 'checking');
  $.get('/profile', {u:uname}, function(d) {
    if ('ok' == d) { unok = true; unnotify('un-ok', 'Username is available'); 
    } else { unok = false; unnotify('un-no', 'Username not available'); }
  });
}

function conotify(classy, txt) {
  $('#pwch-label .un-notify').remove();
  $('#pwch-label').append('<strong class="un-notify"></strong>');
  $('#pwch-label .un-notify').hide().addClass(classy).text(txt).fadeIn(150);
}

function unnotify(classy, txt) {
  $('#un-label .un-notify').remove();
  $('#un-label').append('<strong class="un-notify">checking</strong>');
  $('#un-label .un-notify').delay(150).hide().addClass(classy).text(txt).fadeIn(150);
}

