/**
 * 
 * Custom js (jQuery) functions of the application
 *
 */

// simple accordeon menu
jQuery.fn.accordeonMenu = function () {
    var menu = $(this);
    $('> li > a:not(.active) ~ .sub', menu).hide();
    var items = $('> li > a', menu).click(function () {
        items.removeClass('active');
        $(this).addClass('active').siblings('.sub').slideDown('normal');
        items.not('.active').siblings('.sub').slideUp('normal');
    });
    return menu;
};//eof accordeonMenu

jQuery.fn.digitsOnly = function () {
    var $this = $(this);
    $this.keypress(function (e) {
        // allow digits only
        if (e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
            return false;
        }
    });
    return $this;
};

$(document).ready(function () {

    $('a.menu_item').click(function () {
        $.cookie('selected_path', $(this).attr('__path'), {path: '/'});
    });

    $('a[rel*=facebox]').facebox({
        opacity: 0.3,
        loadingImage: '/img/facebox/loading.gif',
        closeImage: '/img/facebox/closelabel.gif'
    });
    
    
    /* color picker */
	$('#colorSelector').ColorPicker({
		color: '#0000ff',
		onShow: function (colpkr) {
			$(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			$(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			$('#colorSelector div').css('backgroundColor', '#' + hex);
			$('#confbg div').css('backgroundColor', '#' + hex);
		}
	});
});

