﻿
// *** HTML element functions ***

// For rangiora bakery specific:
function changeWrapper(newWrapperClass) {

    $('.wraper').removeClass('homeWrapper');
    $('.wraper').addClass(newWrapperClass);

}

function setMenu(menuID) {

    $('#' + menuID).fadeOut('slow');

    $('#' + menuID).fadeIn('slow');
    


}

// end rangiora bakery specific

function populateDropdown(select, data, firstItemText, disabledItemText) {
    select.empty();

    if (data.Items.length > 0) {

        $(select).removeAttr("disabled");

        select.
            append($("<option></option>").
            attr("value", "").
            text(firstItemText));

        $.each(data.Items,
					function (i, Item) {

					    select.
                          append($("<option></option>").
                          attr("value", Item.Value).
                          text(Item.Name));
					});
    }
    else {

        if (disabledItemText == null) {
            select.hide();
        }
        else {
            select.
            append($("<option></option>").
            attr("value", "").
            text(disabledItemText));

            select.attr("disabled", "disabled");
        }

    }
}


// *** General helpers ***
function showLoading() {
    $('#divLoading').center();
    $('#divLoading').fadeIn('fast');
    $('.otherLoading').fadeIn('fast');    
}

function hideLoading() {
    
    $('#divLoading').fadeOut('fast');
    $('.otherLoading').fadeOut('fast');
}

jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
} 

// *** jQUERY UI extension methods ***
// Script to initialise for each page
function initialiseDatePickers() {
    $(".datepicker").datepicker({ dateFormat: 'dd M yy' });
}


// *** Drop Down Menus ***
function makeDropDownMenus() {

    $('.nav li').hover(
		        function () {
		            //show its submenu
		            $('ul', this).slideDown(100);

		        },
		        function () {
		            //hide its submenu
		            $('ul', this).slideUp(100);
		        }
	        );

    $('.nav li').click(

                function () {
                    //hide its submenu
                    $('ul', this).slideUp(100);
                }

                );

            }

            // *** Top Drop Down Menus ***
            function makeTopDropDownMenus() {

                $('.topnav li').hover(
	function () {

	    //get the position of the placeholder element   
	    var pos = $(this).offset();

	    var firstPos = $('.topnav li').offset();
	    var width = $(this).width();   //show the menu directly over the placeholder   

	    var topOffset = 5;
	    if ($.browser.msie) {
	        topOffset = 5;

	        if ($.browser.version < 8)
	            topOffset = -4;

	    }
        
	    $('.NavItem', this).css({ "left": (pos.left - firstPos.left) + "px", "top": ($(this).height() + topOffset) + "px" });

	    //show its submenu	    
	    $('.NavItem', this).slideDown(100);


	},
	function () {
	    //hide its submenu
	    $('.NavItem', this).slideUp(100);
	}
);

                $('.topnav li').click(

    function () {
        //hide its submenu
        $('.NavItem', this).slideUp(100);
    }

    );

}


function makeNav(navItem){
    $('#' + navItem).css("color", "#444444");
}




