
// jQuery ready function
jQuery(function($) {
    var $carousel = $(".carousel-main"),
         $currentOpps = $("div.current-opps"),
         $videoPlay = $(".video-play");
    
    function runContentScripts(){
        $carousel.children(".carousel").jCarouselLite({
            btnNext: ".next",
            btnPrev: ".previous",
            visible: 5.06,
            start: 1
        });

        // binding a click to the div
        $currentOpps.bind("click", function(event) {
            // caching the div
            var $this = $(this);
            // show paragraphs
            $this.find(".opportunity").show();
            // find the expand links under the div, remove .expand, add .expand-active, bind one event
            $this.find("h2 a").removeClass("expand").addClass("expand-active").one("click", function(event) {
                event.preventDefault();
                // expanded link
                var $this = $(this);
                // fixing classes
                $this.removeClass("expand-active").addClass("expand");
                // hiding paragraph tags
                $this.parents("div.current-opps").find(".opportunity").hide();
                // don't rerun function
                event.stopPropagation();
            });
            // returns false for main title link only
            var $target = $(event.target);
            if($target.is("h2 a"))event.preventDefault();
        });

        $videoPlay.fancybox({
            'type'   :   'iframe',
            'height' :   496,
            'width'  :   630,
            'titlePosition'   :   'inside'
        });
    }
    
    function reveal(element){
        element.css("visibility", "visible");
    }
    
    if($("div.landingVideoWrapper").length == 1){
        var landingVideo = $("div.landingVideoWrapper");
        $(".escape").delay(1200).fadeIn();
        landingVideo.clear(".escape", "div.landingVideo", "mousedown", function() {
            reveal($carousel);
            reveal($currentOpps);
            reveal($videoPlay);
            this.remove();
            $("form > shape").remove();//compensates for png fix
            runContentScripts();
        });
    }
    else{
        reveal($carousel);
        reveal($currentOpps);
        reveal($videoPlay);
        runContentScripts();
    }
});
