﻿var HintClass = "hintTextbox";
var HintActiveClass = "hintTextboxActive";
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
function hasClass(ele, cls) {
    return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(ele, cls) {
    if (!this.hasClass(ele, cls)) ele.className += " " + cls;
}
function removeClass(ele, cls) {
    if (hasClass(ele, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        ele.className = ele.className.replace(reg, ' ');
    }
}
function initHintTextboxes() {
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        var input = inputs[i];
        if (input.type != "text" && input.type != "password")
            continue;

        if (hasClass(input, HintClass)) {
            input.hintText = input.value;
            input.onfocus = onHintTextboxFocus;
            input.onblur = onHintTextboxBlur;
        }
    }
}
function onHintTextboxFocus() {
    var input = this;
    if (input.value.trim() == input.hintText) {
        input.value = "";
        addClass(input, HintActiveClass);
    }
}
function onHintTextboxBlur() {
    var input = this;
    if (input.value.trim().length == 0) {
        input.value = input.hintText;
        removeClass(input, HintActiveClass);
    }
}
function alternate(id) {
    if (document.getElementsByTagName) {
        var tables = document.getElementById(id);
        var table = tables.getElementsByTagName("table");
        for (var j = 0; j < table.length; j++) {
            var rows = table[j].getElementsByTagName("tr");
            for (var i = 0; i < rows.length; i++) {
                //manipulate rows
                // KL - do not remove existing class names...
                if (i % 2 == 0) {
                    rows[i].className +=" even";
                } else {
                rows[i].className += " odd";
                }
            }
        }
    }
}
function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
// KL
function openHeader() {
    $(this).parent().find("ul.sub").slideToggle("normal");
    $(this).attr('src', '/Styles/images/blackArrow_rot.gif');
}

function closeHeader() {
    $(this).parent().find("ul.sub").slideToggle("normal");
    $(this).attr('src', '/Styles/images/blackArrow.gif');
}

function loadTestimonials() {
    var getUrl = "/Menu/GetTestimonials";
    // getting the data
    $("#testimonialList").html('<p style="text-align:center;"><img src="/Styles/images/ajax-loader.gif" width="19" height="19" /></p>');
    $.ajax({
        url: getUrl,
        success: function(result) {
            $("#testimonialList").html(result);
            // binding the carousel
            $("#teaser_slider").jcarousel({
                scroll: 2,
                visible: 2,
                auto: 5,
                vertical: true,
                buttonNextHTML: null,
                buttonPrevHTML: null
            });
        }
    });
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {

    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function init() {
    initHintTextboxes();
    alternate("centerColumn");
    pngFix();
    jQuery(document).ready(function() {
        if ($('#paginate-slider').length != 0) {
            jQuery('#paginate-slider').jcarousel({
                scroll: 1,
                visible: 3,
                wrap: "both",
                initCallback: mycarousel_initCallback
            });

            var carousel;
                        if (document.getElementById("slider")) {
                            featuredcontentslider.init({
                                id: "slider",
                                contentsource: ["inline", ""],
                                nextprev: ["", "Next"],
                                revealtype: "mouseover",
                                enablefade: [true, 0.07],
                                autorotate: [true, 4000],
                                onChange: function(previndex, curindex) {
                                    jQuery('#paginate-slider').data('jcarousel').scroll(jQuery.jcarousel.intval((curindex)));
                                }
                            });
                        }
        }

        // loading testimonials via ajax
        // as of v1.8.2
        // loadTestimonials();

        if (document.getElementById("map")) {
            featuredcontentslider.init({
                id: "map",
                contentsource: ["inline", ""],
                nextprev: ["", "Next"],
                revealtype: "mouseover",
                enablefade: [true, 0.07],
                autorotate: [true, 4000],
                onChange: function(previndex, curindex) {
                }
            });
        }

    });

    if (document.getElementById("galleria")) {
        Galleria.loadTheme('js/themes/classic/galleria.classic.js');
        $('#galleria').galleria({
            image_crop: false,
            transition: 'slide'

        });
    }


    // KL reworked on 2010.07.12
    $("ul.categories ul.sub").slideUp(0);
    $("ul.categories a.activeMain").parent().find("ul.sub").slideDown(0);

    $("ul.categories img.toggle_btn").toggle(openHeader, closeHeader);

    // KL reworked on 2010.08.18
    if (document.getElementById("openQuote")) {

        $("#rightColumn #openQuote").toggle(
          function() {
            $("#quoteDiv").show('normal');
            $(this).html("Close details");
            },
        function() {
            $("#quoteDiv").hide('normal');
            $(this).html("View details");
        }
    )
    }

}
window.onload = init; 








 
