// @author Yonas Hassen

$j(document).ready(function() {
    // Home page controls
    $j(".rkLiveButton").click(function() {
        $j(".rkLive").slideToggle("slow");
        $j(".rkLiveOuter").slideToggle("slow");
        if ($j(".tab").attr("src") == "/Images/buttons/RKLive_off.png") {
            $j(".tab").attr("src", "/Images/buttons/RKLive_on1.png");
        } else if ($j(".tab").attr("src") == "/Images/buttons/RKLive_on1.png") {
            $j(".tab").attr("src", "/Images/buttons/RKLive_off.png");
        } else if ($j(".tab").attr("src") == "Linked/Images/buttons/RKLive_off.png") {
            $j(".tab").attr("src", "Linked/Images/buttons/RKLive_on1.png");
        } else if ($j(".tab").attr("src") == "Linked/Images/buttons/RKLive_on1.png") {
            $j(".tab").attr("src", "Linked/Images/buttons/RKLive_off.png");
        } else if ($j(".tab").attr("src") == "/Linked/Images/buttons/RKLive_off.png") {
            $j(".tab").attr("src", "/Linked/Images/buttons/RKLive_on1.png");
        } else if ($j(".tab").attr("src") == "/Linked/Images/buttons/RKLive_on1.png") {
            $j(".tab").attr("src", "/Linked/Images/buttons/RKLive_off.png");
        } else if ($j(".tab").attr("src") == "../Linked/Images/buttons/RKLive_off.png") {
            $j(".tab").attr("src", "../Linked/Images/buttons/RKLive_on1.png");
        } else if ($j(".tab").attr("src") == "../Linked/Images/buttons/RKLive_on1.png") {
            $j(".tab").attr("src", "../Linked/Images/buttons/RKLive_off.png");
        } else if ($j(".tab").attr("src") == "../../Linked/Images/buttons/RKLive_off.png") {
            $j(".tab").attr("src", "../../Linked/Images/buttons/RKLive_on1.png");
        } else if ($j(".tab").attr("src") == "../../Linked/Images/buttons/RKLive_on1.png") {
            $j(".tab").attr("src", "../../Linked/Images/buttons/RKLive_off.png");
        }
    });
    var isCareers = false;
    if (document.URL.toLowerCase().match(/careers./)) isCareers = true;
    if (!isCareers) {
        $j("#myController").jFlow({
            slides: "#slides",
            controller: ".jFlowControl", // must be class, use . sign
            slideWrapper: "#jFlowSlide", // must be id, use # sign
            selectedWrapper: "jFlowSelected",  // just pure text, no sign
            auto: true, 	//auto change slide, default true
            width: "660px",
            height: "296px",
            duration: 400,
            prev: ".jFlowPrev", // must be class, use . sign
            next: ".jFlowNext" // must be class, use . sign
        });
    }
    else if (isCareers) {
        $j("#careerSlides").css("display", "block");
        // Careers page controls
        $j("#careersController").jFlow({
            slides: "#careerSlides",
            controller: ".jFlowControl", // must be class, use . sign
            slideWrapper: "#jFlowSlide", // must be id, use # sign
            selectedWrapper: "jFlowSelected",  // just pure text, no sign
            auto: false, 	//auto change slide, default true
            width: "99%",
            height: "200px",
            duration: 400,
            prev: ".jFlowPrev", // must be class, use . sign
            next: ".jFlowNext" // must be class, use . sign
        });
    }

    $j(".newsletterEmail").click(function() {
        var inputValue = $j(".newsletterEmail").val();
        if (inputValue == "enter email here") $j(this).attr({ value: '' });
    });

    $j(".featured .featuredImg").hover(function() {
        $j(this).fadeTo(100, 0.33);
        $j(this).fadeTo(500, 1);
    });

    // The Work page controls
    $j(".clientList a").click(function() {
        $j(".clientList li").removeClass("clientListActive");
        $j(this).parent().addClass("clientListActive");
        $j(".theWorkRight h3").html($j(this).html() + ":");
        $j(".theWorkRight .theWorkGrid div").hide("slow");
    });

    $j(".slideControls .slidePrev").hover(function() {
        $j(this).attr({ src: 'http://www.rkconnect.com/Linked/Images/buttons/slidePrevHover.gif' });
    }, function() {
        $j(this).attr({ src: 'http://www.rkconnect.com/Linked/Images/buttons/slidePrev.gif' });
    });
    $j(".slideControls .slideNext").hover(function() {
        $j(this).attr({ src: 'http://www.rkconnect.com/Linked/Images/buttons/slideNextHover.gif' });
    }, function() {
        $j(this).attr({ src: 'http://www.rkconnect.com/Linked/Images/buttons/slideNext.gif' });
    });
    $j(".thumbAnimate").hover(function() {
        $j(this).css({ 'border': '2px solid rgb(81,79,38)' });
    }, function() {
        $j(this).css({ 'border': 'none' });
    });

    // Clients page controls
    $j(".clientsDiv .clientLogos .logoRow .logo img").hover(function() {
        thisSrc = $j(this).attr("src");
        $j(this).attr({ src: thisSrc.replace(/_bw.png/gi, '.png').replace(/_bw.gif/gi, '.gif').replace(/_bw.jpg/gi, '.jpg') });
    }, function() {
        $j(this).attr({ src: thisSrc });
    });

    // Insights page controls
    $j(".insightsLeft .archiveList li a").click(function() {
        if ($j(this).hasClass("openItem")) {
            $j(this).removeClass("openItem");
            $j(this).addClass("closedItem");
            $j(this).parent().children(".innerUL").hide("slow");
        } else {
            $j(this).removeClass("closedItem");
            $j(this).addClass("openItem");
            $j(this).parent().children(".innerUL").show("slow");
        }
        return false;
    });
});
