$(document).ready(function () {
    /*if ($.browser.msie) {
    if ($.browser.version == "6.0") {
    alert('ok');
    }
    }*/
    /*
    $('img').each(function () {
    var src = $(this).attr('src');
    if (src.indexOf("Medicinal-Plants") > -1) {
    alert($(this).css('height'));
    }
    });
    */

    $.ajaxSetup({
        // Disable caching of AJAX responses
        cache: false
    });

    $('#cartupdate').html($('#basketarea').html());



    $('input[id*="searchterm"]').focus(function () {
        if ($(this).val() == "Enter keyword/product code") {
            $(this).val("");
        }
    });

    $('input[id*="searchterm"]').blur(function () {
        if ($(this).val() == "") {
            $(this).val("Enter keyword/product code");
        }
    });

    $("#basketarea").hide();
    //$("#accordion").accordion({ collapsible: true });


    $(".mybasketImg").hover(function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("mybasket_jc_small", "mybasket_jc-hover_small"));
        } else {
            $(this).attr('src', src.replace("mybasket_small", "mybasket-hover_small"));
        }
    }, function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("mybasket_jc-hover_small", "mybasket_jc_small"));
        } else {
            $(this).attr('src', src.replace("mybasket-hover_small", "mybasket_small"));
        }
    });

    $(".hoverbutton").hover(function () {
        var src = $(this).attr('src');
        $(this).attr('src', src.replace(".png", "_hover.png"));
    }, function () {
        var src = $(this).attr('src');
        $(this).attr('src', src.replace("_hover.png", ".png"));
    });


    $(".checkoutImg").hover(function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("checkout_jc_small", "checkout_jc-hover_small"))
        } else {
            $(this).attr('src', src.replace("checkout_small", "checkout-hover_small"))
        }
    }, function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("checkout_jc-hover_small", "checkout_jc_small"))
        } else {
            $(this).attr('src', src.replace("checkout-hover_small", "checkout_small"))
        }
    });



    $('img[src*="buy"]').live('mouseover mouseout', function (event) {
        if (event.type == 'mouseover') {
            var src = $(this).attr('src');
            if (src.indexOf("_jc") > -1) {
                $(this).attr('src', src.replace("buy_jc", "buy_jc_hover"));
            } else {
                $(this).attr('src', src.replace("buy", "buy_hover"));
            }
        } else {
            var src = $(this).attr('src');
            if (src.indexOf("_jc") > -1) {
                $(this).attr('src', src.replace("buy_jc_hover", "buy_jc"));
            } else {
                $(this).attr('src', src.replace("buy_hover", "buy"));
            }
        }
    });

    $(".searchbutton").hover(function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("search_jc", "search_jc_hover"))
        } else {
            $(this).attr('src', src.replace("search", "search_hover"))
        }
    }, function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("search_jc_hover", "search_jc"))
        } else {
            $(this).attr('src', src.replace("search_hover", "search"))
        }

    });
    $(".morebutton").hover(function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("moreinfo_jc", "moreinfo_jc_hover"))
        } else {
            $(this).attr('src', src.replace("moreinfo", "moreinfo_hover"))
        }
    }, function () {
        var src = $(this).attr('src');
        if (src.indexOf("_jc") > -1) {
            $(this).attr('src', src.replace("moreinfo_jc_hover", "moreinfo_jc"))
        } else {
            $(this).attr('src', src.replace("moreinfo_hover", "moreinfo"))
        }

    });

    $(".halffadeimagebox").fadeTo(0, 0.80);
    $(".halffadeimagebox").hover(function () {
        $(this).fadeTo(200, 1);
    }, function () {
        $(this).fadeTo(200, 0.80);
    });        
    $(".fadeimagebox").fadeTo(0, 0.80);
    $(".fadeimagebox").hover(function () {
    $(this).fadeTo(200, 1);
    }, function () {
    $(this).fadeTo(200, 0.80);
    });
    $(".hometext").hover(function () {
        $(".homefadeimagebox").stop(true,true).fadeTo(0, 1);
    }, function () {
        $(".homefadeimagebox").fadeTo(0, 1);
    });

    /*$(".mybasketImg").toggle(function () {
    $("#basketarea").css("visibility", "visible");
    $("#basketarea").slideDown();
    }, function () {
    $("#basketarea").slideUp();
    });*/


    $(".mybasketImg").click(function () {
        if ($("#basketarea").is(':visible')) {
            $("#basketarea").slideUp(500, function () {
                $("#basketarea").css("visibility", "hidden");
            });
        } else {
            $("#basketarea").css("visibility", "visible");
            $("#basketarea").slideDown(500);
        }
    });

    $('#tdbasket').hover(function () {

    }, function () {
        $("#basketarea").delay(500).slideUp(500, function () {
            $("#basketarea").css("visibility", "hidden");
        });
    });

    $('.basketdiv').hover(function () {
        $(this).stop(true, true).css("visibility", "visible").slideDown(500);
    }, function () {
        $(this).delay(500).slideUp(500, function () {
            $(this).css("visibility", "hidden");
        });
    });

    $("#cartupdate").hide();
    $("#cartupdate").css("visibility", "visible");
    $("#cartupdate").slideDown(500);
    $("#cartupdate").animate({ opacity: 1.0 }, 2000).fadeOut();

    /*
    $(".continuebutton").click(function () {
    $("#cartupdate").hide();
    });
    */
    /*$(".menu2").fadeTo(0, 0);
    $(".menu3").hide();
    $(".otherspan").hover(
    function () {
    $(".menu3").show();
    $(this).addClass('bggreen6');
    },
    function () {
    $(".menu3").hide();
    $(this).removeClass('bggreen6');
    }
    );

    $(".menuitem1").hover(
    function () {
    $(this).find(".menu2").css("visibility", "visible");
    $(this).find(".menu2").stop().fadeTo("slow", 1);
    $(this).addClass('bggreen7');
    },
    function () {

    $(this).find(".menu2").stop().delay(200).fadeTo("slow", 0);
    $(this).find(".menu2").css("visibility", "hidden");
    $(this).removeClass('bggreen7');
    }
    );
    */


    $('.otherdiv').hover(function () {
        $(this).addClass('bggreen9');
    }, function () {
        $(this).removeClass('bggreen9');
    });


    $('.subcmsmenu').each(function () {
        var nbchar = 0;
        var longest = "";
        var id = $(this).attr('id');
        var id1 = "#" + id + " > li";
        $(id1).each(function () {
            var txt = $(this).find('a').html();
            if (txt != null) {
                if (txt.length > nbchar) {
                    nbchar = txt.length;
                    longest = txt;
                }
            }
        });
        var width = Math.max(nbchar * 7, 100);
        $(this).width(width);
        var id2 = "#" + id + "> li";
        $(id2).each(function () {
            $(this).width(width);
            $(this).find('ul').css('left', width);
        });
    });

    $('.subcmsmenu > li').hover(function () {
        $(this).children('ul').css('visibility', 'visible');
    }, function () {
        $(this).children('ul').css('visibility', 'hidden');
    });

    $('.otherdiv').hover(function () {
        $(this).children().css('visibility', 'visible');
    }, function () {
        $(this).children().css('visibility', 'hidden');
    });

    $('.greengradient1_cms').hover(function () {
        if (!$.browser.msie) {
            $(this).addClass("cmsmenulihover");
        }
    }, function () {
        if (!$.browser.msie) {
            $(this).removeClass("cmsmenulihover");
        }
    });
});

$(function () {
    $('#navigation a, .fadeimagebox a').click(function () {
        var $self = $(this);
        $('#action').load($('#websiteurl').val() + "/Ajax/cleansession.aspx", function () {
            document.location = $self.attr('href');
        });
        return false;
    });
});








