﻿/* Preloading images */
(function($) {
	var cache = [];
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)


	
/*********************
	     RCMs
**********************/
$(function(){ 
	
	$('.modules-nav-prev').hide();
	
	var offset = $('.modules-nav a.next').attr('id').replace('next-', '');
    var limit = parseInt(offset, 10) + 4;
	$.getJSON('', function(data) {
        $.each(data.modules, function (i, item) {
            if(offset >= i && i <= limit) { return true; }
			var footerText = "";
			var playVideo = "";
			switch (this.category) {
				case "news":
					footerText = "Read the full story at <strong>News Center</strong>";
					break;
				case "website":
					footerText = "Visit this <strong> Website</strong>";
					break;
				case "person":
					footerText = "Read more about this <strong>person</strong>";
					break;
				case "video":
					footerText = "View this <strong>video</strong>";
					playVideo = '<a href="'+this.link+'" class="play"></a>';
					break;
				case "event":
					footerText = "Read more about this <strong>event</strong>";
					break;
				case "survey":
					footerText = "Take the <strong>survey</strong>";
					break;
				case "alert":
					footerText = "Read more about this <strong>alert</strong>";
					break;
				case "other":
					footerText = "Learn more";
					break;
				default:	
			} // switch
			if(footerText!="") {
				$('#modules').append('<div class="module '+this.category+'">'+playVideo+'<a href="'+this.link+'"><img src="'+this.image+'"></a> <h2><a href="'+this.link+'">'+this.title+'</a></h2> <p>'+this.copy+'</p><div class="read"><a href="'+this.link+'">'+footerText+'</a></div></div>');
			}
        }); // each
	}); //getJSON
	
	$('.modules-nav a.next').live('click',function(){
		var offset = $('.modules-nav a.next').attr('id').replace('next-', '');
	    var limit = parseInt(offset, 10) + 4;
        $(this).attr('id', 'next-'+limit);
		
		$('.modules-nav-prev').fadeIn();
		
		if(offset === '3'){
			if ($.browser.msie && $.browser.version.substr(0,1)<8) { 
				$('.module').fadeOut('slow');
				for (i=4;i<=7;i++) {
					$('.module').eq(i).fadeIn('slow');
				}
				$('#modules').css({'height':'385px','overflow':'hidden'});
				$('.modules-nav-prev a').hide().fadeIn(800);
			} else {
				$('#modules').animate({'opacity':'.3'},250).animate({'left':'-1100px'},800).animate({'opacity':'1'},250);
				$('p.modules-nav-prev a').hide().fadeIn(800);
			}
		} else if(offset === '7') {
			if ($.browser.msie && $.browser.version.substr(0,1)<8) { 
				$('.module').fadeOut('slow');
				for (i=8;i<=11;i++) {
					$('.module').eq(i).fadeIn('slow');
				}
			} else {
				$('#modules').animate({'opacity':'.3'},250).animate({'left':'-2200px'},800).animate({'opacity':'1'},250);
				
			}
			$(this).fadeOut(800);
		}
		
		return false;
	});
	
	$('p.modules-nav-prev a').live('click', function(){
		if ($.browser.msie && $.browser.version.substr(0,1)<8) {
			$('.module').fadeOut('slow');
			for (i=0;i<=3;i++) {
				$('.module').eq(i).fadeIn('slow');
			}
		} else {
			$('#modules').animate({'opacity':'.3'},250).animate({'left':'0'},800).animate({'opacity':'1'},250);
		}
		$(this).fadeOut(800);
		$('p.modules-nav a.next').attr('id','next-3').fadeIn(800);
		return false;
	});
}); //End loaded jQuery */

