$(function() {
	
	$.each($('.newWindow'), function(k,v) {		
		$(v).attr("target", "_blank");
	});
	
	$('.thumbLink').bind('mouseenter', function() {
		$(this).stop().animate({
			borderColor: '#666666'
		});
		$(this).children('.bwImage').stop().animate({
			opacity: 0
		});
	});
	$('.thumbLink').bind('mouseleave', function() {
		$(this).stop().animate({
			borderColor: '#e4e3dc'
		});
		$(this).children('.bwImage').stop().animate({
			opacity: 1
		});
	});
		
	/*$('#slideshow').cycle({ 
		fx: 'fade', 
		speed: 300,
		next: '#infographics',
		timeout: 0 		
	});*/
	
	$.fn.qtip.styles.redTip = { // Last part is the name of the style
		padding: 5,
		background: '#FF0033',
		color: '#ffffff',
		border: {
			width: 0,
			color: '#FF0033'
		},
		tip: {
			corner: 'bottomLeft',
			size: {
	            x: 10,
	            y: 10
	        }
		}
	}
	$.fn.qtip.styles.blackTip = { // Last part is the name of the style
		padding: 5,
		background: '#000000',
		color: '#ffffff',
		border: {
			width: 0,
			color: '#000000'
		},
		tip: {
			corner: 'bottomLeft',
			size: {
	            x: 10,
	            y: 10
	        }
		}
	}
	$.fn.qtip.styles.greyTip = { // Last part is the name of the style
		padding: 5,
		background: '#ECE5DC',
		color: '#4c4c4e',
		border: {
			width: 0,
			color: '#ECE5DC'
		},
		tip: {
			corner: 'bottomLeft',
			size: {
	            x: 10,
	            y: 10
	        }
		}
	}

	$('.redToolTip').each(function() {
		$(this).qtip({
			content: '<h2 class="leagueGothic"><nobr>'+$(this).attr('title')+'</nobr></h2>',
			position: {
				target: 'mouse',
				corner: {
					target: 'topRight',
					tooltip: 'bottomLeft'
				},
				adjust: {
					x: 5,
					y: -5,
					screen: true
				}
			},
			show: { effect: { length: 300 } },
			style: 'redTip'
		}).removeAttr('title');
	});

	$('.greyToolTip').each(function() {
		$(this).qtip({
			content: '<h2 class="leagueGothic"><nobr>'+$(this).attr('title')+'</nobr></h2>',
			position: {
				target: 'mouse',
				corner: {
					target: 'topRight',
					tooltip: 'bottomLeft'
				},
				adjust: {
					x: 5,
					y: -5,
					screen: true
				}
			},
			show: { effect: { length: 150 } },
			style: 'greyTip'
		}).removeAttr('title');
	});
	
	/* --- Case Study Page --- */
	
	$('#slider').data('curSlide', 1);
	$('#galleryNavigation .nextButton').bind('click', function() {
		slideLeft('slider', $('#slider img').width());
	});
	$('#galleryNavigation .prevButton').bind('click', function() {
		slideRight('slider', $('#slider img').width());
	});
	
	/* --- Home Page Infographics --- */
	
	$('.toggler:even').css('left', '740px');
	$('.toggler:odd').css('left', '-740px');
	
	$('#showSlide2').bind('click', function() {
		$('#slide1').fadeOut('slow');
		$('#slide2').fadeIn('slow');
	});
	
	$('.showInfoGraphics').bind('click', function() {
		$('#welcomePanel').fadeOut('slow');
		$('#infoSlider').fadeIn();
		$('.toggler').animate({
			left: 0
		}, 'slow');
	});
	
	$('#infographics .toggler').bind('click', function() {
		var element = $(this).next('.element');
		if (element.is(':visible')) {
			element.slideUp().removeClass('openElement');
			$(this).removeClass('current').addClass('viewed');
			
			$(this).animate({ marginTop: '0px' });
			$('#infoSlider').animate({ top: '0px' });
		}
		else {
			$('.openElement').slideUp().removeClass('openElement');
			$('.current').removeClass('current').addClass('viewed');
			
			element.slideDown().addClass('openElement');
			$(this).addClass('current');
			
			var newTop = $(this).position().top;
			if ($(this).position().top) {
				$(this).animate({ marginTop: '20px' });
				newTop += 17;
			}
			
			$('#infoSlider').animate({
				top: '-'+newTop+'px'
			});
		}
	});
	
	$('#infographics .element img').bind('click', function() {
		var element = $(this).parent();
		element.slideUp().removeClass('openElement');
		element.prev('.toggler').removeClass('current').addClass('viewed');
		
		element.prev('.toggler').animate({ marginTop: '0px' });
		$('#infoSlider').animate({ top: '0px' });
	});
	
	$('#tabbedArea #tabs a').bind('click', function() {
		if (!$(this).is('.current')) {
			$('.current').removeClass('current');
			$(this).addClass('current');
			$('.tabPane:visible').fadeOut();
			$('.tabPane').eq($(this).parent().index()).fadeIn();
		}
		return false;
	});
});
