$(document).ready(function() {
	if (window.fixPNG) fixPNG('.playbutton'); // magic global function, additional pngs to fix
	
	$('.popupLink, a[rel~=popup]').live("click", function(event) {
		var url 	= event.target.href;
		var width 	= getURLParameter('w', url);
		var height 	= getURLParameter('h', url);
		var scroll 	= getURLParameter('s', url);
		
		openPopup(url, $(this).attr('href'), width, height, scroll);
		
		return false;
	});
	
	// plain new window
	$('a[rel~=new]').live("click", function() {
		window.open($(this).attr('href'));
        return false;
	});
	
	// add analytics tracking string to all external links
	$('a').click(function() { 		
		lhref = $(this).attr('href');
		if(lhref.indexOf('http://') != -1) { // check it's an external link 
			//Replace all odd characters, so that it works with Analytics Navigation analysis  
			var url = lhref.replace(/[^a-z|A-Z]/g, "_");
			var txt = $(this).html().replace(/[^a-z|A-Z]/g, "_");
			var str = '/outgoinglink/-' + txt + '-' + url;
			
			try {
				pageTracker._trackPageview(str);  
			} catch(err) { 
			}  
		}
	});
	
	
	$('#becomeAFan').click(function(){
		try {
			pageTracker._trackPageview("/FaceBookPage");  
		} catch(err) { 
		}
		//window.location = $(this).attr('href');
		window.open ($(this).attr('href'),"fackbook"); 
		return false;
	});
	
});

function openPopup(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	
	var realname = myname.substring(1,4);
	
	window.open(mypage, realname, settings);
	return false;
}

function getURLParameter(name, url)
{
	url = (url != null)?url:window.location.href;
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if( results == null )
		return "";
	else
		return results[1];
}