// REMAP jQUERY TO $
(function($){

$(document).ready(function (){


/* SMOOTH SCROLLING FUNCTION
------------------------------------------------------------ */
	$(function() {
		$('a[href*=#top], a[href*=#about], a[href*=#competition], a[href*=#complaunch], a[href*=#keymessages], a[href*=#resources], a[href*=#broughtby], a[href*=#getintouch], a[href*=#top]').click(function(noscroll) {
			noscroll.preventDefault();
			if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') && location.hostname === this.hostname) {
				var $target = $(this.hash);
				$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
				if ($target.length) {
					var targetOffset = $target.offset().top;
					$('html,body').stop(true, true).animate({
						scrollTop: targetOffset
					}, 1000);
					return false;
				}
			}
		});
	});

/* HIDDEN CONTENT SLIDING FUNCTION
------------------------------------------------------------ */
	$(function() {
		var clickedItem = $("#about");
		var origContainHeight = clickedItem.actual('height');
		var origContentHeight = clickedItem.find(".content-area").actual('height');
		var origVLineHeight = clickedItem.find(".v-line").height();
		var origLearnmorePos = clickedItem.find(".learnmore").css("bottom");
		$("#about .learnmore").click(function(noscroll) {
			var contentHeight = clickedItem.find(".content-area").actual('height');
			var hiddenHeight = clickedItem.find(".hidden").actual('outerHeight');
			var totalHeight = (hiddenHeight + contentHeight);
			var vertlineHeight = clickedItem.find(".v-line").height();
			var totalLineHeight = (totalHeight + vertlineHeight) - 190;
			noscroll.preventDefault();
			if ( !($(this).hasClass("learnless")) ) {	
				clickedItem.find(".hidden").stop(true, true).slideDown();
				clickedItem.find(".content-area").stop(true, true).animate({ height: totalHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: totalLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: (origContainHeight + hiddenHeight) }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).addClass("learnless"); 
			}
			else if ( ($(this).hasClass("learnless")) ) {
				clickedItem.find(".hidden").stop(true, true).slideUp();
				clickedItem.find(".content-area").stop(true, true).animate({ height: origContentHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: origVLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: origContainHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).removeClass("learnless");
			}
		});
	});
	
	$(function() {
		var clickedItem = $("#competition");
		var origContainHeight = clickedItem.actual('height');
		var origContentHeight = clickedItem.find(".content-area").actual('height');
		var origVLineHeight = clickedItem.find(".v-line2").height();
		var origLearnmorePos = clickedItem.find(".learnmore").css("bottom");
		$("#competition .learnmore").click(function(noscroll) {
			var contentHeight = clickedItem.find(".content-area").actual('height');
			var hiddenHeight = clickedItem.find(".hidden").actual('outerHeight');
			var totalHeight = (hiddenHeight + contentHeight);
			var vertlineHeight = clickedItem.find(".v-line2").height();
			var totalLineHeight = (totalHeight + vertlineHeight) - 80;
			noscroll.preventDefault();
			if ( !($(this).hasClass("learnless")) ) {	
				clickedItem.find(".hidden").stop(true, true).slideDown();
				clickedItem.find(".content-area").stop(true, true).animate({ height: totalHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line2").stop(true, true).animate({ height: totalLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: (origContainHeight + hiddenHeight) }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).addClass("learnless"); 
			}
			else if ( ($(this).hasClass("learnless")) ) {
				clickedItem.find(".hidden").stop(true, true).slideUp();
				clickedItem.find(".content-area").stop(true, true).animate({ height: origContentHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line2").stop(true, true).animate({ height: origVLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: origContainHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).removeClass("learnless");
			}
		});
	});
	
	$(function() {
		var clickedItem = $("#resources");
		var origContainHeight = clickedItem.actual('height');
		var origContentHeight = clickedItem.find(".content-area").actual('height');
		var origVLineHeight = clickedItem.find(".v-line").height();
		var origLearnmorePos = clickedItem.find(".learnmore").css("bottom");
		$("#resources .learnmore").click(function(noscroll) {
			var contentHeight = clickedItem.find(".content-area").actual('height');
			var hiddenHeight = clickedItem.find(".hidden").actual('outerHeight');
			var totalHeight = (hiddenHeight + contentHeight);
			var vertlineHeight = clickedItem.find(".v-line").height();
			var totalLineHeight = (totalHeight + vertlineHeight) - 160;
			noscroll.preventDefault();
			if ( !($(this).hasClass("learnless")) ) {	
				clickedItem.find(".hidden").stop(true, true).slideDown();
				clickedItem.find(".content-area").stop(true, true).animate({ height: totalHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: (totalLineHeight - 139) }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: totalLineHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).addClass("learnless"); 
			}
			else if ( ($(this).hasClass("learnless")) ) {
				clickedItem.find(".hidden").stop(true, true).slideUp();
				clickedItem.find(".content-area").stop(true, true).animate({ height: origContentHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: origVLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: origContainHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).removeClass("learnless");
			}
		});
	});

	$(function() {
		var clickedItem = $("#sponsors");
		var origContainHeight = clickedItem.actual('height');
		var origContentHeight = clickedItem.find(".content-area").actual('height');
		var origVLineHeight = clickedItem.find(".v-line").height();
		var origLearnmorePos = clickedItem.find(".learnmore").css("bottom");
		$("#sponsors .learnmore").click(function(noscroll) {
			var contentHeight = clickedItem.find(".content-area").actual('height');
			var hiddenHeight = clickedItem.find(".hidden").actual('outerHeight');
			var totalHeight = (hiddenHeight + contentHeight);
			var vertlineHeight = clickedItem.find(".v-line").height();
			var totalLineHeight = (totalHeight + vertlineHeight) - 160;
			noscroll.preventDefault();
			if ( !($(this).hasClass("learnless")) ) {	
				clickedItem.find(".hidden").stop(true, true).slideDown();
				clickedItem.find(".content-area").stop(true, true).animate({ height: totalHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: totalLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: totalLineHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).addClass("learnless"); 
			}
			else if ( ($(this).hasClass("learnless")) ) {
				clickedItem.find(".hidden").stop(true, true).slideUp();
				clickedItem.find(".content-area").stop(true, true).animate({ height: origContentHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".v-line").stop(true, true).animate({ height: origVLineHeight }, 500).css('overflow', 'visible');
				clickedItem.animate({ height: origContainHeight }, 500).css('overflow', 'visible');
				clickedItem.find(".learnmore").stop(true, true).animate({ bottom: origLearnmorePos }, 500).removeClass("learnless");
			}
		});
	});
	
/* FORM1/FORM2 ACTIVE LABEL FUNCTION
------------------------------------------------------------ */
	$(function($){
		$("#form1 .txt, #form2 .txt").focus(function() {
			$(this).parent().find("label").css("color", "#fff");
		}).blur(function() {
			$(this).parent().find("label").css("color", "#999");
		});
	});

/* INITIATE JQUERY TWEET
------------------------------------------------------------ */
	$(function($){
	  $(".tweet").tweet({
	    count: 3,
	    query: "#smartrisk",
	    loading_text: "Loading Tweets...",
	    refresh_interval: 60,
	    template: '{user} says "{text}"'
	  }).bind("empty", function() { $(this).append("No matching tweets found.<br /><br />"); });
   });
   
/* INITIATE NIVO SLIDER
------------------------------------------------------------ */
	$(function($){
		$('#slider').nivoSlider({
		  effect: 'fade',
		  directionNav: false,
		  directionNavHide: true,
		  controlNav: true,
		  keyboardNav: false,
		  pauseOnHover: false
		});
	});
   
/* INITIATE LIGHTBOX
------------------------------------------------------------ */
	$('.lightbox').lightbox();
	
/* IF TOUCH DEVICE REMOVE LIGHTBOX CLASSES
------------------------------------------------------------ */
	$('html.touch .lightbox').removeClass("lightbox");
	
});

/* INFOGRAPHIC PARALLAX FUNCTION + INITIATE
------------------------------------------------------------ */
	$(window).scroll(function () {
		var windowTop = $(this).scrollTop();        
		if (windowTop >= $("#about").offset().top) {
			$("#about .info-2").animate({ right: "10px" }, 1000, function() {
				$("#about .info-on").css("display", "block");
				$("#about .info-1").css("background-position", "0 -83px");
			});
		}
		if (windowTop >= $("#broughtby").offset().top) {
			$("#sponsors .info-1 img").css("display", "block");
		} 
	});

})(window.jQuery);
