jQuery(document).ready(function() {
 
    //speed rfp google analytics  click tracking workaround
    jQuery("#speedrfp_button_text").click(function() {       
        strippedUrl = stripUrl(srfp_widget.speedrfp_url);
        str = '/outgoing/' + strippedUrl;
       // alert(str)
        pageTracker._trackPageview(str);
    });
 
    //css the dropdown open in site editing
    jQuery('.languageChanger  li ul').css('display', 'none').css('position', 'absolute');


    window.pushDateVal = 1;  //put in rel attribute of #startdate or .numbernights field
    if (jQuery('#startdate').attr('rel') > 0) {
        window.pushDateVal = parseInt(jQuery('#startdate').attr('rel'));
    }

    if (jQuery("#startdate").length > 0) {

        if (dateFormat == "") {
            var dateFormat = "mm/dd/yyyy";
        }

        jQuery.datepicker.setDefaults({
            minDate: 0,
            buttonText: '&nbsp;&nbsp;&nbsp;',
            defaultDate: +1,
            showOn: 'both',
            buttonImageOnly: false//,
            //dateFormat: dateFormat

        });

        jQuery('#startdate').datepicker({

            onClose: function() {
                pushDate(window.pushDateVal);
            }


        });
        jQuery('#enddate').datepicker({
            beforeShow: minRange,
            defaultDate: +3
        });
    }
    if (jQuery('.languageChanger').length > 0) {
        jQuery('.languageChanger').singleDropMenu();
    }




    jQuery('.iframe_modal').live('click', function(e) {

        e.preventDefault();


        var dWidth = 800;
        var dHeight = 500;

        var $this = $(this);
        if ($this.hasClass('small')) {
            dWidth = 200;
            dHeight = 200;
        }
        if ($this.hasClass('large')) {
            dWidth = 860;
            dHeight = 600;
        }
        if ($this.hasClass('xlarge')) {
            dWidth = 930;
            dHeight = 500;
        }

        var thisDialogClass = '';
        if ($this.hasClass('noTitle')) {
            thisDialogClass = 'noTitle';
        }


        var horizontalPadding = 12;
        var verticalPadding = 0;



        theDialog = jQuery('<iframe  id="externalSite" class="externalSite" frameborder="0" src="' + this.href + '" />');
        theDialog.dialog({
            dialogClass: thisDialogClass,
            title: ($this.attr('title')) ? $this.attr('title') : 'Info',
            autoOpen: true,
            closeText: 'Close',
            width: dWidth,
            height: dHeight,
            modal: true,
            beforeclose: function() {
                $this.removeClass('disabled');
            },
            open: function(event, ui) {
                jQuery('body').css('overflow', 'hidden');
                jQuery('.ui-widget-overlay').css('width', '100%');
            },
            close: function(event, ui) { $('body').css('overflow', 'auto'); },
            closeOnEscape: false
        }).width(dWidth - horizontalPadding).height(dHeight - verticalPadding);



    });
    jQuery('.ui-widget-overlay').live('click', function() {

        // theDialog.dialog('close');

    });





    //put additional functions here.


});   //end ready

//pushes the endDate back to +2d of startdate
function pushDate(numberDaysAhead) {
    if (jQuery("#enddate").length > 0) {

        var startDate = jQuery("#startdate").datepicker("getDate");
        var endDate = jQuery("#enddate").datepicker("getDate");

        if (startDate > endDate) {
            startDate.setDate(startDate.getDate() + numberDaysAhead);
            jQuery('#enddate').datepicker('setDate', startDate);
            //alert('start gt end');
        } else {
            //alert('start lt end');
        }
    }
}

//customize mindate so that enddate cannot be b4 startdate
function minRange(input) {
    return {
        minDate: (jQuery("#startdate").datepicker("getDate") != null ? jQuery("#startdate").datepicker("getDate") : 2)
    };
}
//startdate cannot be after enddate
function maxRange(input) {
    return {
        maxDate: (jQuery("#enddate").datepicker("getDate") != null ? jQuery("#enddate").datepicker("getDate") : null)
    };
}

						
