// Click on filterpanel
$('#filters ul li[class!="selected"] a, #filterclone ul li[class!="selected"] a').live('click', function() {
	var me = $(this),
		parent = $.trim(me.parent().parents('li').clone().children().remove().end().text()),
		action = parent.substring(0, parent.length-1),
		label = me.children('span:first').text(),
		href = me.attr('href');
		
	_gaq.push(['_trackEvent', 'Filter', action, label]);
	setTimeout('document.location="'+ href +'"', 150);
});

// Click on filter inside details-view
$('dd.detailsfilter a').live('click', function(){
	var me = $(this),
		action = me.attr('data-action'),
		label = me.text(),
		href = me.attr('href');

	_gaq.push(['_trackEvent', 'Filter', action, label]);
	setTimeout('document.location="'+ href +'"', 150);
});

function trackVirtualPreview(title, id) {
	_gaq.push(['_trackPageview', '/virtual/preview-image/'+title+'('+id+')']);
}

function trackDownload(from, id, title, urlifiedtitle, format, photographer, href) {
	_gaq.push(
		['_setCustomVar', 1, 'Download', from, 3],
		['_trackPageview', '/virtual/download-image/'+urlifiedtitle+'('+id+')'],
		['_trackEvent', format, photographer, title+'('+id+')'],
		['gwo._trackPageview', '/1128196748/goal']
	);

	setTimeout('document.location="'+ href +'"', 150);

	return false;
}

function trackSelectionDownload(href, format, images) {
	_gaq.push(
		['_setCustomVar', 1, 'Download', 'selection', 3],
		['_trackPageview', '/virtual/download-my-selection'],
		['gwo._trackPageview', '/1128196748/goal']
	);
	
	for (image in images) {
		_gaq.push(['_trackEvent', format, image.photographer, image.title+'('+image.id+')']);
	}
	
	setTimeout('document.location="'+ href +'"', 150);

	return false;
}

function trackDeniedDownload() {
	_gaq.push(['_trackPageview', '/virtual/denied-download']);
}

function trackAddToSelection(id, title) {
	_gaq.push(['_trackPageview', '/virtual/add-to-my-selection/'+title+'('+id+')']);
}

function trackShare(channel, id, title) {
	_gaq.push(['_trackPageview', '/virtual/share/'+channel+'/'+title+'('+id+')']);
}

function trackShareSelection(channel) {
	_gaq.push(['_trackPageview', '/virtual/share-selection/'+channel]);
}

function trackAcceptEmbed(id, title) {
	_gaq.push(['_trackPageview', '/virtual/embed/'+title+'('+id+')']);
}

function trackDeniedEmbed() {
	_gaq.push(['_trackPageview', '/virtual/denied-embed']);
}

