loading = '<img src="/img/loading.gif" alt="" class="loading" />';

populate_select = function(target, source, nonempty) {
	for (key in source) {
		value = source[key]['_'] || key;
		if (key != '_' && (nonempty ? source[key]['id'] : true))
			jQuery(target).append('<option value="'+ key +'">'+ value +'</option>');
	}
}

jQuery(document).ready(function() {
	jQuery('#header_lcmedia ul, #header ul.sub, #footer ul')
		.find('li:not(:last)')
		.after('<li>|</li>');

	jQuery('.more')
		.append('&nbsp;&raquo;');
	
	jQuery('.home #linkads')
		.append('<br class="clear" />');
	
	jQuery('a.file[href$=.pdf]')
		.before('<img src="'+ w_path +'img/pdf.png" alt="" /> ');	

	if (jQuery.browser.msie && jQuery.browser.version < 7)
		jQuery('.png').ifixpng();
	
	jQuery('#navbarCanoe_container, .c_CanoeNetworkBar')
		.find('a:not(#navbarCanoe_btplus)')
		.addClass('popup')
		.attr('onclick','return false;');

	jQuery('a.popup, body.article #content .entry a').click(function() {
		window.open(jQuery(this).attr('href'));
		return false;
	});
	
	jQuery('#f_subscribe, form.subscribe').submit(function() { return false; });
	jQuery('#f_subscribe .submit, form.subscribe .submit').click(function() {
		f = jQuery(this).siblings('input[name=email]').removeClass('error');
		errors = 0;
		if (!/^([-a-z0-9_\.\+])+@(([-a-z0-9])+\.)+([a-z]{2,6})+$/i.test(f.val())) {
			f.addClass('error').focus();
			errors++
		}
		if (!errors) {
			window.open('', 'f_subscribe_popup', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height=400,width=500,toolbar=no', true); 
			f.parents('form').attr('target', 'f_subscribe_popup').attr('id', '_f_subscribe');
			document.forms._f_subscribe.submit();
		};
	});
	
	jQuery('#f_default_site_site').change(function() {
		site = jQuery(this).find('option:selected').attr('value');
		window.location = 'http://www.passionperformance.ca/cookiejar?'+ site;
	});
	
	jQuery('a[target=mmuffler]').bind('click', function() {
		window.open('http://passionperformance.ca/special/monsieur_muffler/', 'mmuffler', 'width=800, height=600');
		return false;
	});
	
	jQuery('a[href^=http://]').bind('click', function() {
		url = jQuery(this).attr('href');
		if (!/passionperformance.(ca|net)|guideautoweb.com|carguideweb.com/.test(url))
			pageTracker._trackPageview('/exit/'+ url.replace(/[:\/]/g, '_'));
	})
});
