/*!
 * jQuery blockUI plugin
 * Version 2.31 (06-JAN-2010)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://malsup.com/jquery/block/
 * Copyright (c) 2007-2008 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
 */
eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[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}(';(15($){7(/1\\.(0|1|2)\\.(0|1|2)/.73($.45.70)||/^1.1/.73($.45.70)){191(\'13 195 108 197.2.3 185 198!  211 213 214 216\'+$.45.70);37}$.45.132=$.45.67;11 92=15(){};11 110=22.215||0;11 153=$.46.68&&(($.46.140<8&&!110)||110<8);11 125=$.46.68&&/204 6.0/.73(144.207)&&!110;$.13=15(5){117(54,5)};$.162=15(5){114(54,5)};$.174=15(85,47,32,180){11 $97=$(\'<18 41="174"></18>\');7(85)$97.104(\'<101>\'+85+\'</101>\');7(47)$97.104(\'<155>\'+47+\'</155>\');7(32==103)32=206;$.13({47:$97,67:209,44:143,79:69,32:32,53:69,112:180,19:$.13.50.148})};$.45.188=15(5){37 24.123({44:0}).78(15(){7($.19(24,\'28\')==\'196\')24.25.28=\'194\';7($.46.68)24.25.202=1;117(24,5)})};$.45.123=15(5){37 24.78(15(){114(24,5)})};$.13.140=2.31;$.13.50={47:\'<101>189 136...</101>\',85:64,94:34,77:69,19:{107:0,134:0,55:\'30%\',26:\'40%\',52:\'35%\',186:\'119\',145:\'#120\',66:\'217 212 #208\',131:\'#150\',122:\'136\'},84:{55:\'30%\',26:\'40%\',52:\'35%\'},72:{131:\'#120\',130:0.6,122:\'136\'},148:{55:\'203\',26:\'93\',52:\'\',199:\'93\',66:\'42\',107:\'201\',130:0.6,122:\'210\',145:\'#150\',131:\'#120\',\'-184-66-152\':\'93\',\'-187-66-152\':\'93\'},154:/^193/111.73(54.190.192||\'\')?\'205:69\':\'228:249\',98:69,151:143,161:34,79:34,142:34,156:34,158:34,67:200,44:250,32:0,53:34,182:34,137:34,81:64,112:64,178:4};11 57=64;11 56=[];15 117(12,5){11 17=(12==54);11 16=5&&5.47!==103?5.47:103;5=$.80({},$.13.50,5||{});5.72=$.80({},$.13.50.72,5.72||{});11 19=$.80({},$.13.50.19,5.19||{});11 84=$.80({},$.13.50.84,5.84||{});16=16===103?5.47:16;7(17&&57)114(54,{44:0});7(16&&175 16!=\'251\'&&(16.51||16.70)){11 65=16.70?16[0]:16;11 14={};$(12).14(\'13.124\',14);14.12=65;14.75=65.51;14.36=65.25.36;14.28=65.25.28;7(14.75)14.75.163(65)}11 33=5.151;11 74=($.46.68||5.98)?$(\'<141 41="13" 25="33-91:\'+(33++)+\';36:42;66:42;134:0;107:0;28:113;55:100%;82:100%;26:0;52:0" 248="\'+5.154+\'"></141>\'):$(\'<18 41="13" 25="36:42"></18>\');11 59=$(\'<18 41="13 247" 25="33-91:\'+(33++)+\';36:42;66:42;134:0;107:0;55:100%;82:100%;26:0;52:0"></18>\');11 23;7(5.77&&17){11 21=\'<18 41="13 109 147 39-106 39-83 39-243-253" 25="33-91:\'+33+\';36:42;28:126">\'+\'<18 41="39-83-244 39-106-149 245">\'+(5.85||\'&246;\')+\'</18>\'+\'<18 41="39-83-102 39-106-102"></18>\'+\'</18>\';23=$(21)}43{23=17?$(\'<18 41="13 109 147" 25="33-91:\'+33+\';36:42;28:126"></18>\'):$(\'<18 41="13 109 252" 25="33-91:\'+33+\';36:42;28:113"></18>\')}7(16){7(5.77){23.19(84);23.257(\'39-83-102\')}43 23.19(19)}7(!5.137||!($.46.258&&/255/.73(144.254)))59.19(5.72);59.19(\'28\',17?\'126\':\'113\');7($.46.68||5.98)74.19(\'130\',0.0);11 139=[74,59,23],$146=17?$(\'38\'):$(12);$.78(139,15(){24.256($146)});7(5.77&&5.94&&$.45.94){23.94({241:\'.39-106-149\',225:\'226\'})}11 138=153&&(!$.76||$(\'227,242\',17?64:12).86>0);7(125||138){7(17&&5.142&&$.76)$(\'224,38\').19(\'82\',\'100%\');7((125||!$.76)&&!17){11 61=90(12,\'169\'),60=90(12,\'170\');11 128=61?\'(0 - \'+61+\')\':0;11 127=60?\'(0 - \'+60+\')\':0}$.78([74,59,23],15(111,116){11 21=116[0].25;21.28=\'113\';7(111<2){17?21.49(\'82\',\'223.219(22.38.220, 22.38.88) - (108.76?0:\'+5.178+\') + "48"\'):21.49(\'82\',\'24.51.88 + "48"\');17?21.49(\'55\',\'108.76 && 22.62.181 || 22.38.181 + "48"\'):21.49(\'55\',\'24.51.118 + "48"\');7(127)21.49(\'52\',127);7(128)21.49(\'26\',128)}43 7(5.79){7(17)21.49(\'26\',\'(22.62.176 || 22.38.176) / 2 - (24.88 / 2) + (221 = 22.62.63 ? 22.62.63 : 22.38.63) + "48"\');21.218=0}43 7(!5.79&&17){11 26=(5.19&&5.19.26)?168(5.19.26):0;11 177=\'((22.62.63 ? 22.62.63 : 22.38.63) + \'+26+\') + "48"\';21.49(\'26\',177)}})}7(16){7(5.77)23.222(\'.39-83-102\').104(16);43 23.104(16);7(16.70||16.229)$(16).95()}7(($.46.68||5.98)&&5.53)74.95();7(5.67){11 133=5.81?5.81:92;11 183=(5.53&&!16)?133:92;11 179=16?133:92;7(5.53)59.132(5.67,183);7(16)23.132(5.67,179)}43{7(5.53)59.95();7(16)23.95();7(5.81)5.81()}115(1,12,5);7(17){57=23[0];56=$(\':230:237:238\',57);7(5.182)96(105,20)}43 119(23[0],5.161,5.79);7(5.32){11 71=96(15(){17?$.162(5):$(12).123(5)},5.32);$(12).14(\'13.32\',71)}};15 114(12,5){11 17=(12==54);11 $12=$(12);11 14=$12.14(\'13.124\');11 71=$12.14(\'13.32\');7(71){239(71);$12.160(\'13.32\')}5=$.80({},$.13.50,5||{});115(0,12,5);11 29;7(17)29=$(\'38\').172().173(\'.13\').240(\'38 > .13\');43 29=$(\'.13\',12);7(17)57=56=64;7(5.44){29.44(5.44);96(15(){121(29,14,5,12)},5.44)}43 121(29,14,5,12)};15 121(29,14,5,12){29.78(15(111,116){7(24.51)24.51.163(24)});7(14&&14.12){14.12.25.36=14.36;14.12.25.28=14.28;7(14.75)14.75.236(14.12);$(12).160(\'13.124\')}7(175 5.112==\'15\')5.112(12,5)};15 115(89,12,5){11 17=12==54,$12=$(12);7(!89&&(17&&!57||!17&&!$12.14(\'13.159\')))37;7(!17)$12.14(\'13.159\',89);7(!5.156||(89&&!5.53))37;11 129=\'235 231 232 233\';89?$(22).115(129,5,135):$(22).234(129,135)};15 135(27){7(27.157&&27.157==9){7(57&&27.14.158){11 29=56;11 165=!27.164&&27.99==29[29.86-1];11 87=27.164&&27.99==29[0];7(165||87){96(15(){105(87)},10);37 69}}}7($(27.99).171(\'18.109\').86>0)37 34;37 $(27.99).171().172().173(\'18.13\').86==0};15 105(87){7(!56)37;11 27=56[87===34?56.86-1:0];7(27)27.105()};15 119(12,166,167){11 58=12.51,21=12.25;11 60=((58.118-12.118)/2)-90(58,\'170\');11 61=((58.88-12.88)/2)-90(58,\'169\');7(166)21.52=60>0?(60+\'48\'):\'0\';7(167)21.26=61>0?(61+\'48\'):\'0\'};15 90(12,58){37 168($.19(12,58))||0}})(108);',10,259,'|||||opts||if||||var|el|blockUI|data|function|msg|full|div|css||s|document|lyr3|this|style|top|e|position|els|||timeout|z|true||display|return|body|ui||class|none|else|fadeOut|fn|browser|message|px|setExpression|defaults|parentNode|left|showOverlay|window|width|pageBlockEls|pageBlock|p|lyr2|l|t|documentElement|scrollTop|null|node|border|fadeIn|msie|false|jquery|to|overlayCSS|test|lyr1|parent|boxModel|theme|each|centerY|extend|onBlock|height|widget|themedCSS|title|length|back|offsetHeight|b|sz|index|noOp|10px|draggable|show|setTimeout|m|forceIframe|target||h1|content|undefined|append|focus|dialog|padding|jQuery|blockMsg|mode|i|onUnblock|absolute|remove|bind|o|install|offsetWidth|center|000|reset|cursor|unblock|history|ie6|fixed|fixL|fixT|events|opacity|backgroundColor|_fadeIn|cb|margin|handler|wait|applyPlatformOpacityRules|expr|layers|version|iframe|allowBodyStretch|1000|navigator|color|par|blockPage|growlCSS|titlebar|fff|baseZ|radius|setExpr|iframeSrc|h2|bindEvents|keyCode|constrainTabKey|isBlocked|removeData|centerX|unblockUI|removeChild|shiftKey|fwd|x|y|parseInt|borderTopWidth|borderLeftWidth|parents|children|filter|growlUI|typeof|clientHeight|expression|quirksmodeOffsetHack|cb2|onClose|clientWidth|focusInput|cb1|webkit|or|textAlign|moz|block|Please|location|alert|href|https|relative|requires|static|v1|later|right||5px|zoom|350px|MSIE|javascript|3000|userAgent|aaa|700|default|You|solid|are|using|documentMode|v|3px|marginTop|max|scrollHeight|blah|find|Math|html|cancel|li|object|about|nodeType|input|mouseup|keydown|keypress|unbind|mousedown|appendChild|enabled|visible|clearTimeout|add|handle|embed|corner|header|blockTitle|nbsp|blockOverlay|src|blank|400|string|blockElement|all|platform|Linux|appendTo|addClass|mozilla'.split('|'),0,{}))


