﻿$(function() {
    
    //External link alert
    $(".externalTCLink").click(function() {
        var qs = confirm ("By clicking OK, you will exit the Property Appraiser’s Web site and be directed to the Tax Collector’s site.")
        if (qs){
            //nothing - go to link
            } else{
            return false; // do not go to link
        };
    });
    
    
    //turn on form hints - jquery plugin -- sets 'title' attribute to the form hint
    //$('input[title != ""]').hint();
    
    $('#details_exemptions #propExemptionsCounty ul.exemptionList li:odd').addClass('alt');
    $('#details_exemptions #propExemptionsFind ul.exemptionList li:odd').addClass('alt');
    $('#details_exemptions #propExemptionsSchool ul.exemptionList li:odd').addClass('alt');
    
    //push footer down on short pages
    if ($(window).height() > $(document).height()) {
        $('#bd').css({
            height: $('#bd').height() +
                ($(window).height() -
                $(document).height()) + 'px'
        });
    };
   
    /* Adds 'first' and 'last' to UL/LI for print features/styles */
    $('#details_prc #prcData ul li:first').addClass("first");
    $('#details_prc #prcData ul li:last').addClass("last");
   
    /* date picker */
    Date.format = 'mm/dd/yyyy';
    $('.date-pick').datePicker({startDate:'01/01/1899'})
    $('#ctl00_cphBody_txtSalesDateBegin').bind(
	    'dpClosed',
	    function(e, selectedDates)
	    {
		    var d = selectedDates[0];
		    if (d) {
			    /*$('#ctl00_cphBody_txtSalesDateEnd').dpSetStartDate(d.addDays(1).asString());*/
			    $('#ctl00_cphBody_txtSalesDateEnd').dpSetStartDate(d.addDays(1).asString());			    
		    }
	    }
    );
    $('#ctl00_cphBody_txtSalesDateEnd').bind(
	    'dpClosed',
	    function(e, selectedDates)
	    {
		    var d = selectedDates[0];
		    if (d) {
			    /*$('#ctl00_cphBody_txtSalesDateBegin').dpSetEndDate(d.addDays(-1).asString());*/
			    $('#ctl00_cphBody_txtSalesDateBegin').dpSetEndDate(d.addDays(-1).asString());
		    }
	    }
    );
    
    /* mask date fields*/
    $('.date-pick').mask("99/99/9999",{placeholder:"  "});

    /* png fix */
    $('img[@src$=.png], div.propGISimg img').ifixpng().iunfixpng();
    $('div#wevalue').ifixpng();
    $('a.dp-choose-date').ifixpng();  
    $('#specialLink').ifixpng();
    $('#decor').ifixpng();
    $('#advanced_property_location li.first img').ifixpng();
    
   
    /* tooltips on detail page */
    $('#detailsWrapper .shortTip').Tooltip({
        track: 		false,
	    delay: 		500,
	    showURL:	false,
	    showBody:	" - ",
	    fixPNG: 	true,
	    top:        -17,
	    left:       20,
        extraClass: "shortImg"
    });

    $('#detailsWrapper .longTip').Tooltip({
        track: 		false,
	    delay: 		500,
	    showURL:	false,
	    showBody:	" - ",
	    fixPNG: 	true,
	    top:        -17,
	    left:       20
    });
    
    /* collapse/expand on detail page */
    //hide traversing data by default
    //$('div#detailsWrapper div.propTrav h3').toggleClass('closed');
    //$('div#detailsWrapper div.propTrav h3').next('div').hide();
    
    //hide all buildings except the first one
    $('div#buildingsDetailWrapper h3:gt(0)').toggleClass('closed');
    $('div#buildingsDetailWrapper h3:gt(0)').next('div').hide();
    
    //identifies the clickable element
    $('div#detailsWrapper div.collapsable div h2').click(function() {
            //toggle the 'closed' class -- changes the + image to a - or vise versa.
            $(this).toggleClass('closed')
                //find the next div element and toggle it's slide effect: just hide and ease it out or in.
	            .next('div').SlideToggleUp(500);
    });
    
//    $('div.propTrav h3').click(function() {
//            $(this).toggleClass('closed')
//	            .next('div').SlideToggleUp(500);
//    });
    
    $('div#buildingsDetailWrapper h3').click(function() {
            $(this).toggleClass('closed')
	            .next('div').SlideToggleUp(500);
    });

    /* fix empty li for address2 line on property detail */
    $('#detailsWrapper .data ol li:has(span:empty)').hide();
    $('#detailsWrapper .data ol li:empty').hide();
    
    /* Fix empty li for Subdivision lookup */
    $('#searchResults fieldset ol#subdivResultsButtons li:empty').hide();
    
    //temp fix for errors
    $('ul.errors li:empty').hide();
    
    
});