/*
 * Footer
 */

$('#footerMore').click(function() {
	if ($(this).hasClass('footerHide')) {
		$(this).removeClass('footerHide').addClass('footerMore').html('+&nbsp;&nbsp;More');
	} else {
		$(this).removeClass('footerMore').addClass('footerHide').html('-&nbsp;&nbsp;Hide');
	}
	$('#footerOpen').slideToggle(500, function() {
		$('#footerFoot').scrollintoview();
	});
	return false;
});

$('#featuredSlideshow .slide').mouseover(function() {
	var entryId = $(this).data('entry-id');
	$('#caption-'+entryId).hide();
	$('#more-'+entryId).show();
}).mouseout(function() {
	var entryId = $(this).data('entry-id');
	$('#caption-'+entryId).show();
	$('#more-'+entryId).hide();
});

$('#showreelSlideshow').mouseover(function() {
	$('#showreelView').html('+ Click to view');
}).mouseout(function() {
	$('#showreelView').html('');
});

$('.linkedItem').mouseover(function() {
	$(this).removeClass('grey');
	$(this).addClass('black');
	$('.more', this).addClass('moreHover');
	$('.rollReveal', this).show();
}).mouseout(function() {
	$('.more', this).removeClass('moreHover');
	$('.rollReveal', this).hide();
	$(this).removeClass('black');
	$(this).addClass('grey');
}).click(function() {
	var url = $(this).data('url');
	var target = $(this).data('target');
	if ("blank" == target) {
		window.open(url);
	} else {
		location = url;
	}
});

$('#listArticles article').live({
	mouseover: function() {
		var entryId = $(this).data('entry-id');
		$('#img-'+entryId).show();
		$('#title-'+entryId).hide();
		$('#category-'+entryId).hide();
		$('#summary-'+entryId).show();
		$('#readMore-'+entryId).show();
	},
	mouseout: function() {
		var entryId = $(this).data('entry-id');
		$('#img-'+entryId).hide();
		$('#summary-'+entryId).hide();
		$('#readMore-'+entryId).hide();
		$('#title-'+entryId).show();
		$('#category-'+entryId).show();
	},
	click: function() {
		/*var url = $(this).data('url');
		var target = $(this).data('target');
		if ("blank" == target) {
			window.open(url);
		} else {
			location = url;
		}*/
	}
});

$('#newsOverview #listArticles article .hotspot').live({
	mouseover: function() {
		var entryId = $(this).data('entry-id');
		var height = $(this).children('h1').height();
		$('#img-'+entryId).show();
		$('#title-'+entryId).hide();
		$('#category-'+entryId).hide();
		$('#summary-'+entryId).height(height).show();
		$('#readMore-'+entryId).show();
	},
	mouseout: function() {
		var entryId = $(this).data('entry-id');
		$('#img-'+entryId).hide();
		$('#summary-'+entryId).hide();
		$('#readMore-'+entryId).hide();
		$('#title-'+entryId).show();
		$('#category-'+entryId).show();
	},
	click: function() {
		
		var url = $(this).data('url');
		var target = $(this).data('target');
		if ("blank" == target) {
			window.open(url);
		} else {
			self.location.href = url;
		}
	}
});

$('#furtherReading #listArticles article .hotspot').live({
	mouseover: function() {
		var entryId = $(this).data('entry-id');
		var height = $(this).children('h1').height();
		$('#img-'+entryId).show();
		$('#title-'+entryId).hide();
		$('#category-'+entryId).hide();
		$('#summary-'+entryId).height(height).show();
		$('#readMore-'+entryId).show();
	},
	mouseout: function() {
		var entryId = $(this).data('entry-id');
		$('#img-'+entryId).hide();
		$('#summary-'+entryId).hide();
		$('#readMore-'+entryId).hide();
		$('#title-'+entryId).show();
		$('#category-'+entryId).show();
	},
	click: function() {
		console.debug('hotspot');
		var url = $(this).data('url');
		var target = $(this).data('target');
		if ("blank" == target) {
			window.open(url);
		} else {
			location = url;
		}
	}
});


$('#prevNext .prev').mouseover(function() {
	$('#prevNextText').html('PREVIOUS');
}).mouseout(function() {
	$('#prevNextText').html('');
});

$('#prevNext .next').mouseover(function() {
	$('#prevNextText').html('NEXT');
}).mouseout(function() {
	$('#prevNextText').html('');
});

$('.itemHighlighting article').live({
	mouseover: function() {
		var entryId = $(this).data('entry-id');
		$('#work-'+entryId+' .title').hide();
		$('#work-'+entryId+' .projectDate').hide();
		$('#work-'+entryId+' .clickMore').show();
		if ( !($.browser.msie && parseInt($.browser.version) <= 8)) {
			$('.itemHighlighting article:not(#work-'+entryId+')').stop().fadeTo(500, 0.4);
		}
	},
	mouseout: function() {
		var entryId = $(this).data('entry-id');
		$('#work-'+entryId+' .clickMore').hide();
		$('#work-'+entryId+' .title').show();
		$('#work-'+entryId+' .projectDate').show();
        if ( !($.browser.msie && parseInt($.browser.version) <= 8)) {
			$('.itemHighlighting article:not(#work-'+entryId+')').stop().fadeTo(500, 1);
		}
	},
	click: function() {
		location = $(this).data('url');
	}
});

$('#aboutSummary .slide').mouseover(function() {
	$('#captionBox').stop().animate({"bottom": "0px"}, 200);
}).mouseout(function() {
	$('#captionBox').stop().animate({"bottom": "-34px"});
});

$('#aboutSummary #captionBox').mouseover(function(){
	$(this).stop().animate({"bottom": "0px"});
}).mouseout(function() {
	$(this).stop().animate({"bottom": "-34px"});
});

