function zindex() {
 	var zIndexNumber = 1000;
	$('#header div, #global_navbar div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	//fix fancybox
//	var zIndexFancybox = 1110;
//  $('#fancy_overlay,#fancy_loading,#fancy_outer,#fancy_title').each(function() {
//    $(this).css('zIndex', zIndexFancybox);
//    zIndexFancybox += 10;
//  });
}

//docuement ready function
$(document).ready(function() {
  


  //check for ie6
  $.reject({
    imagePath:    '/images/browser_titles/', // Absolute path to the images
    header:       'Did you know that your Internet Browser is out of date?', // Header of pop-up window 
    paragraph1:   'Your browser is out of date, and may not be compatible with our website. A list of the most popular web browsers can be found below.',
    paragraph2:   'Click on the icons to go to the download page for each browser',
    closeMessage: 'By closing this window you acknowledge that your experience on this website may be degraded', // Message displayed below closing link 
    closeLink:    'Close This Window' // Text for closing link  
  });
  

     

  $('.datepicker').datepicker({maxDate: '+20d', minDate: '+0d'});
     
  //set the z-index on all divs
  zindex();
  
  //modals
  $("a.modal_details, a.modal_box_specials, a.btn_reserve_now").fancybox({
    'padding': 8,
    'frameWidth': 450,
    'frameHeight': 315,
    'overlayShow': true,
    'overlayColor': '#fff',
    'overlayOpacity': 0.5,
    'hideOnOverlayClick': true,
    'centerOnScroll': true
  });
  $("a.modal_ccid").fancybox({
    'padding': 8,
    'frameWidth': 350,
    'frameHeight': 250,
    'overlayShow': true,
    'overlayColor': '#fff',
    'overlayOpacity': 0.5,
    'hideOnOverlayClick': true,
    'centerOnScroll': true
  });
//  $("a.modal_box_contact").fancybox({
//    'padding': 15,
//    'frameWidth': 800,
//    'frameHeight': 600,
//    'overlayShow': true,
//    'overlayColor': '#fff',
//    'overlayOpacity': 0.5,
//    'hideOnContentClick': false,
//    'hideOnOverlayClick': false,
//    'centerOnScroll': false,
//    'callbackOnShow': function(){ $("#contact_modal #btn_contact_cancel").click(function(){$.fn.fancybox.close()})}
//  });
  $("a.modal_job_description").fancybox({
    'padding': 10,
    'frameWidth': 350,
    'frameHeight': 250,
    'overlayShow': true,
    'overlayColor': '#fff',
    'overlayOpacity': 0.5,
    'hideOnContentClick': false,
    'hideOnOverlayClick': false,
    'centerOnScroll': false,
    'callbackOnShow': function(){ $("#contact_modal #btn_contact_cancel").click(function(){$.fn.fancybox.close()})}
  });

  //table stripping
  $("table#listings tr:even").css("background","#f0f0f0")
  $("table#listings tr:first").css("background","#fff")
  
//  //tooltips
//  $.cluetip.setup({insertionType: 'appendTo', insertionElement: 'form'});
//    
//  $("#uber_nav li a.anchor").cluetip({
//    activation:         'click',
//    arrows:             true,
//    closePosition:      'title', 
//    cluetipClass:       'nav_tip',
//    cluezIndex:         1100,
//    cursor:             'pointer',
//    dropShadow:         true,
//    dropShadowSteps:    6,
//    fx:                 {open:'fadeIn', openSpeed:'fast'},
//    hideLocal:          true,
//    leftOffset:         150,
//    local:              true,
//    positionBy:         'bottomTop',
//    sticky:             true,
//    topOffset:          25,
//    width:              227
//  });
//  $("#localize_link a.anchor").cluetip({
//    activation:         'click',
//    arrows:             true,
//    closePosition:      'title', 
//    cluetipClass:       'sol_tip',
//    cluezIndex:         1100,
//    cursor:             'pointer',
//    dropShadow:         true,
//    dropShadowSteps:    6,
//    fx:                 {open:'fadeIn', openSpeed:'fast'},
//    hideLocal:          true,
//    leftOffset:         20,
//    local:              true,
//    positionBy:         'auto',
//    sticky:             true,
//    topOffset:          0,
//    width:              227
//  });
//  $(".localize_cta a.anchor").cluetip({
//    activation:         'click',
//    arrows:             true,
//    closePosition:      'title', 
//    cluetipClass:       'sol_tip',
//    cluezIndex:         1100,
//    cursor:             'pointer',
//    dropShadow:         true,
//    dropShadowSteps:    6,
//    fx:                 {open:'fadeIn', openSpeed:'fast'},
//    hideLocal:          true,
//    leftOffset:         20,
//    local:              true,
//    positionBy:         'auto',
//    sticky:             true,
//    topOffset:          0,
//    width:              227
//  });

  //reservation and account field tweaking
  if($('input#autopay_signup').attr('checked') == true){
    $('input#autopay_agree').attr('disabled', false);
    $('textarea#terms_conditions').attr('disabled', false);
  }
  
  $("input#autopay_signup").change(function(){
    if($('input#autopay_signup').attr('checked') == true){
      $('input#autopay_agree').attr('disabled', false);
      $('textarea#terms_conditions').attr('disabled', false);
    } else {
      $('input#autopay_agree').attr('disabled', true);
      $('textarea#terms_conditions').attr('disabled', true);
    }
  });

  if($("input#another_card").attr('checked') == true){
    togglePaymentForm();
  }
  $('input[name=card_select]').click(function(){
    togglePaymentForm();
  });

});

function togglePaymentForm(){
  var inputs = $(".cc_info :input");
  if($("input#another_card").attr('checked') == true){
    jQuery.each(inputs, function(){
      $(this).attr('disabled', false);
    });
  } else {
    jQuery.each(inputs, function(){
      $(this).attr('disabled', true);
    });
  }
}

function toggleAnswer(id){
  if($('#answer_' + id).css('display') == 'none'){
    $('#answer_' + id).css({'display' : 'block'});
    $('#plus_minus_'+id).text('-');
  } else {
    $('#answer_' + id).css({'display' : 'none'});
    $('#plus_minus_'+id).text('+');
  }
}

function toggleDiv(id) {
         if($('#' + id).css('display') == 'none') {
            $('#' + id).css({'display' : 'block'});
         } else 
         {
          $('#' + id).css({'display' : 'none'});
         }
}


