/* Requires jquery.js */
jQuery.noConflict();
jQuery(document).ready(function() {
    init_dropNavs();
    init_launchPad();

    jQuery('#zLocSelect .close a').click(function() {
        return tog_zLocSelect();
    });
    
    jQuery('#pageMainNav li').hover(function() {
        if (!jQuery(this).hasClass('curr')) jQuery(this).addClass('dropped');
    }, function() {
        jQuery(this).removeClass('dropped');
    });
});

function init_zLocSelect() {
    // Attach expand/collapse toggle events to location selector	
    jQuery('#zLocSelect .close a').click(function() {
        return tog_zLocSelect();
    });
}


function tog_zLocSelect(_userID) {
    if (jQuery('#zLocSelect').css('display') == 'block') {
        jQuery('#zLocSelect_tog').removeClass('open');
        jQuery('#zLocSelect').slideUp(700);
    }
    else {
        // Just got here, no location selector content yet
        if (jQuery('#zLocDomestic').length == 0) {
            // Retrieve and inject #zLocDomestic, #zLocIntl, and #zLocRecent (if _userID is set)
            jQuery.post('/RecentLocations/recentLocHandler.aspx', { userID: _userID }, function(d, stat) {
                jQuery(d).insertAfter('#launchPad');
                tod_zExpand();
                init_zLocSelect();
            });
        }
        // Already have location selector content, just reveal
        else {
            jQuery('#zLocSelect_tog').addClass('open');
            jQuery('#zLocSelect').slideDown(700);
        }
    }
    return false;
}

function tod_zExpand() {
    jQuery('#zLoc .zLocSelect_tog').addClass('open');
    jQuery('#zLocSelect').slideDown(150);
    jQuery('#zLocSelect .inner').slideDown(700);
    jQuery('#zLocSelectFtr').slideDown(700);
    jQuery('#zLocJump').slideDown(700);
}


function init_dropNavs() {
    var i, w;

    for (i = 0; i < jQuery('.zSubNav').length; i++) {
        w = jQuery('.zSubNav').eq(i).innerWidth();
        w = (w < 130) ? 130 : w;
        
        /*alert('inner:'+jQuery('.zSubNav').eq(i).innerWidth());
        alert('width:'+jQuery('.zSubNav').eq(i).width());
        alert('outer:'+jQuery('.zSubNav').eq(i).outerWidth());*/
        
        jQuery('.zSubNav').eq(i).css('width', w);
    }
}

function init_pressTicker() {
    /* Random */
    jQuery('#pressTicker li').eq(Math.floor(Math.random() * 10) % jQuery('#pressTicker li').length).addClass('curr');

    /* Time of Day */
    /*
    var d = new Date();
    jQuery('#pressTicker li').eq(Math.floor((d.getHours()/24) * jQuery('#pressTicker li').length)).addClass('curr');
    */
}

function init_launchPad() {
    /*jQuery('#form_search input').keypress(function(){
        try{
        return WebForm_FireDefaultButton(event, 'ctl00_ctl00_MainPageHeaderNavigation_SubHeader_ctl00_btnSearch');
        }
        catch(e){
        alert(e.msg);
        }
    });*/
    /*
    jQuery('#bLnk_cuisines').click(function() {
        var LB_W = jQuery('#dorm_cuisines').width();
        var _left = (jQuery(document).width() - LB_W) / 2;

        jQuery.blockUI({ message: '<div class="lb_browse">' + jQuery('#dorm_cuisines').html() + '</div>', css: { position: 'absolute', left: _left + 'px', cursor: 'auto', width: 'auto', top: '100px', borderWidth: '0px'} });

        jQuery('.btn_close a').click(function() {
            jQuery.unblockUI();
        });
        jQuery('.btn_cancel a').click(function() {
            jQuery.unblockUI();
        });

        jQuery('.lb_browse form').submit(function() {
            var c = '';
            for (var i = 0; i < jQuery('input[checked=true]', jQuery(this)).length; i++) {
                c += jQuery('input[checked=true]', jQuery(this)).eq(i).attr('value') + ',';
            }

            window.location = 'results.html?c=' + c;
            return false;
        });
    });

    jQuery('#bLnk_neighborhoods').click(function() {
        var LB_W = jQuery('#dorm_neighborhoods').width();
        var _left = (jQuery(document).width() - LB_W) / 2;

        jQuery.blockUI({ message: '<div class="lb_browse">' + jQuery('#dorm_neighborhoods').html() + '</div>', css: { position: 'absolute', left: _left + 'px', cursor: 'auto', width: 'auto', top: '100px', borderWidth: '0px'} });

        jQuery('.btn_close a').click(function() {
            jQuery.unblockUI();
        });
        jQuery('.btn_cancel a').click(function() {
            jQuery.unblockUI();
        });
    });

    jQuery('#bLnk_topRated').click(function() {
        var LB_W = jQuery('#dorm_topRated').width();
        var _left = (jQuery(document).width() - LB_W) / 2;

        jQuery.blockUI({ message: '<div class="lb_browse">' + jQuery('#dorm_topRated').html() + '</div>', css: { position: 'absolute', left: _left + 'px', cursor: 'auto', width: 'auto', top: '100px', borderWidth: '0px'} });

        jQuery('.btn_close a').click(function() {
            jQuery.unblockUI();
        });
        jQuery('.btn_cancel a').click(function() {
            jQuery.unblockUI();
        });
    });*/
}