﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />


Sys.Application.add_load(function() {


    pageSetUp();

    //Animate the check box wrapper to the height of the table that it contains. The table contains the check boxes.
    $(".checkBoxes_link").toggle(function() {
        var boxHeight = (($(".search_Check_Boxes").innerHeight() * 1) + 20) + "px";
        $(".search_Check_Boxes_Wrap").stop().animate({ height: boxHeight }, { duration: 800, easing: 'easeOutCubic' });
    }, function() {
        $(".search_Check_Boxes_Wrap").stop().animate({ height: '0px' }, { duration: 800, easing: 'easeOutCubic' });
    });

    //Latest Property over events
    $(".propPreview").hover(function() {
        //get the height of the 'details' element. The 'price' element to animate is hidden beneath this
        //so we need to know how far to animate it from the top of the container
        var elemHeight = (($("#" + ($(this).attr("id")) + " span.details").innerHeight() * 1)) + "px";

        $("#" + ($(this).attr("id")) + " span.price").stop().animate({ height: '28px', top: elemHeight }, { duration: 300, easing: 'easeOutCubic' });
    }, function() {
        $("#" + ($(this).attr("id")) + " span.price").stop().animate({ height: '0', top: '0' }, { duration: 300, easing: 'easeOutCubic' });
    });


    //Show blanket overlay and alert boxes For each of the various alerts.
    //These are currently fired by their differing class names for display purposes. 
    //How this will work in the live envirinment is up to the backend developers.

    //Add to property shortlist
    $(".loadOverLay").click(function() {
        //load the white overlay.
        loadOverlay();

        //get the id of the alert element that is to be shown. 
        //This will be the 2 character prefix of the clicked element's id.
        var showElem = $(this).attr("id");

        //Show the alert box after a pre determined time.
        //setTimeout('showAlert(showElem)', 1000);
        setTimeout(function() { showAlert(showElem) }, 1000);
    });

    //Hide blanket overlay and alert boxes.
    $(".closeAlert").click(function() {
        closeAlert();
    });

});

//Set any page defaults on load
function pageSetUp() {

    $('.slideShow').cycle({
        fx: 'fade',
        timeout: 5000,
        speed: 4000
    });
    
    //Match the two columns height to the main container
    var pageHeight = (($(".Wrapper_Container").innerHeight() * 1)) + "px";
    
    $(".Left_Column").css({ height: pageHeight });
    $(".Right_Column").css({ height: pageHeight });
}

//Logic to show the alert box and to possibly fill it with data? 
//For now the passed id of the clicked element matches that of the element to be displayed
function showAlert(elementToShow) {
    $("#alertBoxWrapper").fadeIn("fast");
    $("#alert_" + elementToShow).fadeIn("fast");

}

function closeAlert() {
    $("#alertBoxWrapper").fadeOut("fast");
    $(".alertDetailsWrap").fadeOut("fast");
    $("#blanketOverlay").fadeOut("slow");

}

//load the white overlay
function loadOverlay() {

    //get the height of the containing element and match the height of the overlay to it.
    $("#blanketOverlay").css({ height: $(".pageContent").height() + "px" });

    //re-enforce the opacity setting for the blanket here for the benifit of IE. 
    $('#blanketOverlay').css('filter', 'alpha(opacity=85)');

    //fade in the overlay.
    $("#blanketOverlay").fadeIn("slow");
}

//A request has been submitted so show thank you and fade out. 
//The window from which the request was made will be passed.
function submitRequest(id) {
    setTimeout(function() {closeAlert();}, 3000);
}


//the google code ie compliance js file (IE9.js) removes this padding.
//This is the only way we could find to keep it by resoring it here.
$(".contentWrap").css('padding', '0 9px');
