﻿/**/// CrabTree site scripts


/**/// method inits ajax functionality used for cloud boxes
function initClouds() {
//    var rowNo = 0;
//    $('ul.clouds li').each(function (elementId) {
//        if (elementId % 2 == 0) {
//            $(this).attr('id', 'question_' + rowNo);
//            $(this).find('a').attr('rel', 'answer_' + rowNo);

//            $(this).find('a').click(function () {
//                var answerId = $(this).attr('rel');
//                $('#' + answerId).toggle('fast');
//            });
//        }
//        else {
//            $(this).attr('id', 'answer_' + rowNo);
//            rowNo++;
//        }
    //    });
    $('a[rev="showPriceLink"]').each(function (elementId) {
        var cloudId = '#' + $(this).attr('rel');
        var linkRef = $(this);
        $(this).click(function () {
            $(cloudId).slideToggle('slow', function () {
                // is expanding
                if (linkRef.hasClass('down')) {
                    linkRef.removeClass('down');
                    linkRef.addClass('up');
                    linkRef.html('Hide price');
                }
                // is closing
                else {
                    linkRef.removeClass('up');
                    linkRef.addClass('down');
                    linkRef.html('Show price');
                }
            });
        });
    });
}

/**/// Resize the popup to element with particular id
function resizeTo(id) {
    $.colorbox.resize(id);
}

/**/// Init popups with searchbox inside
function initSearchboxPopup(rel) {
    $('a[rel="' + rel + '"]').colorbox({ maxWidth: 600, next: "", previous: "", inline: true,
        rel: "nofollow", loop: false, current: '', onComplete: function () { resizeTo($(this).attr('rev')); }, href: function () {
            var rel = '#' + $(this).attr('rev');
            return rel;
        }
    });
}

/**/// Init popups with google map inside
function initGoogleMapPopup(rel) {
    $('a[rel="' + rel + '"]').colorbox({ width: 710, height: 550, iframe: true, loop: false, next: '', rel: "nofollow",
        previous: '', current: '' });
}

function alertNotSupported() {
    alert("Sorry, this function is not supported yet.");
}

$(document).ready(function () {
    /**/// try to recognize the browser
    /**/// NOTE: currently not used
    /**/// var browser = $.browser;

    /**/// bind superfish to main menu
    $("ul.sf-menu").superfish({
        animation: { width: 'show' },
        delay: 600
    });

    /**/// assign css classes for colorbox container
    $('a[rel="group_popupGMap"], a[rel="group_popupSearch"]').each(function () {
        $(this).click(function () {
            $('#colorbox').removeClass();
            $('#colorbox').addClass($(this).attr('rel'));
        });
    });

    /**/// adds "last-child" class where needed
    $(".preserve-last").each(function () {
        $(this).children(":last-child").addClass("last-child");
    });
});
