//Animate navigation manu
$(document).ready(function() {
    categiriesMenu();
    exposeMenu();
    removeBorderFromLastLi();
    assignListStyles();
    editOrderStatus();
    removeAddressTarget();
     if(!jQuery.browser.msie ) {
        priMenuWobbly();
     };
});

function exposeMenu(){
	$(' a[href*=/catalog/sale-items]').addClass('saleitem');
	//$(".sidebar-left .block-uc_catalog ul:first li:nth-child(2)").filter(":first").addClass('saleitem');
}

// Animate primary lins to be woobly 
function priMenuWobbly(){
    $("#navlist li > a").hover(function() {
            $(this).animate({fontSize:"1.6em"}, 300);
        },
        function() {
            $(this).animate({fontSize:"1.2em"}, 500);
        });
}

// Show and hide new blocks in dropdown menu
function categiriesMenu(){
// $(".block-uc_catalog .content ul").css({display: "none"}); // Opera Fix
$(".block-uc_catalog .content li").hover(function(){
        $(this).find('ul:first').css({visibility: "visible",display: "none"}).show(600);
        },function(){
        $(this).find('ul:first').css({visibility: "hidden"});
        });
};

// Assign right list styls if item has children
function assignListStyles(){
    $('.block-uc_catalog .content li a').hover(function(){
        if ($(this).parent().next().get(0).tagName.toLowerCase()
 == 'ul')
        $(this).css({cursor:"default"});
    },
    function() {
    }
    );
};

// Remove bottom border from last element of the list
function removeBorderFromLastLi(){
    $(".block-uc_catalog ul li:last-child").css({border:"none"});
};


// Disable click if link si not last in its category
function removeAddressTarget(){
    $(".block-uc_catalog .content li a").click(function(){
    if ($(this).parent().next().get(0).tagName.toLowerCase() == 'ul')
        return false;
    });
};

function editOrderStatus(){
    $("form#uc-order-view-update-form select.form-select").change(function() {

    var message = "Your order has been received";

    if ($(this).val() == 'received_stock')
     message += " and is currently being processed. Orders are normally despatched within 24hrs and confirmation of this will be mailed directly to you as soon as our courier uplifts your order.";
     else if($(this).val() == 'received_nostock')
     message += ", however the item you have requested is temporarily out of stock. Delivery of out of stock items is normally within 5 working days by express courier. Any further delay to your order will be notified immediately. Should you wish to amend your order please contact customer services within 24 hours on sales@scottmurraymotorcycles.co.uk or by calling 01383 840842.";
     else if ($(this).val() == 'received_partstock') 
     message += ",however part of your order is temporarily out of stock. Delivery of out of stock items is normally within 5 working days by express courier. Your order will be despatched as soon as all items are available. Any further delay to your order will be notified immediately. Should you wish to amend your order please contact customer services within 24 hours on sales@scottmurraymotorcycles.co.uk or by calling 01383 840842.";

        if ($(this).val() == 'received_partstock' ||
            $(this).val() == 'received_stock' ||
            $(this).val() == 'received_nostock'){
                $("div.update-controls input.form-checkbox").attr('checked',true);
                $("form#uc-order-view-update-form fieldset:first").removeClass('collapsed');
                $("form#uc-order-view-update-form fieldset:first textarea").attr('rows','15');
                $("form#uc-order-view-update-form fieldset:first textarea").val(message);
        }
        else {
            $("div.update-controls input.form-checkbox").attr('checked',false);
            $("form#uc-order-view-update-form fieldset:first").addClass('collapsed');
            $("form#uc-order-view-update-form fieldset:first textarea").val('');
            if ($(this).val() == 'completed' || $(this).val() == 'processing' )$("div.update-controls input.form-checkbox").attr('checked',true);
        }
    });
}