// culturedstone.js -- Javascript behaviors for Cultured Stone site

function popup(target, name, width, height, scrollbars) {
	popupURL = target.href;
	scrollbars = scrollbars ? 'yes' : 'no';
	name = (name == '') ? 'popup' : name;
	popupParams = 'scrollbars=' + scrollbars + ',width=' + width + ',height=' + height;
	newWin = window.open(popupURL, name, popupParams);
	if (focus) { newWin.focus(); }
	return false;
}

function popupForPrint(target, name, width, height, scrollbars) {
	popupURL = target.href;
	scrollbars = scrollbars ? 'yes' : 'no';
	name = (name == '') ? 'popup' : name;
	popupParams = 'scrollbars=' + scrollbars + ',width=' + width + ',height=' + height + ',titlebar=yes,menubar=yes,resizable=yes';
	newWin = window.open(popupURL, name, popupParams);
	if (focus) { newWin.focus(); }
	return false;
}

function pack() {
	dims = getPopupDimensions();
	
	window.resizeTo(dims.x, dims.y + 57);
	
}

function fixExternalLinks() {
	//alert(this);
	if (element.getAttribute("rel") == "external") {
		//alert('external link found');
		element.target = "_blank";
	}
}


if (typeof(Behaviour) == 'object') { 
//Behaviour.addLoadEvent(function() { fixExternalLinks(); }); 
	var myrules = {
		'a' : function() { fixExternalLinks(); },
		'area' : function() { fixExternalLinks(); }
	};
			
	Behaviour.register(myrules);
}

function downloadTrackr() {
	$("a.download, a.dxf-link, a.program-download, a.pdf-detail-link, a.pdf-link, a.dwg-link").click(function(){
		var fileDownload = $(this).attr("href");
		console.log("downloadTrackr " + ['_trackEvent', 'File Download', 'File Downloaded', fileDownload]);
		_gaq.push(['_trackEvent', 'File Download', 'File Downloaded', fileDownload]);
		window.open(this.href);
		return false;
	});
}

// Initialize JS functions
$(document).ready(function(){
	downloadTrackr();
});
