$(document).ready(function () {
    //    $.preload(['s0', 's1', 's2', 's3', 's4', 's5', 's6'], {
    //        base: root + 'style/images/',
    //        ext: '.png'
    //    });

    $("#container").supersleight();
    m.i();
    $("#nav > li").hover(
		function () {
		    $("ul", this).show();
		},
		function () {
		    $("ul", this).hide();
		}
	);
   
    $(".subnav").hover(
		function () {
		    var img = $(this).parent().find("img.tn");
		    m.si(img, img.attr('src').replace('_s1.png', '_s2.png'));
		},
		function () {
		    var img = $(this).parent().find("img.tn");
		    m.si(img, img.attr('src').replace('_s2.png', '_s1.png'));
		}
	);

 


    //    $(".crumbs li a:last").addClass("background-none");



    //    try {
    //        $(".shadow").each(function () {
    //            var d = $(this);

    //            d.wrap('<div class="shadowcontainer" />');

    //            var t = $("<div></div>").attr("class", "shadowtop");
    //            t.insertBefore(d);

    //            var b = $("<div></div>").attr("class", "shadowbottom");
    //            b.insertAfter(d);
    //        });
    //    } catch (e) {

    //    }



    //    $('input.search').autocomplete({
    //        serviceUrl: root + "search/default.aspx",
    //        minChars: 2,
    //        maxHeight: 400,
    //        width: 300,
    //        zIndex: 9999,
    //        deferRequestBy: 0, //miliseconds
    //        onSelect: function (value, data) {
    //            window.location = root + "products/by-cas-number/" + data + "/";
    //            //            alert('You selected: ' + value + ', ' + data);
    //        }

    //    });


    //    $(".form").each(function (e) {
    //        $(this).keypress(function (e) {
    //            if (e.which == 13 && e.target.type != 'textarea') {
    //                eval($(this).find('.submit').attr('href'));
    //            }
    //        });
    //    });


    //    $("span.linklist").each(function () {
    //        var l = $(this).find("a").length;
    //        $("a", this).map(function (index) {
    //            if (index < l - 1) {
    //                $(this).after(", ");
    //            }
    //        });
    //    });

    //    $("#searcha").click(function () {
    //        window.location = root + "search/?q=" + $(".search").val();
    //    });

    //    $(".search").keypress(function (e) {
    //        if (e.which == 13) {
    //            window.location = root + "search/?q=" + $(".search").val();
    //        }
    //    });

    //    if ($("#productcategory").exists()) {
    //        if ($("#productcategory .item").length < 2) {
    //            $("#productcategory").addClass("nb");
    //        }
    //    }
    SetupModal(null, null);

    if ($('#cycle').exists()) {
        var slider = $('#cycle').movingBoxes();
//        $.fn.getMovingBoxes.goForward();
    }

    //var x = ($("#bottombanner").position().top - 16) + "px";
    //$("#social").css("top", x);

    var opened = false;
    $(".socialcontrol").click(function () {
        if (opened) {
            $("#social").addClass("social").removeClass("social2").animate({ "height": "166px" }, 300);
            $("#socialopen").toggle();
            $("#socialclose").toggle();
            $(".video").toggle();
        } else {
            $("#social").animate({ "height": "477px" }, 300, function () {
                $("#social").addClass("social2").removeClass("social");
            });
            $("#socialopen").toggle();
            $("#socialclose").toggle();
            $(".video").toggle();
        }
        $("#socialcontent").slideToggle("fast");
        opened = opened ? false : true;
        return false;
    });


    $(".minimodal").fancybox({
        autoDimensions: false,
        margin: 0,
        width: 600,
        height: 300,
        type: 'iframe'
    });
});
function SetupModal(sender, args) {
    $(".modal").fancybox({
        autoDimensions: false,
        margin: 0,
        width: 900,
        height: 600,
        type: 'iframe'
    });
}
$.fn.hoverClass = function (c) {
    return this.each(function () {
        $(this).hover(
			function () { $(this).addClass(c); },
			function () { $(this).removeClass(c); }
		);
    });
};
jQuery.fn.exists = function () { return jQuery(this).length > 0; }

m = {
    i: function () {
        $(".hover img:not(.exclude)").hover(function () {
            m.o(this);
        }, function () {
            m.ou(this);
        });
    },
    o: function (e) {
        if (!$(e).hasClass('on')) {
            m.si(e, $(e).attr('src').replace('_s1.png', '_s2.png'));
        }
    },
    ou: function (e) {
        if (!$(e).hasClass('on')) {
            m.si(e, $(e).attr('src').replace('_s2.png', '_s1.png'));
        }
    },
    si: function (e, s) {
        if ($.browser.msie && $.browser.version < 7 && $(e).hasClass("png")) {
        } else {
            $(e).attr('src', s);
        }
    }
}
function GotoValidationSummary() {
    if (typeof (ValidatorOnSubmit) == "function") {
        var isValidated = ValidatorOnSubmit();
        if (!isValidated) {
            var pos = $("#validationsummary").show().position();
            window.scrollTo(pos.left, pos.top);
            return false;
        }
        return true;
    }
}
function GetImage(id, alt) {
    var img$ = $("#" + id + " img").filter(function (index) {
        return $(this).attr("alt") == alt;
    })
    return img$;
}
function GetByRel(id, rel) {
    var img$ = $("#" + id + " img").filter(function (index) {
        return $(this).attr("rel") == rel;
    })
    return img$;
}
