/**
 * Metaltech Services Ltd jQuery functions
 *
 * @author Martin Bean <martin@digitalpop.co.uk>
 * @copyright 2010 http://www.msl-ltd.com
 */
$(document).ready(function() {
    $('body').css('overflow-y', 'scroll');
    $('a[rel=external]').click(function() {
        window.open(this.href);
        return false;
    });
    accordionMenu();
	defaultValue('input#keywords', 'Search...');
	//initLightbox('a[rel=lightbox]');
	productImages();
});

//
function accordionMenu() {
    $('#menu ul').hide();
    $('#menu li.selected ul').show();
    $('#menu a').click(function() {
        var nextElm = $(this).next();
        var speed = 333;
        if (nextElm.is('ul')) {
            $('#menu ul:visible').slideUp(speed);
            if (nextElm.is(':visible')) {
                // do nothing
            } else {
                $('#menu ul:visible').slideUp(speed, function() {
                    $(this).parent(0).removeClass('selected');
                });
                $(this).parent(0).addClass('selected');
                $(this).next().slideDown(speed);
            }
            return false;
        }
    });
};

//
function defaultValue(elm, value) {
	if ($(elm).val()=='') {
		$(elm).val(value);
	}
	$(elm).focus(function() {
		if ($(elm).val()==value) {
			$(elm).val('');
		}
	});
	$(elm).blur(function() {
		if ($(elm).val()=='') {
			$(elm).val(value);
		}
	});
};

//
function initLightbox(elm) {
    $(elm).lightBox({
        imageLoading:  lightbox_img_dir + 'loading.gif',
        imageBtnClose: lightbox_img_dir + 'close.gif',
        imageBtnPrev:  lightbox_img_dir + 'prev.gif',
        imageBtnNext:  lightbox_img_dir + 'next.gif',
        imageBlank:    lightbox_img_dir + 'blank.gif'
    });
};

//
function productImages() {
    $('#product_images a').click(function() {
        $('#main_product_image img').attr('src', this.href);
        return false;
    });
};