var isIE6=false;


$j(function () {

    $j("#silver-nav").click(function () {
        $j(".plan-details").hide();
        $j("#bronze").show();
        $j(".plan-nav").addClass("inactive");
        $j(".plan-nav").removeClass("active");
        $j(this).removeClass("inactive");
        $j(this).addClass("active");
    });
    $j("#gold-nav").click(function () {
        $j(".plan-details").hide();
        $j("#silver").show();
        $j(".plan-nav").addClass("inactive");
        $j(".plan-nav").removeClass("active");
        $j(this).removeClass("inactive");
        $j(this).addClass("active");
    });
    $j("#platinum-nav").click(function () {
        $j(".plan-details").hide();
        $j("#gold").show();
        $j(".plan-nav").addClass("inactive");
        $j(".plan-nav").removeClass("active");
        $j(this).removeClass("inactive");
        $j(this).addClass("active");
    });
    $j("#diamond-nav").click(function () {
        $j(".plan-details").hide();
        $j("#diamond").show();
        $j(".plan-nav").addClass("inactive");
        $j(".plan-nav").removeClass("active");
        $j(this).removeClass("inactive");
        $j(this).addClass("active");
    });


    $j(".featured-works .feature .feature-image").hover(
        function () {
            $j(".learn-more", this).fadeIn('fast');
        },
        function () {
            $j(".learn-more", this).hide();
        }
    );

    $j("#footer .image-block").hover(
        function () {
            $j(".learn-more", this).fadeIn('fast');
        },
        function () {
            $j(".learn-more", this).hide();
        }
    );

    $j("#project-detail .screenshot").css('overflow', 'hidden').height($j("#project-detail .screenshot img").height());
    $j("#project-detail .screenshot img").fadeIn("slow");
    $j("#project-detail .screenshot-thumbs img:first").addClass("active");
    $j("#project-detail .screenshot-thumbs img").click(function () {
        var imgSrc = $j(this).attr("rel");
        $j("#project-detail .screenshot-thumbs img").removeClass("active");
        $j(this).addClass('active');

        $j("#project-detail .screenshot .ajax-overlay").fadeTo(100, 0.75, function () {
            var projectScreenshot = new Image();
            var currentImage = $j("#project-detail .screenshot img");
            currentImage.css("z-index", 2);
            $j("#project-detail .screenshot").css('overflow', 'hidden').height(currentImage.height());

            $j(projectScreenshot).load(function () {
                $j("#project-detail .screenshot").animate({ height: projectScreenshot.height }, 500, function () {
                    $j(projectScreenshot).css("z-index", 3);
                    $j("#project-detail .screenshot").append(projectScreenshot);
                    $j(projectScreenshot).fadeIn(250, function () {
                        $j("#project-detail .screenshot .ajax-overlay").fadeTo(250, 0, function () {
                            $j("#project-detail .screenshot img:first").remove();
                        });
                    });
                });
            });
            projectScreenshot.src = imgSrc;
        });
    });

    $j("#partners .section:last").addClass("last");
    $j("#career .section:last").addClass("last");
    $j("#news-container .section:last").addClass("last");

    $j("#show-first-set").click(function () {
        $j(".feature-actions .toggle").removeClass("active");
        $j(this).addClass("active");
        $j(".featured-works .second-set").fadeOut('slow', function () {
            $j(".featured-works .first-set").fadeIn('slow');
            window.location.hash = "p1";
        });
        return false;
    });
    $j("#show-second-set").click(function () {
        $j(".feature-actions .toggle").removeClass("active");
        $j(this).addClass("active");
        $j(".featured-works .first-set").fadeOut('slow', function () {
            $j(".featured-works .second-set").fadeIn('slow');
            window.location.hash = "p2";
        });
        return false;
    });

    if (window.location.hash == "#p2") {
        $j(".feature-actions .toggle").removeClass("active");
        $j("#show-second-set").addClass("active");
        $j(".featured-works .first-set").hide();
        $j(".featured-works .second-set").show();
    }


    var imageBanner = $j("#banner-image");
    if (imageBanner.length > 0) {
        bannerHeaderResize();
        $j(window).bind("resize", bannerHeaderResize);
    }

    function bannerHeaderResize() {
        var leftPush = 2;
        if ($j(".Who-we-are").length > 0) leftPush = 12;
        $j(".header", imageBanner).width($j(".content:first").offset().left + $j("h1", imageBanner).width() + leftPush);
    }

    var slider = $j(".Our-space #image-slider .scrollable");
    if (slider.length > 0) {
        slider.scrollable({ speed: 500 }).navigator();
    }

    $j('div.magento-partner').find('a.featured-link').click(function () {
        if (!$j(this).hasClass('featured-link-active')) {
            $j(this).addClass('featured-link-active');
            $j('a.cs-link').removeClass('cs-link-active');
            $j('div.feature').show();
        }
    });

    $j('div.magento-partner').find('a.cs-link').click(function () {
        if (!$j(this).hasClass('cs-link-active')) {
            $j(this).addClass('cs-link-active');
            $j('a.featured-link').removeClass('featured-link-active');
            $j('div.feature').not('div.case-study').hide();
        }
    });


    /* MOBILE/IPAD TWEAKS */
    $j(document).ready(function () {
        if ($j.browser.mobile) {
            $j("h1, h2, .sifr").css("visibility", "visible");
            $j("#banner-image h1").css("margin-top", "5px");
            $j(".magento-partner .titleanddesc h1").css("margin-bottom", "40px");
        }
        //Show non-SIFRed headers if no flash and desktop browser.
        if (!$j.browser.mobile && (!navigator.mimeTypes || typeof navigator.mimeTypes["application/x-shockwave-flash"] == 'undefined')) {
            $j("h1, h2, .sifr").css("visibility", "visible");
            $j("#banner-image h1").css("margin-top", "5px");
            $j(".magento-partner .titleanddesc h1").css("font-size", "28px");
        }
    });
});

