// JavaScript Document

$(document).ready(function() {
    $('body').addClass('hasJS');

    // Accordion Panel	
    $("div.more").each(function() {
        $(this).css("height", $(this).height() + "px");
        $(this).hide();
    });

    $("a.fancyboxPhoto").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true
    });

    $("a.mapModal").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'width': 625,
        'height': 525,
        'type': 'iframe',
        'autoScale': false,
        'autoDimensions': false,
        'scrolling': 'no',
        'centerOnScroll': true
    });

    $(".featuredVideos li").each(function(i, val) {
        $(this).hover(function() {
            $("div", this).hide();
            $(this).stop(false, true).animate({ height: "150px" }, 1000);
        }, function() {
            $("div", this).show();
            $(this).stop(false, true).animate({ height: "40px" }, 1000);
        });
    });

    $("a.fancyboxVideo").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'width': 500,
        'height': 435,
        'type': 'iframe',
        'autoScale': false,
        'autoDimensions': false,
        'scrolling' : 'no',
        'centerOnScroll': true
    });

    $('.rotateContent script').remove();
    $('.rotateContent ul').remove();
    $('.rotateContent').children('a').remove();
    $('.rotateContent input').remove();

    $(".rotateContent").cycle({      
        fx: 'fade',
        sync: 0,
        delay: -1000,
        pager: '#RotatorPager',
        slideExpr: '.bannerRotateImage',
        speed: 2500,
        timeout: 7500,
        cleartype: 1,
        cleartypeNoBg: true,        
        pagerAnchorBuilder: function(idx, slide) { return '<a href="#">' + (idx + 1) + '</a>'; }
    });
    
    $(".facebookFeed").cycle({
        fx: 'fade',
        sync: 0,
        delay: -1000,
        speed: 1500,
        timeout: 0,
        cleartype: 1,
        cleartypeNoBg: true,        
        next: "#facebookNext",
        prev: "#facebookPrev"
    });

    $(".twitterFeed").cycle({
        fx: 'fade',
        sync: 0,
        delay: -1000,
        speed: 1500,
        timeout: 0,
        cleartype: 1,
        cleartypeNoBg: true,        
        next: "#twitterNext",
        prev: "#twitterPrev"
    });
           
    $("#toggleFacebook").click(function(e) {
        e.preventDefault();

        $("#toggleFacebook").parent().addClass("selected");
        $("#toggleTwitter").parent().removeClass("selected");

        $(".facebookWrapper").show();
        $(".twitterWrapper").hide();
        //$(".YouTubeWrapper").hide();
    });

    $("#toggleTwitter").click(function(e) {
        e.preventDefault();
        
        $("#toggleFacebook").parent().removeClass("selected");
        $("#toggleTwitter").parent().addClass("selected");

        $(".facebookWrapper").hide();
        $(".twitterWrapper").show();
    });
    
    $(".twitterWrapper").hide();

    $(".accordion h4").css("cursor", "pointer");
    $('<div class="toggleSprite">+/-</div>').appendTo('.accordion h4');
    $(".accordion h4").hover(
		function() {
		    $(this).css({ color: "#00589a" }); //mouseover
		},
		function() {
		    $(this).css({ color: "#5c5c5c" }); // mouseout
		}
	);

	$('.megaMenu li').hover(function() {
	        $('div.sub', this).stop(false, true).slideDown('slow');
		},
		function() {
		    $('div.sub', this).stop(false,true).slideUp('fast');
		}
	);

    $("#mainContent .accordion h4").click(function() {
        $(this).siblings("div.more").slideToggle(700);
        $(this).parent().toggleClass("close");
    });

    $("#sideContent2 .accordion h3").click(function() {
        $(this).siblings("div.more").slideToggle(500);
        $(this).siblings("p.readMore").children("div.toggleSprite").toggleClass("close");
    });

    $(".readMore").click(function() {
        $(this).siblings("div.more").slideToggle(1000);
        $(this).children("div.toggleSprite").toggleClass("close");
    });

    // Tab Switchers
    $(function() {
        var tabContainers = $('div.tabContainer > div');

        $('div.tabs ul.tabNavigation a').click(function() {
            tabContainers.hide().filter(this.hash).show();

            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');

            return false;
        }).filter(':first').click();
    });
});

