function clearTxt(el) {
    if (el.value == "Explore O’Reilly’s") {
        el.value = "";
    }
}
function checkTxt(el) {
    if (el.value == "") {
        el.value = "Explore O’Reilly’s";
    }
}
function clearFocusTxt(el) {
    var el = document.getElementById(el);
    el.value = "";
    el.focus();
}
function noscript() {
    jQuery(".jshide").css({ visibility: "visible" });

    if (jQuery(".next").length > 1) {
        jQuery(".next").css({ visibility: "visible" });
    }
}
function kriesi_sleekslide() {
    modifyIE = 1;
    if (jQuery.browser.msie && jQuery.browser.version < 7) {
        modifyIE = -1;
    }
    var animation_stopped = true;
    var viewport = (jQuery(window).width() * 2);
    jQuery(".bgImage:not(.bgi1)").each(function(i) {
        jQuery(this).css({ "opacity": "0", "display": "block" });
    });
    jQuery(".bgImage:not(.bgi1)").each(function(i) {
        jQuery(this).css({ "opacity": "0", "display": "block" });
    });
    jQuery(".hhWrapper").each(function(i) {
        jQuery(this).css({ "display": "block" });
    });
    jQuery(".oslideContainer").each(function(i) {
        var currentPos_container = jQuery(this).position();
        var newpos_container = (currentPos_container.left + viewport) * modifyIE;
        jQuery(this).css({ left: newpos_container }).removeClass("notactive");
    });
    jQuery(".tab").each(function(i) {
        jQuery(this).bind("click", function() {
            if ((this.className.indexOf("on")) == -1) {
                if (animation_stopped) {
                    animation_stopped = false;
                    viewport = (jQuery(window).width() * 2);
                    var number = currentTab;
                    var next = i + 1;
                    if (jQuery(".oslideContainer").length < next) {
                        next = 1;
                    }
                    function bgSlide() {
                        jQuery('.bgi' + next).fadeTo(1500, 1);
                        jQuery('.bgi' + number).fadeTo(1500, 0);
                    }
                    var bgSlideIt = setTimeout(bgSlide, 900);

                    jQuery('.oslide' + number).animate({ left: -viewport }, 800, "easeInQuint", function() {
                        var css_set = viewport * modifyIE;
                        jQuery('.oslide' + number).css({ left: css_set });
                    });
                    function slideIn() {
                        var x = $('.oslide' + next);
                        var z = $('.oslide' + next + ' div.hhWrapper');
                        x.animate({ left: 0 }, 800, "easeOutQuint", function() {
                            animation_stopped = true;
                        });
                    }
                    var intId = setTimeout(slideIn, 2500);
                    jQuery('.oslide' + number + ' .slideme').each(function(i) {
                        var speed = 450;
                        var this_css_left = jQuery(this).css("left");
                        var pos_left = parseInt(this_css_left.replace(/px/g, ""));
                        var adjust_left = pos_left + ((i + 1) * 35);
                        jQuery(this).animate({ left: adjust_left }, speed, "linear").animate({ left: pos_left }, 300);
                    });
                    setTab(currentTab, next);
                }
            };
            return false;
        });
    });
}
var currentTab = 1;
var _NUMTABS = 5;
function setTab(curTabIndex, nextTab) {
    if (nextTab > _NUMTABS) {
        nextTab = 1;
    }
    var objCurrentTab = document.getElementById('promo' + curTabIndex);
    objCurrentTab.className = 'off';
    var objNewTab = document.getElementById('promo' + nextTab);
    objNewTab.className = 'on';
    currentTab = nextTab;
}
$(document).ready(function () {
    $(function () {
        var jLoader = $('.jLoader');
        var oSlider = $('.OSlider');
        var x = $('.oslide1');
        function justFade() {
            jLoader.fadeTo(1000, 0, function() {
                x.animate({ left: 0 }, 800, "easeOutQuint");
                jLoader.hide();
            }); ;
        }
        setTimeout(justFade, 3000);
    });
    $("ul.gallery li").hover(function () {
        var thumbOver = $(this).find("img").attr("src");
        $(this).find("a").css({ 'background': 'url(' + thumbOver + ') no-repeat center top' });
        $(this).find("span").stop().fadeTo(700, 0, function () {
            $(this).hide()
        });
    }, function () {
        $(this).find("span").stop().fadeTo(700, 1).show();
    });
    kriesi_sleekslide();
    noscript();
    $('h1 span.likes span.fb_edge_comment_widget')
        .live('mouseover', function () {
            var w = 1024;
            var d = 310;
            var ww = $(window).width();
            var l = (ww < w) ? d : d - ((ww - w) / 2);
            if (l > d) l = d; else if (l < -56) l = -56;
            $('h1 span.likes span.fb_edge_comment_widget').animate({ left: (l * -1) }, 0)
        });
});