/**
 * Omniture namespace, a collection of function for tracking data to omniture
 */
if(typeof(Omniture) == 'undefined') {
    var Omniture = {};
}
Omniture.trackQuickSearch = function(searchData, partners)
{
    s.pageName = searchData.product + ": Search";
    s.channel = searchData.product;

    //Set up the events to record (note no ad view event19)
    s.events = "event1,prodView";
    
    //Set and widget information to Not Applicable
    s.eVar8="Not Applicable";
    s.eVar48="Not Applicable";

    s.prop37 = searchData.isDomestic == true ? 'Domestic' : 'International';
    s.eVar47 = searchData.isDomestic == true ? 'Domestic' : 'International';

    //Record products for prodView
    for (var i=0; i < partners.length; i++) {
      partners[i] = partners[i].category + ";" + partners[i].partner_id;
    };
    s.products = partners.join(",");

    s.eVar44 = searchData.product;
    switch (searchData.product) {
        case 'flights':
            s.prop8 = searchData.places.origin.display_name;
            s.eVar45 = searchData.places.origin.display_name;
            s.prop9 = searchData.places.destination.display_name;
            s.eVar46 = searchData.places.destination.display_name;
            s.prop10 = searchData.params.depart_date;
            s.prop11 = searchData.params.return_date;
            s.prop12 = searchData.params.travelers;
            s.prop34 = searchData.params.legs == 2 ? 'false' : 'true';
            s.prop35 = searchData.params.from_code_include_nearby == true ? 'true' : 'false';
            s.prop36 = searchData.params.to_code_include_nearby == true ? 'true' : 'false';
            break;
        case 'hotels':
            s.prop13 = searchData.places.destination.display_name;
            s.eVar46 = searchData.places.destination.display_name;
            s.prop14 = searchData.params.depart_date;
            s.prop15 = searchData.params.return_date;
            s.prop16 = searchData.params.travelers;
            s.prop17 = searchData.params.rooms;
            break;
        case 'packages':
            s.prop18 = searchData.places.origin.display_name;
            s.eVar45 = searchData.places.origin.display_name;
            s.prop19 = searchData.places.destination.display_name;
            s.eVar46 = searchData.places.destination.display_name;
            s.prop20 = searchData.params.depart_date;
            s.prop21 = searchData.params.return_date;
            s.prop22 = searchData.params.travelers;
            break;
        case 'cruises':
            s.prop23 = searchData.places.destination;
            s.eVar46 = searchData.places.destination;
            s.prop24 = searchData.params.month + '/' + searchData.params.year;
            s.prop25 = searchData.params['length'];
            break;
    }

    //Send the tracking information to omniture.
    s.t();
}