$('#contact .slide').mouseover(function() {
	$('#captionBox').stop().animate({"bottom": "0px"}, 200);
}).mouseout(function() {
	$('#captionBox').stop().animate({"bottom": "-34px"});
});

$('#contact #captionBox').mouseover(function(){
	$(this).stop().animate({"bottom": "0px"});
}).mouseout(function() {
	$(this).stop().animate({"bottom": "-34px"});
});


$('#aboutSummary #clientList a').mouseover(function() {
	var img = $(this).data('img');
	var disabled = $(this).data('disabled');
	$('#clientImg').attr('src', '');
	$('#clientImg').attr('src', img);
	if (!disabled) {
		$('#clientMore').html('Click to view');
	}
}).mouseout(function() {
	$('#clientMore').html('');
}).click(function(e) {
	var disabled = $(this).data('disabled');
	if (disabled) {
		e.preventDefault();
	}
});

$('#aboutSummary #officeList a').mouseover(function() {
	var img = $(this).data('img');
	$('#officeImg').attr('src', '');
	$('#officeImg').attr('src', img);
	$('#officeMore').html('Click to go to website');
}).mouseout(function() {
	$('#officeMore').html('');
});

$('#clientFilterCol a').click(function() {
	$('#clientFilter').slideToggle(500);
});

$('#yearCol a').click(function() {
	$('#yearFilter').slideToggle(500);
});

$('#newsFilterCol ul a').live({
	click: function (e) {
		e.preventDefault();
		var ulEl = $(this).closest('ul');
		var url = $(this).attr('href');
		var addUrl = $(this).data('addUrl');
		if (addUrl != undefined && addUrl != '' ) {
			url = url + addUrl;
		}
		var id = $(this).data('id');
		$('#noResults').hide();
		$('#loading').show();
		$.ajax({
			url: url,
			success: function(data) {
				$('li', ulEl).removeClass('current');
				$('#item-'+id).addClass('current');
				
				if ( ($.browser.msie && parseInt($.browser.version) <= 8)) {
					$('#results').html(innerShiv(data));
					newsFilterLinkMagic();
				} else {
					$('#results').hide().html(data).fadeIn(function() {
						newsFilterLinkMagic();
					});
				}
				if ($('#results article').length == 0) {
					$('#noResults').show();
				}
				$('#loading').hide();
			}
		});
	}
});

function newsFilterLinkMagic() {
	var clientUrlTitle = $('#listArticles').data('client');
	if (clientUrlTitle != undefined) {
		var clientLink = '';
		if (clientUrlTitle != '') {
			var clientLink = '/client/' + clientUrlTitle;
		}
		$('#yearFilter a').each(function() {
			$(this).data('addUrl', clientLink);

		});
	}

	var filterYear = $('#listArticles').data('year');
	if (filterYear != undefined) {
		var yearLink = '';
		if (filterYear != '') {
			var yearLink = '/year/' + filterYear;
		}
		$('#clientFilter a').each(function() {
			$(this).data('addUrl', yearLink);

		});
	}
}

$('#workFilterCol ul a').live({
	click: function (e) {
		e.preventDefault();
		var el = $(this).closest('div');
		var url = $(this).attr('href');
		var addUrl = $(this).data('addUrl');
		if (addUrl != undefined && addUrl != '' ) {
			url = url + addUrl;
		}
		var id = $(this).data('id');
		$('#noResults').hide();
		$('#loading').show();
		$.ajax({
		  url: url,
		  success: function(data) {
			  $('a', el).parent().removeClass('current');
			  $('#item-'+id).addClass('current');
			  if ( ($.browser.msie && parseInt($.browser.version) <= 8)) {
			  	$('#results').html(innerShiv(data));
				workFilterLinkMagic();
			  } else {
				$('#results').hide().html(data).fadeIn(function() {
				  	workFilterLinkMagic();
			  	});
			  }
			  if ($('#results article').length == 0) {
				  $('#noResults').show();
			  }
			  $('#loading').hide();
		  }
		});
	}
});

function workFilterLinkMagic() {
	var clientUrlTitle = $('#listArchive').data('client');
	  if (clientUrlTitle != undefined ) {
		  var clientLink = '';
		  if (clientUrlTitle != '') {
			  var clientLink = '/client/' + clientUrlTitle;
		  }
		  $('#dateNameSort a').each(function() {
			  $(this).data('addUrl', clientLink);
			  
		  });
	  }
	  
	  var filterOrder = $('#listArchive').data('order');
	  if (filterOrder != undefined && filterOrder != '' ) {
		  var filterLink = '/order/' + filterOrder;
		  $('#clientFilter a').each(function() {
			  $(this).data('addUrl', filterLink);
			  
		  });
	  }
}


$('#search').click(function(e) {
	e.preventDefault();
	$('#searchContainer').animate({
		top: '-32px'
	}, 250, 'easeOutQuad');
	//$('#keywords').trigger('focus');
});

$('#keywords').focus(function() {
	if ($(this).val().length > 0) {
		$('#searchText').hide();
	} else {
		$('#searchText').show();
	}
}).blur(function() {
	if (!$(this).attr('value')) { 
		$('#searchText').show();
	}
});

$('#searchText').click(function() {
	$('#keywords').focus();
});

$('input#keywords').keyup(function() {
	if ($(this).attr('value').length > 0) {
		$('#searchText').hide();
	} else {
		$('#searchText').show();
	}
});

$('#searchHide').click(function(e) {
	e.preventDefault();
	$('#searchContainer').animate({
		top: '-196px'
	}, 250, 'easeOutQuad');
});

var KEYCODE_ESC = 27;

$(document).keyup(function(e) {
	if (e.keyCode == KEYCODE_ESC) {
		$('#searchHide').click();
	} 
});




