$(document).ready(function() {

	$('#tagline ul').cycle({ 
		fx:      'fade', 
		speed:    1000, 
		timeout:  5000 
	});

	$('.home #slides-cycle').cycle({ 
		fx:      'fade', 
		speed:    1000, 
		timeout:  5000 
	});
	
	/* --- */
	
	$('#navigation > li:has(> ul)').addClass("hassub");
	
	$("#navigation li").hover(function() {
		$(this).children("ul").slideDown(200);
	}, function() {
		$(this).children("ul").hide();
	});
	
	/* --- */
	
	$('abbr[title], acronym[title]').colorTip({
		color:'black',
		timeout: 100
	});
	
	/* --- */
	
	$('#header-search').css({
		width: "50px"
	});
	
	$('#header-search label').click(function() {
	
		if($(this).hasClass('active')) {
			$(this).removeClass('active');
			$(this).html('Search');
			$('#header-search').animate({
				width: "50px"
			}, 200);
		} else {
			$(this).addClass('active');
			$(this).html('Search:');
			$('#header-search').animate({
				width: "200px"
			}, 200, function() {
				$('#header-search input').focus();
			});
		}
	
	});
	
	/* --- */
	
	$(".accordion").accordion({
		autoHeight: true,
		collapsible: true,
		active: false
	});
	
	/* --- */
	
	$('.sectors-list li a').hover(function() {
	
		$(this).children('.icon').stop().animate({
			top: "-10px"
		}, 300, 'easeOutBounce');
	
	}, function() {
	
		$(this).children('.icon').stop().animate({
			top: "0"
		}, 300, 'easeOutBounce');
	
	});
	
	
	$('.subpages-list li a').hover(function() {
	
		$(this).children('.icon').stop().animate({
			top: "-10px"
		}, 300, 'easeOutBounce');
	
	}, function() {
	
		$(this).children('.icon').stop().animate({
			top: "0"
		}, 300, 'easeOutBounce');
	
	});
	
	/* --- */
	
	$('#joinnews .news .rss').hide();
	
	$('#joinnews .news').hover(function() {
		$('#joinnews .news .rss').fadeIn(300);
	}, function() {
		$('#joinnews .news .rss').fadeOut(300);
	});
	
	/* --- */
	
	$('#totop').hide();
	
	$(window).scroll(function() {
		var position = $(this).scrollTop();
		
		if(position > 180) {
			$('#totop').fadeIn(300);
		} else {
			$('#totop').fadeOut(300);
		}
	});
	
	$('#totop').click(function(e) {
		e.preventDefault();
		$('html,body').animate({scrollTop: 0}, 500);
	});
	
	/* --- */
	
	$(".related-studies .carousel").jCarouselLite({
		btnNext: 	".controls .next",
		btnPrev:	".controls .prev",
		scroll:		1,
		easing:		"swing",
		speed:		300,
		auto: 		5000
	});
	
	$(".news .carousel").jCarouselLite({
		btnNext: 	".controls .down",
		btnPrev:	".controls .up",
		scroll:		1,
		easing:		"swing",
		speed:		300,
		auto: 		5000,
		vertical:	true,
		visible: 1
	});
	
	/* --- */
	
	$(".study .thumbnail a img:not(.mask)").css({
		opacity: "0.7"
	});
	
	$(".study .thumbnail a").hover(function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "1"
		}, 300);
	}, function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "0.7"
		}, 300);
	});
	
	/* --- */
	
	$('.thumbnail a.withdate').hover(function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "0"
		}, 300);
	}, function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "1"
		}, 300);
	});
	
	
	$('.related-studies .thumbnail a').children('img:not(.mask)').css({
		opacity: "0.7"
	});
	
	$('.related-studies .thumbnail a').hover(function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "1"
		}, 300);
	}, function() {
		$(this).children('img:not(.mask)').stop().animate({
			opacity: "0.7"
		}, 300);
	});
	
	/* --- */
	
	$('.gform_body input[type="text"], .gform_body textarea').blur(function(){
		$(this).parent(".ginput_container").stop().animate({
			backgroundColor: "#f2f2f2"
		}, 200);
	});
	
	$('.gform_body input[type="text"], .gform_body textarea').focus(function() {
		$(this).parent(".ginput_container").stop().animate({
			backgroundColor: "#e2e3f1"
		}, 200);
	});
	
	
	
	$('.gform_body textarea').css({
			height: "16px"
	});
	
	$('.gform_body textarea').blur(function() {
		if($(this).val() == "") {
			$(this).stop().animate({
				height: "16px"
			}, 200);
		}
	});
	
	$('.gform_body textarea').focus(function() {
		$(this).stop().animate({
			height: "200px"
		}, 200);
	});
	
	
	/* --- */

	$('.googlemap').gMap({
		mapTypeControl:         true,
		zoomControl:            true,
		panControl:             true,
		scaleControl:           true,
		streetViewControl:      true,
		
		address:	"42 Technology Ltd, Meadow Lane, St. Ives, Cambridgeshire, PE27 4LG",
		zoom:		12,
		markers:	[{
						latitude: 52.32313060627961,
						longitude: -0.06820321083068848, 
						html: "<h6 style='margin-bottom: 5px'>42 Technology</h6><p style='margin-bottom: 5px'>Meadow Lane, St. Ives, <br />Cambridgeshire, PE27 4LG</p><p style='margin-bottom: 5px'><strong>Tel: </strong> +44 (0)1480 302700</p>",
						icon: {
							image: 'http://42.thinblack.com/wp-content/themes/42/images/42-map-marker.png',
							iconsize: [40, 34],
							iconanchor: [15, 26],
							infowindowanchor: [100, 100]
						}
					}]
		
	});

});