window.popupTest = false;

function getDeals(product, place, forContent) {
  forContent = travel_guide_safe(forContent);
  loadGoogleAds(product + " " + forContent);
  $.get(product_path + '/deals/', place == null ? {} : {'location':forContent}, function(data){
    if (data) {
      $('#deals-block').replaceWith(data).show();
    } else {
      $('#deals-block').hide();
    }
  });
}

function updateTitle(destination) {
  if (product_name == 'flights') {
    $('#title h1').text('Cheap Flights to ' + destination);
  } else if (product_name == 'hotels') {
    $('#title h1').text('Hotels in ' + destination);
  } else if (product_name == 'cruises') {
    $('#title h1').text('Cruises in ' + destination);
  } else if (product_name == 'packages') {
    $('#title h1').text('Packages to ' + destination);
  } else if (product_name == 'cars') {
    $('#title h1').text('Car Rentals in ' + destination);
  }
}


$(document).ready(function() {

// ==============================================================================
// = PRESENTIONAL UI                                                            =
// ==============================================================================

	$('#deals-box .navbar li span').click(function() {
		$('#deals-box .navbar li').toggleClass('selected', false);
		$('#deals-box #dealsBoxes ul').toggleClass('show', false);
		$(this).parent().addClass('selected');
		$('#deals-box #dealsBoxes ul.' + $(this).attr('rel')).toggleClass('show', true);
		if($('#deals-box .body').css('display') == 'none') {
			$(this).parents('#deals-box').find('.body').slideToggle("slow");
			$(this).parents('#deals-box').find('.arrow').toggleClass('closed');
		}
		return false;
	});

	$('#deals-box .navbar li:not(.spacer)').hover(function() {
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});

  /**
   * Disable the compare button if, there were no badges preloaded
   */
  if ($('#Continue').attr('src').indexOf('btn_compare.gif') == -1) {
    $('#Continue').attr('disabled', 'disabled');
  }



// ============================================================================
// = PARTNER BADGES / CHECKBOXES                                              =
// ============================================================================

  $('#sponsorBadges .badge, #related_package .extra-badge').live('click', function(e) {
    var chBox = $(this).find('input:checkbox');

    //if they clicked the checkbox then don't mess with the value
    if ($(e.target).is(':checkbox')) {
        $(this).toggleClass('checked');
        return true;
    }

    if ($(chBox).is(':checked')) {
      $(chBox).each(function(){ this.checked = false; });
      $(this).removeClass('checked');
    } else {
      $(chBox).each(function(){ this.checked = true; });
      $(this).addClass('checked');
    }
  });
  $('#related_package .extra-text h3').live('click', function(){
    $(this).parent().parent().find('.extra-badge').click();
  });

  $('#Continue').click(function() {
    var uuid  = $.uid();
    
    if ($('#sponsorBadges .badge input:checked, #related_package .extra-badge input:checked').length == 0){
      if ($('#sponsorBadges .badge input').size() < 4) {
        var clickBadgeText = 'one partner logo';
      } else {
        var clickBadgeText = 'three partner logos';
      }
      
      alert("To continue with this action and compare multiple sites in one click, please select at least "+clickBadgeText+".");
      return false;
    }

    if ($("#sponsorBadges .badge input, #related_package .extra-badge input").is("[value='']")) {
      $('#search_form').submit();
      alert("To continue with this action, please ensure that you have completed all fields of the search form.");
      return false;
    }

    if ($('#related_package .extra-badge input').is(':checked')) {
      var cids = [],
          cid = $('#related_package .extra-badge input:checked').attr('data-cid');
          
      $('#sponsorBadges .badge input:checked').each(function(i){
        cids.push($(this).attr('data-cid'));
      });
      
      if (_(cids).include(cid)) {
        var badgeToUncheck = $('#sponsorBadges .badge input[data-cid='+cid+']');
        badgeToUncheck[0].checked = false;
        badgeToUncheck.removeClass('checked');
      }
    }
    
    // Ensure that user has checked at least 3 badges
    if ($('#sponsorBadges .badge input, #related_package .extra-badge input').length > 3 &&
        $('#sponsorBadges .badge input:checked, #related_package .extra-badge input:checked').length < 3) {
      alert('Please select at least 3 badges to compare the best rates available.');
      return false;
    }

    Omniture.trackContinue(product_name);

    if ($.browser.msie) {
      var b = $('#sponsorBadges .badge input:checked, #related_package .extra-badge input:checked');
    } else {
      var b = $('#sponsorBadges .badge input:checked, #related_package .extra-badge input:checked').reverse();
    }
    
    GoogleAnalytics.trackContinue(b.size());
    
    b.each(function(i){
        if(window.screenX) window.screenLeft = window.screenX;
        var url = $(this).val() + '&uuid=' + uuid;
        var isOpened = window.open(url, "_blank", "left="+(400+window.screenLeft)+",width=700,scrollbars=1,resizable=1");
        if (!isOpened) {
            $('body').find('#ajaxModal_popup_blocker').remove();
            $('body').append('<div id="ajaxModal_popup_blocker" style="display:none"><div id="clickToOpen" class="no_modal_signup"></div></div>');
            var clickToOpen = $('#clickToOpen');
            var height = 150;
            clickToOpen.append('<div class="clickBadges"></div>');
            var i=0;

            if ($.browser.msie) {
              var b = $('#sponsorBadges .badge input:checked');
            } else {
              var b = $('#sponsorBadges .badge input:checked').reverse();
            }
            
            b.each(function(index, value){
                if ($('.extra-badge')[0] != undefined && index > 2) {
                  height += 56;
                } else if ($('.extra-badge')[0] == undefined && index > 1) {
                  height += 46;
                }
                var img = $(this).parents('.badge').find('img').attr('src');
                var url = $(this).parents('.badge').find('input').attr('value') + '&uuid=' + uuid;
                var checked = i==0 ? 'Checked' : '';
                clickToOpen.find('.clickBadges').append('<div class="clickBadge'+checked+'"><a href="'+url+'&isModal=true" target="_blank" onclick="window.open(this.href,\'_blank\',\'left='+(300+window.screenLeft)+',width=900,scrollbars=1\'); return false;"><img src="'+img+'" width="90" height="22" /></a></div>');
                i++;
            });
                      
            var text = '<p class="text">Uh oh! Your pop-up blocker is turned on, and that\'s preventing us from giving you the best rates. To find the lowest rates, click the badges to the left to launch each site in a new window.';
            if (i > 1) {
              text += '<br><br><a href="#" onclick="tb_remove(); return false;">Close</a>';
            }
            clickToOpen.append(text + '</p><div style="clear:both"></div>');
            
            if ($('#related_package')[0] != undefined && $('#sponsorBadges .badge input').is(':checked')) {
              var img = $('#related_package .extra-badge img').attr('src');
              var url = $('#related_package .extra-badge input').attr('value') + '&uuid=' + uuid;

              height += 110;
              clickToOpen.append('<div style="clear:both"></div><div id="pop_related_package">' +
                '<div class="copy">Save 30% more with AIR + HOTEL! Click here &raquo;</div>' +
                '<div class="clickBadge">' +
                  '<a href="'+url+'&isModal=true" target="_blank"><img src="'+img+'" width="90" height="22" /></a>' +
                '</div>' +
              '</div>');
            } else {
              height += 30;
            }
             
            if (i == 1) {
              clickToOpen.append('<div style="clear:both"></div><div style="margin:0px 0px 0px 10px; text-align:center;"><a href="#" onclick="tb_remove(); return false;">Close</a></div>');
            }
            clickToOpen.append('<style>#TB_window { margin:0px !important; top:0; left:0; }</style>');
            tb_show('', '#TB_inline?height='+height+'&width=400&modal=true&inlineId=ajaxModal_popup_blocker', false);
            return false; 
        }
    });

    $('#clickToOpen .clickBadge').live('click', function(){
      if ($(this).has('.clickBadgeChecked')) {
        $(this).addClass('clickBadgeChecked').removeClass('clickBadge');
      }
    });

    return true;
  });

  $('.single-deal').live('click', function(e){
    var link = $(this).find('a');
    
    if (e.target.tagName != 'A') {
  		if (link.attr('target') == '_blank') {
  			window.open(link.attr('href'));
  		} else {
  			location.href = link.attr('href');
  		}
  		return false;
    } else {
      return true;
    }
  });

  /**
   * Provide required field indicator to user
   */
  $('input.required_field').change(function() { 
      var selector = "label[for='"+$(this).attr('id')+"']";
      if ($(this).val().length == 0 ) { 
          $(selector).addClass('show_required');
      } else {
          $(selector).removeClass('show_required');
      }
  });

});

