(function($){

jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

	/********************************/
	$.fn.mybox = function(options){
		var overlay, iframe, inner;
		var iFrameWidth = 650, iFrameHeight = 0, iFrameHTML = ''; 
		var elementId = jQuery(this).attr('id');
		var backgroundTrigger = jQuery("<div id='bg-trigger'/>");

		if (options) {
			if (options.width) {
				iFrameWidth = options.width;
			}

			if (options.height) {
				iFrameHeight = options.height;
			}
		}

		if (!$(this).length) {
			return;
		}

		if (jQuery('#overlay.' + elementId + 'Overlay').length) {
			overlay = $('#overlay.' + elementId + 'Overlay');
		}
		else {
			overlay = $('<div id="overlay" class="' + elementId + 'Overlay"></div>').appendTo('body').hide();
		}

		overlay.height($("#main").height() + $("#bottom").height());

		iFrameHTML = "<iframe id='" + elementId + "' scrolling='no' allowTransparency='yes' border='0' frameborder='no' width='" + iFrameWidth + "'";

		if (iFrameHeight>0) {
			iFrameHTML += " height='" + iFrameHeight + "'";
		}

		iFrameHTML += " style='border:0;background:transparent;'/>";

		iframe = $(iFrameHTML);
		inner = $("<div id='inner' width='" + iFrameWidth + "' style='width:" + iFrameWidth + "px' />").addClass('overlayed').appendTo(overlay);
		
		var closeit = function() {
			inner.empty();
			overlay.hide();
			return false;
		};
		
		backgroundTrigger.click(closeit).prependTo(overlay);
		
		$(this).click(function(e) {
			var elementId = jQuery(this).attr('id');
			var overlayElement = jQuery('#overlay.' + elementId + 'Overlay');

			e.stopPropagation();
			var href = $(this).attr("href");
			//overlay.show();
			overlayElement.show();
			inner.append("<h3>"+$(this).attr("title")+"</h3><a href='#close' id='close-trigger'>Close</a>");
			$("#close-trigger").click(closeit);
			iframe.attr("src", href).appendTo(inner);
			iframe.load(function(){
				var innerDoc = (iframe[0].contentDocument) ? iframe[0].contentDocument : iframe[0].contentWindow.document;
			    iframe.height(innerDoc.body.scrollHeight+10);
			});
			$("html, body").animate({scrollTop:0}, 200);
			return false;
		});
		
	};
	
	$(".grayHover").each(function(){
		var img = $(this),
			w = img.css('width'),
			h = img.css('height'),
			src = img.attr("src");
		if(img.attr("src").indexOf("getGreyscaleSprite.aspx?path=") === -1){
			return false;
		}
		img.wrap("<div class='colorimg'><div class='grayimg'></div></div>").hide();
		var gray = img.parent(),
			color = gray.parent();

		color.css({
			background: 'url('+src+') no-repeat left top',
			width: w,
			height: h,
			overflow: 'hidden'
		});
		gray.css({
			background: 'url('+src+') no-repeat left bottom',
			width: w,
			height: h,
			overflow: 'hidden'
		});
		color.parent().hover(function(){
			gray.animate({ opacity:0 }, { queue: false, duration: 500 });
		}, function(){
			gray.animate({ opacity:1 }, { queue: false, duration: 500 });
		});

	});
	
	/********************************/
	$(".slider").each(function(){
		var content = $(".content", this),
			toggle = $(this).hasClass("toggle"),
			arrowed = $(this).hasClass("arrowed"),
			navigation = $("<div class='navigation'/>").appendTo(this),
			allmylinks = '';
			
		if(content.children().length <= 1){
			return false;
		}

		for(var i=1;i<=content.children().length;i++){
			allmylinks += '<a href="#slider-'+i+'" class="sprite btn"><span>'+i+'</span></a>';
		}
		
//		content.children().hide();
		var visibleWidth = content.children(":first").outerWidth(),
			visibleHeight =content.children(":first").height();
		content.children().css({ 'float':'left' });
		content.css({
			width: visibleWidth,
			overflow:'hidden',
			position:'relative'
		}).wrapInner("<div style='padding:0;height:auto;overflow:hidden;position:absolute;left:0;width:999em;'></div>");
		content.height(content.children().height());
		content = content.children(); // because of the inner-wrapped div
		
		if(toggle){
			title = $("<div class='title'>"+$(this).attr("title")+" <span>1</span></div>").appendTo(this);
			var more = $("<a href='#' class='sprite info-dark'><span>More</span></a>").appendTo(this);
			more.click(function(){
				var n = title.find("span").text();
				content.children("div:nth-child("+n+")").toggle();
				return false;
			});
		}
		
		$(allmylinks).appendTo(navigation);
		navigation.find("a:first").addClass("active");
		
		if(!toggle){
			content.children(":first").show();
		}
		
		if(arrowed){
			$('<a href="#slider-prev" class="sprite disabled prev"><span>Previous</span></a>').prependTo(navigation);
			$('<a href="#slider-next" class="sprite next"><span>Next</span></a>').appendTo(navigation);
		}
		
		navigation.find("a").click(function(e){
			var $this = $(this),
				href = $this.attr("href"),
				n = href.substring( href.indexOf("slider-") + 7); 
			if(arrowed){
				if(n == "next" || n == "prev"){
					navigation.find("a.active")[n](":not(.next):not(.prev)").click();
					return false;
				}
				navigation.find(".disabled").removeClass("disabled");
				if($this.next().hasClass("next")){
					$this.next().addClass("disabled");
				}
				if($this.prev().hasClass("prev")){
					$this.prev().addClass("disabled");
				}				
			}
//			content.children().hide();
//			content.children(":nth-child("+n+")").show();
			content.animate({ left: -content.children(":nth-child(" + n + ")").position().left }, { duration:650, queue:false, easing:'easeOutCubic'});
			navigation.find("a").removeClass("active");
			$this.addClass("active");
			
			if(toggle){
				title.find("span").text(n);
			}
			
			return false;
			
		});
		
		if($(this).hasClass("autoslide")){
			var autoslide = setInterval(function(){
				/* if(-(slideshow.position().left-start) < max-1){
					nav.find("a.slide-next").click();
				}else{
					slideshow.animate({ left:start }, { duration:250, queue: true });
				} */
				var last = navigation.find("a:not(.prev):not(.next):last"),
 					active = navigation.find("a.active:not(.prev):not(.next)");
				if(last.is(".active")){
					navigation.find("a:not(.prev):not(.next):first").click();
				}else{
					active.next(":not(.prev):not(.next)").click();
				}
			}, 4000);
			navigation.find("a").click(function(e){
				if(e.hasOwnProperty("originalEvent")){
					clearInterval(autoslide);
				}
			});
			$('.modalOverlay').click(function(event) {
				event.preventDefault();
				clearInterval(autoslide);
			});
		}
		
	});
	
	/********************************/
	function vslider(element_, options_) {
		if (element_) {
			// set last element to show
			var elementsCount = element_.find('.content p').length;
			var lastToShowIndex = elementsCount - options_.itemsShown + 1;
			var containerHeight = element_.height();

			/*if (options_.itemsShown) {
				element_.find('.navigation a:nth-child(' + (elementsCount-options_.itemsShown+1).toString() + ')').addClass('lastToShow');
			}*/
			
			element_.each(function() {
				var content = $(".content", this),
					toggle = $(this).hasClass("toggle"),
					arrowed = $(this).hasClass("arrowed"),
					navigationPrev = $("<div class='navigation vsliderNavigationUp'/>").prependTo(this),
					navigation = $("<div class='navigation'/>").appendTo(this),
					allmylinks = '';
				
				navigationPrev.width(content.width());
				navigation.width(content.width());
				navigationPrev.css('text-align', 'center');
				navigation.css('text-align', 'center');
								
				if (content.children().length <= 1) {
					return false;
				}
				
				for (var i=1, j=content.children().length; i<=j; i++) {
					allmylinks += '<a href="#slider-' + i + '" class="sprite btn';

					if (i==lastToShowIndex) {
						allmylinks += ' lastToShow';
					}

					allmylinks += '" style="display:none;"><span>' + i + '</span></a>';
				}
				
		//		content.children().hide();
				var visibleWidth = content.children(":first").outerWidth(),
					visibleHeight = content.children(":first").height();
				//content.children().css({ 'float':'left' });
				
				content.css({
					width: visibleWidth,
					overflow:'hidden',
					position:'relative'
				}).wrapInner("<div style='padding:0;height:auto;overflow:hidden;position:absolute;left:0; clear:both;'></div>");
				
				//content.height(content.children().height());
				content.height(containerHeight);

				content = content.children(); // because of the inner-wrapped div
				
				if (toggle) {
					title = $("<div class='title'>"+$(this).attr("title")+" <span>1</span></div>").appendTo(this);
					var more = $("<a href='#' class='sprite info-dark'><span>More</span></a>").appendTo(this);

					more.click(function() {
						var n = title.find("span").text();
						content.children("div:nth-child("+n+")").toggle();
						return false;
					});
				}
				
				$(allmylinks).appendTo(navigation);
				navigation.find("a:first").addClass("active");
				
				if (!toggle) {
					content.children(":first").show();
				}
				
				if (arrowed) {
					$('<a href="#slider-prev" class="sprite disabled vPrev"><span>Previous</span></a>').appendTo(navigationPrev);
					$('<a href="#slider-next" class="sprite vNext"><span>Next</span></a>').appendTo(navigation);
				}
				
				navigationPrev.find("a").click(function(e) {
					var $this = $(this),
						href = $this.attr("href"),
						n = href.substring( href.indexOf("slider-") + 7); 
					
					if (arrowed) {
						if (n=="next" || n=="prev") {
							navigation.find("a.active")[n](":not(.next):not(.prev)").click();

							return false;
						}
						
						navigation.find(".disabled").removeClass("disabled");
						
						/*if ($this.next().hasClass("next")) {
							$this.next().addClass("disabled");
						}*/


						if ($this.attr('href')=='#slider-' + (navigation.children().size()-options_.itemsShown)) {
							//$this.next().addClass("disabled");
							//navivation.find('.vNext');
							navigation.find('.vNext');
						}
						
						if ($this.prev().hasClass("prev")) {
							$this.prev().addClass("disabled");
						}				
					}
					
		//			content.children().hide();
		//			content.children(":nth-child("+n+")").show();
					content.animate({ top: -content.children(":nth-child("+n+")").position().top }, { duration:250, queue:false });
					navigation.find("a").removeClass("active");
					$this.addClass("active");
					
					if(toggle) {
						title.find("span").text(n);
					}
					
					return false;
					
				});
				
				navigation.find("a").click(function(e) {
					var $this = $(this),
						href = $this.attr("href"),
						n = href.substring( href.indexOf("slider-") + 7); 
						
					if (!(navigation.find('a.active').hasClass('lastToShow') && n=='next') ) {
						if (arrowed) {
							if (n == "next" || n == "prev") {
								navigation.find("a.active")[n](":not(.next):not(.prev)").click();
								return false;
							}
							
							navigation.find(".disabled").removeClass("disabled");
							
							/*if ($this.next().hasClass("next")) {
								$this.next().addClass("disabled");
							}*/


							if ($this.attr('href')=='#slider-' + (navigation.children().size()-options_.itemsShown)) {
								//$this.next().addClass("disabled");
								//navivation.find('.vNext');
								navigation.find('.vNext').addClass("disabled");
							}
							
							if ($this.prev().hasClass("prev")) {
								$this.prev().addClass("disabled");
							}				
						}
						
			//			content.children().hide();
			//			content.children(":nth-child("+n+")").show();
						content.animate({ top: -content.children(":nth-child("+n+")").position().top }, { duration:250, queue:false });
						navigation.find("a").removeClass("active");
						$this.addClass("active");
						
						if (toggle) {
							title.find("span").text(n);
						}
					
					}

					return false;
					
				});
				
				if ($(this).hasClass("autoslide")) {
					var autoslide = setInterval(function() {
						/* if(-(slideshow.position().left-start) < max-1){
							nav.find("a.slide-next").click();
						}else{
							slideshow.animate({ left:start }, { duration:250, queue: true });
						} */
						var last = navigation.find("a:not(.prev):not(.next):last"),
							active = navigation.find("a.active:not(.prev):not(.next)");
						if (last.is(".active")) {
							navigation.find("a:not(.prev):not(.next):first").click();
						}
						else {
							active.next(":not(.prev):not(.next)").click();
						}
					}, 4000);
					
					navigation.find("a").click(function(e) {
						if(e.hasOwnProperty("originalEvent")) {
							clearInterval(autoslide);
						}
					});
				}
				
			});
		}
	} // vslider
	
	vslider($(".vslider"), {itemsShown:5});
	
	$(".goto-top").hover(function(){
		$(this).find("a.reveal-me").show();
	}, function(){
		$(this).find("a.reveal-me").hide();
	});
	
	$(".slidedown").each(function(){
		var $this = $(this),
			area = $this.find(".slide-hidden").css("clear", "both").hide(),
			areaShadowBottom = $this.find('.shadow-bottom'),
			trigger = $("<a href='#' class='cta slide-cta'><span>+ See</span> " + area.attr("title") + "</a>").appendTo(this);

		if (area.attr("title") != "") {
			area.wrapInner("<div class='content'/>");
			$("<div class='title'>"+area.attr("title")+"</div>").prependTo(area);
		}

		area.attr("title", "");

		trigger.click(function() {
			var pre = $(this).find("span");

			if(pre.text() == "+ See"){
				pre.text("Close");
			}
			else{
				pre.text("+ See");
			}

			if (areaShadowBottom.length>0) {
				areaShadowBottom.toggle();
			}

			area.slideToggle(200);

			return false;
		});
	});
	
	/**
	 * questionaire-nav 
	 */
	$(".questionaire").each(function(){
		var items = $(this).children(), 
			nav = $("<div class='questionaire-nav'/>");
			
		/*items.each(function(i){
			var separator = (i+1 == items.length)?"":" &nbsp; | &nbsp; ";
			//nav.append("<a href='#question-"+(i+1)+"'>Question "+(i+1)+"</a>"+separator);
			nav.append("<a href=\"video-sample.aspx\" rel=\"fancybox\">Question "+(i+1)+"</a>"+separator);
		});*/
        
		items.hide();
        
		nav.find("a").click(function() {
			nav.find(".current").removeClass("current");
			
			var href = $(this).addClass("current").attr("href"),
				n = parseInt(href.substring(href.indexOf("question-") + 9));
				
				alert('d');

			items.hide().filter(":nth-child(" + n + ")").show();
		});
		
		items.filter(":first").show();
		nav.find("a:first").addClass("current");
		$(this).after(nav);
		
	});
	
/*	$(".slideshow").each(function(){
		var items = $(this).children();
		if(items.length > 1){
			var slideshow = $(this).css("left", "10px"),
				nav = $("<div class='slide-nav'/>").appendTo(this.parentNode),
				howmuch = items.filter(":first").outerWidth(true),
				start = slideshow.position().left,
				max = (items.length-1)*howmuch;
			$("<a href='#previous' class='slide-prev sprite'>&larr;</a><a href='#next' class='slide-next sprite'>&rarr;</a>").appendTo(nav);
			nav.find("a").click(function(e){
				if(!slideshow.is(":animated")){
					var direction = ($(this).attr("href").indexOf("#next") >= 0)?"-":"+",
						nextPos = -(slideshow.position().left-start);
					if( (nextPos < max-1 && direction == "-") || (nextPos > 0 && direction == "+") ){ // the -1 is a error margin prevent
						slideshow.animate({ left: direction+"="+howmuch+"px" }, { duration:250, queue: true });
					}
				}
				return false;
			});
			
		}
	}); */

	// add soft navigation to local hrefs having softScroll class
	if (jQuery.scrollTo) {
		jQuery('.softScroll').bind('click', function() {
			var thisElement = jQuery(this);

			if (thisElement.attr('href')) {
				jQuery.scrollTo(thisElement.attr('href'), 'slow');

				return false;
			}

		});
	}
	
	// add navigation events
	jQuery('.newsNavigation .prev').bind('click', function(event) {
		event.preventDefault();

		// find previous news page
		var currentPage = parseInt(jQuery('.newsNavigation .current').html());
		var totalPages = parseInt(jQuery('.newsNavigation .total').html());

		if (currentPage>1) {
			// add code here to fetch new data with ajax and replace current news

			if ((currentPage-1)==1) {
				jQuery('.newsNavigation .prev').addClass('disabled').attr('disabled', true);
			}

			if (currentPage==totalPages) {
				jQuery('.newsNavigation .next').removeClass('disabled').attr('disabled', false);
			}

			jQuery('.newsNavigation .current').html((currentPage - 1).toString());
		}
	});

	jQuery('.newsNavigation .next').bind('click', function(event) {
		event.preventDefault();

		// find next news page
		var currentPage = parseInt(jQuery('.newsNavigation .current').html());
		var totalPages = parseInt(jQuery('.newsNavigation .total').html());

		if (currentPage<totalPages) {
			// add code here to fetch new data with ajax and replace current news

			if ((currentPage+1)==totalPages) {
				jQuery('.newsNavigation .next').addClass('disabled').attr('disabled', true);
			}

			if (currentPage==1) {
				jQuery('.newsNavigation .prev').removeClass('disabled').attr('disabled', false);
			}

			jQuery('.newsNavigation .current').html((currentPage + 1).toString());
		}
	});


})(jQuery);

var VCU = {};

VCU.selectTopMenu = function (text_) {
	if (text_==='') {
		jQuery('#top').find('nav a').removeClass('selected');
	}
	else {
		jQuery('#top').find('nav a:contains("' + text_ + '")').addClass('selected');
	}
}

function getQuerystring(key, default_) {
    if (default_==null) default_="";
    
    key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
    var qs = regex.exec(window.location.href);
    
    if(qs == null)
        return default_;
    else
        return qs[1];
        
}

