var Custom = {
    InitMenu: function() {
        var lstMenu = $("#lstMenu");
        var oMenuCont = $("#MenuCont").get(0);

        lstMenu.children(":last").addClass("last");


        var iWidth = 0;
        lstMenu.children().each(function() {
            iWidth += this.offsetWidth;
        });


        lstMenu.css("marginRight", ((940 - iWidth) / 2) + "px");

    },

    InitSideMenu: function() {

        $("#side-menu").find("ul").each(function() {
            $(this).children(":last").addClass("last");
        });

        $("#side-menu").find("H3").bind("click", function() {
            $("#side-menu").children().removeClass("opened");
            $(this).parent().addClass("opened");
        });

        $("#side-menu").find(".selected").parents("li:first").addClass("opened");
    },

    InitGallery: function() {
        $("#Gallery").children().each(function(idx) {
            if ((idx + 1) % 4 == 0) {
                $(this).addClass("last");
            }
        });


        $("#Gallery a").fancybox();
    },

    InitBogrim: function() {
        $("#lstBogrim").children(":last").addClass("last");
        $("#lstBogrim a").fancybox();
    },

    MarqueePlay: function(obj) {
        if ($.browser.version == 6) {
            $("#news-items").css("height", "auto").css("borderBottom", "none");
            return;
        }
        if (!obj.getAttribute('iMarqueeDataHeight'))
            obj.setAttribute('iMarqueeDataHeight', obj.offsetHeight);
        var iMarqueeDataHeight = obj.getAttribute('iMarqueeDataHeight');
        if (!obj.getAttribute('iMarqueeTop'))
            obj.setAttribute('iMarqueeTop', (obj.offsetHeight - 10));
        var iMarqueeTop = obj.getAttribute('iMarqueeTop');


        $(obj).children(":first").get(0).style.marginTop = iMarqueeTop + 'px';

        setInterval(function() {
            if (obj.getAttribute('bMarqueeStop') == 'true') {
                return;
            }
            iMarqueeTop--;
            if (iMarqueeTop < $(obj).children(":first").get(0).offsetHeight * -1) {
                //obj.appendChild(obj.firstChild);
                iMarqueeTop = obj.offsetHeight - 1;
                //obj.lastChild.style.marginTop=iMarqueeTop+'px';				
            }
            else $(obj).children(":first").get(0).style.marginTop = iMarqueeTop + 'px';
            obj.setAttribute('iMarqueeTop', iMarqueeTop);
        }, 40);
    },

    SendMail: function(sObj) {
        var sMsg = "אנא מלא ";
        var bValid = true;
        $(sObj).find("input").each(function() {
            if (this.value == "") {
                alert(sMsg + $(this).parents(":eq(1)").find("label:first").text().replace(/\:/gi, ""));
                bValid = false;
                return false;
            }
        });
        if (bValid) {
            $.ajax({
                type: "POST",
                cache: false,
                url: "getXML.aspx",
                dataType: "xml",
                data: "obj=MailSender&sFunc=SendContactForm&" + $(sObj).serialize(),
                success: function(xml) {
                    if ($(xml).find("Succeed") && $(xml).find("Succeed").text() == "true") {
                        alert("תודה על פנייתך!");
                        $(sObj).get(0).reset();
                    }
                },

                error: function(a1, a2, a3) {
                    alert("תקלה בשליחת הדואר, אנא נסה שנית מאוחר יותר.");
                }
            });
        }
    },
    SendMailInner: function(sObj) {
        var sMsg = "אנא מלא ";
        var bValid = true;
        $(sObj).find("input").each(function() {
            if (this.value == "") {
                alert(sMsg + $(this).parents(":first").prev().text().replace(/\:/gi, ""));
                bValid = false;
                return false;
            }
        });
        if (bValid) {
            $.ajax({
                type: "POST",
                cache: false,
                url: "getXML.aspx",
                dataType: "xml",
                data: "obj=MailSender&sFunc=SendContactForm&" + $(sObj).serialize(),
                success: function(xml) {
                    if ($(xml).find("Succeed") && $(xml).find("Succeed").text() == "true") {
                        alert("תודה על פנייתך!");
                        $(sObj).get(0).reset();
                    }
                },

                error: function(a1, a2, a3) {
                    alert("תקלה בשליחת הדואר, אנא נסה שנית מאוחר יותר.");
                }
            });
        }
    }
}

