$(document).ready(function () {
    $("#container").supersleight();
    Menu.Init();
    var section = $('head').attr("rel");

    if (section) {
        var img$ = GetImage(section);
        img$.addClass("on").attr('src', img$.attr("src").replace('_s1.png', '_s2.png'));
    }

    $("#mainnav li").hover(
		function () {
		    //		    $("ul", this).fadeIn("slow");
		    $("ul", this).show();
		},
		function () {
		    //		    $("ul", this).fadeOut("fast");
		    $("ul", this).hide();
		}
	);
    $(".subnav").hover(
		function () {
		    var img$ = $(this).parent().find(".tn");
		    m.si(img$, img$.attr('src').replace('_s1.png', '_s2.png'));
		},
		function () {
		    var img$ = $(this).parent().find(".tn");
		    m.si(img$, img$.attr('src').replace('_s2.png', '_s1.png'));
		}
	);

    $(".modal").fancybox({
        autoDimensions: false,
        margin: 0,
        width: 900,
        height: 600,
        type: 'iframe'
    });

    $('.editable').hover(function () {
        $(this).addClass("editback");
        $(this).attr("title", "Double Click to edit this content.");
    }, function () {
        $(this).removeClass("editback");
    });


    $(".editable").bind("dblclick", function () {
        $.fancybox(root + 'admin/content/?ID=' + $(this).attr("rel"), {
            autoDimensions: false,
            margin: 10,
            width: '95%',
            height: '95%',
            type: 'iframe'
        });
        return false;
    });


    $('.datagrid').tableHover({ allowHead: false });


    $("#signup").click(function () {
        $('#ea').val($('#Email').val());
        $('#ccoptin').submit();
    });


    $("#Email").watermark("Enter Email");

});
function GetImage(alt) {
    var img$ = $(".nav > li > a > img").filter(function (index) {
        return $(this).attr("alt") == alt;
    })
    return img$;
}
function SetImage(elt, src) {
    $(elt).attr('src', src);
}
$.fn.hoverClass = function (c) {
    return this.each(function () {
        $(this).hover(
			function () { $(this).addClass(c); },
			function () { $(this).removeClass(c); }
		);
    });
};

Menu = {
    Init: function () {
        $('.nav img').preload({
            find: '_s1.png',
            replace: '_s2.png'
        });
        $('.nav img').hover(function () {
            Menu.Over(this);
        }, function () {
            Menu.Out(this);
        });
    },
    Over: function (elt) {
        if (!$(elt).hasClass('on')) {
            SetImage(elt, $(elt).attr('src').replace('_s1.', '_s2.'));
        }
    },
    Out: function (elt) {
        if (!$(elt).hasClass('on')) {
            SetImage(elt, $(elt).attr('src').replace('_s2.', '_s1.'));
        }
    }
}

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 RefreshContent(id, content) {
    $('[rel=' + id + ']').html(content);
}
