$(document).ready(function() {
    
    var agent = navigator.userAgent.toLowerCase();
	var is_iphone = ((agent.indexOf('iphone') != -1));
	var is_ipad = ((agent.indexOf('ipad') != -1));
	
	if (is_iphone) { 
		
	}	
	
	if (is_ipad) { 

	}	
	
	
	var ie_version = getInternetExplorerVersion();
	
	// Setup a default popup link binding
    $('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=600, height=800, scrollbars'); e.preventDefault(); });

	$('#projectThumbs .projectLink').eq(4).css("margin-right","0px");
	$('#projectThumbs .projectLink').eq(9).css("margin-right","0px");
	$('#projectThumbs .projectLink').eq(14).css("margin-right","0px");	
	//$('#projectThumbs .projectLink').eq(10).css("margin-left","198px");
	$('#projectThumbs .projectLink').eq(10).css("margin-bottom","0px");
	$('#projectThumbs .projectLink').eq(11).css("margin-bottom","0px");
	$('#projectThumbs .projectLink').eq(12).css("margin-bottom","0px");
	$('#projectThumbs .projectLink').eq(13).css("margin-bottom","0px");	
	$('#projectThumbs .projectLink').eq(14).css("margin-bottom","0px");	

});

function getInternetExplorerVersion() {
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

function popupWindow(url, name, attributes){
	// Append popup to the URL if it does not already exist
	var queryStringExists = false;
	if(url.match(/\?/)) {
		queryStringExists = true;
	}
	
	if(queryStringExists) {
		// Only append if we haven't already got the parameter popup defined
		if(!url.match(/(\?|&)popup=/)) {
			url = url + '&popup=true';
		}
	} else {
		url = url + '?popup=true';
	}
	
	var baseTags = document.getElementsByTagName('base');
	if(baseTags != undefined && baseTags.length > 0) {
		url = baseTags[0].href + url;
	}
	
	var newWindow = window.open(url, name.replace(/[^A-z]/ig, ''), attributes);
	newWindow.focus();
}

