﻿/// <reference path="jQuery/jquery-1.4.2.min.js" />
/// <reference path="cycleLite/jquery.cycle.lite.1.0.js" />
/// <reference path="prettyCheckboxes/jquery.prettyCheckboxes1.1.min.js" />
/// <reference path="hint/jquery.contour.hint.js" />
/// <reference path="colorbox/jquery.colorbox-min.js" />
/// <reference path="SWFObject/swfobject.js" />


//This is the site URL without the http:// (does not end in /)
siteURL = window.location.hostname;

//Add the http:// and closing slash
siteURL = "http://" + siteURL + "/";


/* -- jQuery when DOM is ready -- */
$(document).ready(function () {

    //Homepage image crossfade
    $("#imageCarousel div").cycle();

    //Map options custom checkboxes
    $("#mapOptions input[type=checkbox]").prettyCheckboxes({
        checkboxWidth: 22,              // The width of your custom checkbox
        checkboxHeight: 23,             // The height of your custom checkbox
        className: 'prettyCheckbox',    // The classname of your custom checkbox
        display: 'inline'               // The style you want it to be display (inline or list)
    });

    //Gallery links
    $("a.gallery").colorbox({ opacity: "0.5" });

    //Form watermark (use <small> tag)
    $(".contourField").contourhint();

    // Init the tablesorter on the pricelist
    $("#data").tablesorter({ sortList: [[0, 0]], widgets: ['zebra'] });

    //Map options custom checkboxes
    $(".filtersection input[type=checkbox]").prettyCheckboxes({
        checkboxWidth: 22,              // The width of your custom checkbox
        checkboxHeight: 23,             // The height of your custom checkbox
        className: 'prettyCheckbox',    // The classname of your custom checkbox
        display: 'inline'               // The style you want it to be display (inline or list)
    });

    // Init the filters on the pricelist
    $("input.filter").click(function () {
        
        var current = this;
        var css_class = $(this).attr("name");
        
        // This if, makes sure that we dont toggle items hidden by the "build step" above
        if (css_class == "sold")
        {
            var steps = $("ul#steps li input:checked");
            
            $.each(steps, function(key, value) {

                $.each($(document).find("tr." + $(value).attr("name")), function (key, value) {
                    if ($(current).is(":checked"))
                    {
                        if ($(value).hasClass("sold"))
                        {
                            $(value).hide();
                        }
                    }
                    else
                    {
                        if ($(value).hasClass("sold"))
                        {
                            $(value).show();
                        }
                    }
                });
            });
        }
        else
        {
            if ($(this).is(":checked"))
            {
                 $(document).find("tr." + css_class).show();
            }
            else
            {
                $(document).find("tr." + css_class).hide();
            }
        }  
        
    });

});

function displayApartment(apartmentID) {

    //DEBUG 
    //alert("DEBUG: displayApartment called with " + apartmentID);

    $("#apartmentInfo").load(siteURL + apartmentID + ".aspx #apartmentInfo", function () {

        // remove the second apartmentId from the DOM completely.
        $(this).children().unwrap();

        //Load in the apartment floor plan
        $("#buildingViewerWrapper span").load(siteURL + apartmentID + ".aspx #buildingViewerWrapper span", function () {
            //re-do links loaded in
            $("a.gallery").colorbox({ opacity: "0.5" });
        });

        // initialize tell a friend popup
        $(".emailFriend").colorbox({ width: 457, height: 480, iframe: true });        
    });
}

function WriteBuildingViewer(flashURL, footURL, filterURL, aid, bid, bid_xml) {

    var flashvars = {};
    flashvars.footprintUrl = footURL;
    flashvars.filterUrl = filterURL;
    flashvars.xmlSource = "/flashxml.aspx?bid=" + bid_xml; //Bid xml will always be empty as Kristian needs it like this

    if (aid != "") {
        flashvars.aid = aid;
    }

    if (bid != "") {
        flashvars.bid = bid;
    }

    var params = {};
    params.menu = "false";
    params.allowScriptAccess = "always";
    params.quality = "high";
    params.wmode = "transparent";


    var attributes = {};

    //swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
    swfobject.embedSWF(flashURL, "buildingViewer", "940", "370", "9.0.0", false, flashvars, params, attributes);
}



