
// This targets the div with the id #ctl00_cphMain_ucMod833_apg and then looks for the next div in the code which is the messsage then uses slideToggle() to hide it.
$(document).ready(function() {
	//You may need to duplucate this one line of code with the ID's of each gallery.
    $("#ctl00_cphMain_ucMod833_apg").next("div").slideToggle();
	$("#ctl00_cphMain_ucMod836_apg").next("div").slideToggle();
	$("#ctl00_cphMain_ucMod838_apg").next("div").slideToggle();
	$("#ctl00_cphMain_ucMod863_apg").next("div").slideToggle();
});

// For Blog Pagination
$(document).ready(function() {
	var number = $("#ctl00_cphMain_ctl00_lbNumberOfPages").text();
    var nav = window.location.search;
	
	// Check to see if the query string contains a page number
	if (nav.indexOf('?page') != -1)
	{
		var pageNumber = nav.substring(nav.length - 1, nav.length);
		
		for(var x = 1; x < number + 1; x++)
		{
			if( x != pageNumber)
			{
				var listID = "#blogList" + x;
				$(listID).toggle(); // Hide all other pages
			}		
		}	
		
		// Next and Previous Button images if ?page = something exists
		if(pageNumber == number)
		{
				// If you're on the last page
				var previous = "/blog.aspx?page=" + (number - 1);
				var next = "/blog.aspx?page=" + number;
				$("#pagePrev").attr("href", previous);
				$("#pageNext").attr("href", next);
		}
		else if( pageNumber == 1)
		{
			// If you're on the first page
			$("#pagePrev").attr("href", "/blog.aspx?page=1");
			$("#pageNext").attr("href", "/blog.aspx?page=2");		
		}
		else{
				var previous = "/blog.aspx?page=" + ( parseInt(pageNumber) - 1);
				var next = "/blog.aspx?page=" + ( parseInt(pageNumber) + 1);
				$("#pagePrev").attr("href", previous);
				$("#pageNext").attr("href", next);		
		}
	}
	
	else{
		for( var x = 2; x < number + 1; x++)
		{
			var listID = "#blogList" + x;
			$(listID).toggle();
		}	
		
		$("#pagePrev").attr("href", "/blog.aspx?page=1");
		$("#pageNext").attr("href", "/blog.aspx?page=2");
	}	
});


function ResizeContainer()
{  
    var difference = 0;
    
    $('div[id^="mod"]').each(function()
    {
        var currentDifference = parseInt($(this).height() - $(this).css('min-height').replace('px', ''));
        
        if(currentDifference > difference)
        {
            difference = currentDifference;
        }
    });
    
    $('#container').height($('#container').height() + difference);
}

function ResizeForm(formID, numberOfValidators)
{
    if($('.form' + formID + ' .formValidator').css('display') == 'none') //only run once
    {
        var offset = 15; 
    
        $('#container').height($('#container').height() + (offset * numberOfValidators));
    }
}

function ResizeModule(name)
{
    if (typeof(Page_Validators) != 'undefined') 
    {
        if(!Page_IsValid)
        {
            if(!$('.' + name).parent().attr('style'))
            {
                var offset = 10; 
                var numberOfValidators = $('span[id*="RequiredFieldValidator"]').length;
            
                $('.' + name).parent().height($('.' + name).parent().height() + (offset * numberOfValidators));
                ResizeContainer();
            }
        }
    }
}

$(window).load(function() {
    ResizeContainer();
});
$(document).ready(function() {
    var nav = window.location.pathname;
    $('ul[id^="ni"] li[^="link"] a[href$="' + nav + '"] ').addClass('activeLink');
});

$(document).ready(function() {
	//Code goes here
	
	$(".paging").show();
	$(".paging a:first").addClass("active");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;

	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 500 );

}; 

	//Rotation  and Timing Event
	var play = 's'; 
	rotateSwitch = function(){
	  
		clearInterval(play); //make sure this is cleared or it will start spawning
		play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			$active = $('.paging a.active').next(); //Move to the next paging
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (7 seconds)
	};

	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
	clearInterval(play); //Stop the rotation
	}, function() {
	rotateSwitch(); //Resume rotation timer
	});	

	//On Click
	$(".paging a").click(function() {
	$active = $(this); //Activate the clicked paging
	//Reset Timer
	clearInterval(play); //Stop the rotation
	rotate(); //Trigger rotation immediately
	rotateSwitch(); // Resume rotation timer
	return false; //Prevent browser jump to link anchor
	});	
	
});



// Pre select contact dropdown for Calton Institute
if( location.search.indexOf("?") != -1)
{
	$("#ctl00_cphMain_ddlForm233QuestionReferring").children().eq(5).attr("selected", true);
}

// Moves star on Micro Quiz Results
$(document).ready(function() {
	var score = parseInt($("#ctl00_cphMain_ucMod859_lbStarLeft").text());
	$("#starScore").css("left", score);
	$("#starScore").css("display", "block");
});

// Moves star on Stack Up Results
$(document).ready(function() {
	var score = parseInt($("#ctl00_cphMain_ucMod873_lbleft").text());
	$("#theStar").css("left", score);
	//$("#theStar").css("display", "block");
});


$(document).ready(function() {

    var testimonicals = $('#tb1226').children('img'), startingY = 0, bottomMargin = 2, i;
	testimonicals.sort(function(a, b) { 
		return parseInt($(a).css('top')) - parseInt($(b).css('top'));
	});
    for(i = 0; i < testimonicals.length; i++){
		$(testimonicals[i]).css({left: '0px', top: startingY + 'px', width: '300px'});
		startingY += parseInt($(testimonicals[i]).height()) + bottomMargin;
    }

	
	/*
		var css = {"left" : "0px", "width" : "300px", "position" : "relative", "top" : "0px"}
	
		$("#tb1226 img").each(function () {	
			$(this).css(css);
		});
		
	*/
	


});

$(document).ready(function () {
	$(".moduleNewsletterSignup").parent().css("background", "url('/images/newsletter.jpg') no-repeat scroll 0 0 transparent");
	$(".testimonials").prev().css("padding-right", "10px");
});


function CheckBoxRequired_ClientValidate(sender, e)
{
    e.IsValid = jQuery(".AcceptedAgreement input:checkbox").is(':checked');
}

$(document).ready(function() {
	
	$("#moduleDidYouKnow").click(function() {
		window.location = "/blog.aspx";
	});

});




