// JavaScript Document
//alert("load");

$(document).ready(function(){
//Start JQuery Code


  //Cufon Calls/Text Replacement
  Cufon.replace('#utility_nav a', {fontFamily: 'Gotham Rounded Medium', hover: true});
  Cufon.replace('#sitenav dd a.primary', {fontFamily: 'Gotham Rounded Medium', hover: true});
  Cufon.replace('#contactinfo dt', {fontFamily: 'Gotham Rounded'});  
  Cufon.replace('.phone', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('.foreignphone', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('.location', {fontFamily: 'Gotham Rounded'});  
  Cufon.replace('h1', {fontFamily: 'Gotham Rounded'});

  Cufon.replace('#article h2', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('#article h3', {fontFamily: 'Gotham Rounded Medium'});
  
  if (($("body").attr("class").search("landing") == -1) && ($("body").attr("class") != "global")) Cufon.replace('#article h4', {fontFamily: 'Gotham Rounded Medium'});

  Cufon.replace('#sidebar h2', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('#sidebar .happening h2', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('#sidebar h3', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('#sidebar h4', {fontFamily: 'Gotham Rounded Medium'});    
  /*Cufon.replace('#socialmedia h3', {fontFamily: 'Gotham Rounded Medium'});*/
  Cufon.replace('#signin a', {fontFamily: 'Gotham Rounded Medium', hover: true});
  Cufon.replace('#pagelisting h3', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('.process h3', {fontFamily: 'Gotham Rounded Medium'});  
  
  Cufon.replace('#pageheader h2', {fontFamily: 'Gotham Rounded'});  
  Cufon.replace('ul.tabs a', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('#interest a.freetext', {fontFamily: 'Gotham Rounded Medium', hover: true});
  Cufon.replace('body.landing #belowfold h2', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('#belowfoldcontent #article h3.headline', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('.meetaupairs h3', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('.starting h3', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('body.landing #article .happening h3', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('body.landing #sidebar h2', {fontFamily: 'Gotham Rounded'});  
  
  Cufon.replace('#explore h2', {fontFamily: 'Gotham Rounded Medium'});
  Cufon.replace('body.global #sidenav h2', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('span.wheretostart', {fontFamily: 'Gotham Rounded'});  
  Cufon.replace('body.global #belowfold h2', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('body.utility #belowfold h2', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('body.global #article h3', {fontFamily: 'Gotham Rounded Medium'});  
  
  Cufon.replace('#email form .header h2', {fontFamily: 'Gotham Rounded'});
  
  Cufon.replace('h1.application', {fontFamily: 'Gotham Rounded Medium'});  
  Cufon.replace('body.aupairform #article h2', {fontFamily: 'Gotham Rounded Medium'});    
  Cufon.replace('body.intro #article h2', {fontFamily: 'Gotham Rounded'});
  Cufon.replace('body.aupairform #article h3', {fontFamily: 'Gotham Rounded'});
  
  Cufon.replace('#article blockquote h3', {fontFamily: 'Gotham Rounded'});
  
  Cufon.now();
  
  // bind for Social media Global Include
  $("ul.flickrimg a").click(function(){
   window.open($(this).attr('href'));
     return false;
    });
  // bind for Social media Global Include
  $("a.facebook").click(function(){
   window.open('http://www.facebook.com/share.php?u='+encodeURIComponent(location.href));
     return false;
    });
  // bind for Social media Global Include
  $("a.delicious").click(function(){
   window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400');
     return false;
    });
  
  //Button Hovers
  $(".submit").hover(
    function() {      
      off_img = $(this).attr("src");      
      over_img = off_img.replace("off/","on/");                                      
      $(this).attr("src", over_img);    
    },    
    function() {    
      $(this).attr("src", off_img);
    }
  );  
  
  //Outside Links
  $("a.target").click(function(){
    window.open($(this).attr("href"));
    return false;
  });  
  
  //Print Button 
  $("a#printlink").click(function(){
    window.print();
    return false;
  });  

  //Landing Page (Interested Tabs)
      
  $(".tabs a").click(function(){
    var anchor = $(this).attr("href").replace("#","");
    
    $("#firsttab, #secondtab").addClass("hide");
    
    if (anchor == "firsttab") {
      $("#first, #secondalternate").addClass("hide");
      $("#second, #firstalternate").removeClass("hide");  
      $("#firsttab").removeClass("hide");      
      $("#secondtab .cufon").addClass("hide");  
      $("#firsttab .cufon").removeClass("hide");      
    } else {
      $("#first, #secondalternate").removeClass("hide");
      $("#second, #firstalternate").addClass("hide");
      $("#secondtab").removeClass("hide");        
      $("#firsttab .cufon").addClass("hide");  
      $("#secondtab .cufon").removeClass("hide");      
    };
    
    return false;
  });    
  
  //Opportunies - Global
  $(".selector a").click(function(){                
    var anchor = $(this).attr("href").replace("#","");    
    $(".opportunity").css("left","-9999px");    
    $("#" + anchor).css("left", "auto");    
    return false;
  });    
  
  $(".opportunity a.closewindow").click(function(){
    $(".opportunity").css("left","-9999px");                    
    return false;
  });  
  
  //Au Pair Homepage - Carousel
  
  if($("body").attr("class") == "landing") {
    $(function() {
      $(".carousel").jMyCarousel({
          btnPrev: $(".meetaupairs span.previous"),
          btnNext: $(".meetaupairs span.next"),      
          visible: '602px',                    
          visible: '11',
          eltByElt: true,
          evtStart: 'mousedown',
          evtStop: 'mouseup'        
  
      });
    });
   };
  
  $(".meetaupairs span.next, .meetaupairs span.previous").mouseover(function(){
    $(this).css("cursor","pointer");
  });  

  //Landing Page Pulldowns - 10/27/09
  $(".starting select").change(function(){
          if ($("option:selected").attr("value") != "") window.location.href = $("option:selected").attr("value");
     });

  //LC/State Pulldown - 10/30/09
  $("#stateList").change(function(){
          if ($("option:selected").attr("value") != "") window.location.href = "#" + $("option:selected").attr("value");
     });  
  
  //Region Page Functions (Formatting) - 7/23/10
  if($("body").attr("class") == "region") regionFunctions();

  //Focus change - Changed 4/15/10
  $("form[id!='searchBox'] input, select, textarea").focus(function(){      
    $(this).parents("li").css("background-color", "#FFFF99");
    $(this).parents("li").children(".help").removeClass("hide")
  });  
  
  $("form[id!='searchBox'] input, select, textarea").blur(function(){      
    $(this).parents("li").css("background-color", "transparent");
    $(this).parents("li").children(".help").addClass("hide")    
  });  
  
  //Search Box Label - Added 4/15/10
  //Loading
  $("input[id='keywords']").val('');
  
  //Funtionality
  $("input[id='keywords']").focus(function(){      
    $(this).siblings("label").css("text-indent","-100px");
  });  
  $("input[id='keywords']").blur(function(){      
    if ($(this).val() = '') $(this).siblings("label").css("text-indent","0");
  });      
  
  $(".notify, .help").addClass("hide");
  
  
//End JQuery Code
});

function calcHours(){
  var hours = 0;
  
  $("input:text").not("#Week_Total_Hours_Display").each(function(i) {
    if(!isNaN($(this).attr("value"))) {
      hours += parseInt($(this).attr("value"), 10);
      $(this).attr("value", parseInt($(this).attr("value"), 10));      
    } else {
      $(this).attr("value", "0");
      hours += 0;      
    }
  });    
  
  return hours;
};

function dailyHours(repeat){
  if(repeat == "y") {
    var duties = $("#Day_1Mon_Duties").attr("value");
    var hours = $("#Day_1Mon_Total").attr("value");
    $(":input[name$='_Duties']").not("#Day_1Mon_Duties").attr("value", duties);
    $(":input[name$='_Total']").not("#Day_1Mon_Total").attr("value", hours);        
  } else {
    $(":input[name$='_Duties']").not("#Day_1Mon_Duties").attr("value", "");  
    $(":input[name$='_Total']").not("#Day_1Mon_Total").attr("value", "");        
  };    
  $("#Week_Total_Hours").attr("value", calcHours());
  $("#Week_Total_Hours_Display").attr("value", calcHours());  
};

function evaluateFormPostResponse(responseStr) {  

  var response = $.trim(responseStr);
  updateDialog('success','Thank you for submitting your information');
  //document.write(response);
}

function showProgressDialog(title,msg) {
  $.nyroModalManual({
      type: 'form',
    modal: true,
    autoSizable: true,
     content: getProgressDialog('Submitting Information','Please wait while your information is being submitted...'),
    minWidth: 350,
    minHeight: 140,
    height: 140,
    width: 350  
   });    
}

function getProgressDialog(title,msg) {
 var oContainerDiv = document.createElement("div");
 var oHeaderDiv = document.createElement("div");
 var oTitleDiv = document.createElement("div"); 
 var oActionDiv = document.createElement("div");
 var oInteriorDiv = document.createElement("div");
 var oButtonsDiv = document.createElement("div");
 
 oHeaderDiv.className='modalHeader';
 oTitleDiv.className='modalTitle';
 oActionDiv.className='modalAction';
 oInteriorDiv.className='modalInterior progress';
 oButtonsDiv.className='modalButtons';
 
 oTitleDiv.innerHTML='<h2>'+title+'</h2>';
 oActionDiv.innerHTML='';
 oHeaderDiv.appendChild(oTitleDiv);
 oHeaderDiv.appendChild(oActionDiv);
 oInteriorDiv.innerHTML=msg; 
 oButtonsDiv.innerHTML='<input type="button" value="OK"  id="primaryDialogButton" />';
 
 oContainerDiv.appendChild(oHeaderDiv);
 oContainerDiv.appendChild(oInteriorDiv);
 oContainerDiv.appendChild(oButtonsDiv);
 
 return oContainerDiv.innerHTML;
}

function updateDialog(type,msg) {
 switch(type) {
  case 'success':
   $('.modalInterior').removeClass("progress");
   $('.modalInterior').addClass("success");
   $('.modalInterior').html(msg);
   $('.modalButtons').css('display','block');  
   $("#primaryDialogButton").click(function () { 
    $.nyroModalRemove();
   });

   break;
  case 'error':   
   $('.modalInterior').removeClass("progress");
   $('.modalInterior').addClass("error");
   $('.modalInterior').html(msg);
   $('.modalButtons').css('display','block');
   $("#primaryDialogButton").click(function () { 
    $.nyroModalRemove();
   });
   
   break;
  case 'progress':
   break;  
 
 
 }
}
    
/* Added 7/22/10 */
function regionFunctions(){
  
  //Region Pages - 9/11/09  
  $("body.region #article h1").prepend("<span class=\"headertop\">&nbsp;</span>");
  $("body.region #article h1").append("<span class=\"headerbottom\">&nbsp;</span>");  
  
  //Sidebar/Header Alterations - 7/23/10
  topPadding = $("body.region #article h1").height() + 60;
  $("body.region #sidebar").css("padding-top",topPadding + "px");
}