﻿jQuery(function($) {
    $("#site-primary-menu > li:has(ul):not(.default)").addClass("extended").addClass(function(index) {
		if($(this).nextAll().length < 2) return "right";
	}).live("mouseenter", function(e) {
		$(this).addClass("active");
	}).live("mouseleave", function(e) {
		$(this).removeClass("active");
	}); 
	
	$("#headerMore").wrap("<div></div>").hide();
    $("#site-more-info").show();

    $('<button type="button">Can\'t Find it?</button').click(function() {
        $(this).blur();
	$("#site-search").hide();
        $("#headerMore").toggleClass("active").slideToggle(function() {
		if($("#headerMore").is(":visible")) {
          	$("#site-search").show();
		}
        });
    }).appendTo($('<p></p>').appendTo("#site-more-info"));


    $("fieldset.serv-opp-signup").hide().after(function() {
        var form = this;
        return $('<a class="signup-show" href="#">Want more information?</a>').click(function(e) {
            e.preventDefault();
            $(this).hide();
            $(form).show();
        });
    });

    $("#page-content ul.serv-opp-list").addClass("min").before(function() {
        var list = this;
        return $('<p style="margin-bottom:1em;" />').append($('<a class="serv-opp-list-expand" href="#">See all details...</a>').click(function(e) {
            e.preventDefault();
            $(list).toggleClass("min");
            if ($(list).hasClass("min")) {
                $(this).text("See all details...");
                $(list).find("li").addClass("min");
            } else {
                $(this).text("Hide all details...");
                $(list).find("li").removeClass("min");
            }

        }));
    });
    $("#page-content ul.serv-opp-list li").addClass("min").append(function() {
        var item = this;
        return $('<a class="serv-opp-expand" href="#">See details...</a>').click(function(e) {
            e.preventDefault();
            $(item).removeClass("min");
        });
    });
    $("div.popup").each(function() {
        var delay = parseInt($(this).attr("data-delay-ms"));
        var href = "#" + $(this).children("[id]").attr("id");
        window.setTimeout(function() {
            $.fancybox({
                href: href
            });
        }, delay);
    });
    $("#highlights .highlights a").append("<span></span>").click(function(e) {
    	e.preventDefault();
    	var link = this;
    	$.fancybox($("<div />").append($(this).clone()).html(), {
			
			overlayColor:"000000",
			overlayOpacity:0.75,
			titlePosition:"inside",
			titleFormat:function formatTitle(title, currentArray, currentIndex, currentOpts) {
			  return $("<div />").append($("<a>Click here for additional information</a>").attr("href", link.href)).html();
			}
		}
	);
    });
});
