﻿function embedLocation(url) {

    var listWrapper = $("div#loc-wrapper-more_column div#loc-list");
    var flashWrapper = $("div#loc-wrapper-more_column div#loc-flash_map");

    if ($.browser.mozilla) {
        var locShellSwf = "_inc/swf/firefox/pr_locations_shell_ff.swf";
        var locSwf = "_inc/swf/firefox/";
    } else {
        var locShellSwf = "_inc/swf/pr_locations_shell.swf";
        var locSwf = "_inc/swf/";
    }

    if ($("#properties").length) {
        var retailFlash = true;
    } else {
        var retailFlash = false;
    }

    // for js users
    $("div#loc-wrapper div#loc-list").css("borderTop", "dotted 1px #666");

    // define inital state depending on flash or no flash
    if (swfobject.getFlashPlayerVersion().major >= 9) {
        flashWrapper.css({ display: "block" });

        /*  Commented out until we get the flash map    */
        var flashvars = {};
        flashvars.swfPath = rootVirtual + locSwf;
        flashvars.xmlPath = rootVirtual + url;
        flashvars.retail = retailFlash;
        var params = {};
        params.wmode = "opaque";
        params.allowscriptaccess = "always";
        var attributes = {};
        swfobject.embedSWF(rootVirtual + locShellSwf, "flash", "679", "665", "9.0.0", false, flashvars, params, attributes);

    }
}

// Prime Outlets Event Tracking (Prime Retail Google Custom API)
var PrimeEventTracking = {
	
	// Track user clicking on an outlet center location.
	MapSelect: function(location){
		var args = {
			category: 'map+of+locations', 
			action: 'map+select', 
			label: location
		}
		PrimeEventTracking._trackEvent(args);
	},
	
	// Track user clicking any link to property detail page from map. 
	MapLink: function(location){
		var args = {
			category: 'map+of+locations', 
			action: 'map+link',
			label: location
		}
		PrimeEventTracking._trackEvent(args);	
	},
	
	// Track user downloading property details PDF.
	MapDownload: function(location){
		var args = {
			category: 'map+of+locations', 
			action: 'map+download+pdf', 
			label: location
		}
		PrimeEventTracking._trackEvent(args);	
	},
		
	// Private
	_trackEvent: function(oArgs) {
		//var _source = oArgs.source || document.location.pathname+document.location.search+document.location.hash;
		var _source = oArgs.source || document.location.pathname;
		//var _media = oArgs.media || 'js';		// flash, js, etc.
		var _category = oArgs.category || '';		// RIA object
		var _action = oArgs.action || ''; 		// what is happening
		var _label = oArgs.label || '';			// what is being viewed
		//var _value = oArgs.value || '';
		//var _target = oArgs.target || '';
		
		// Instantiate GA tracking call
		//var sReport = encodeURI('/_event/object='+_object+'/action='+_action+'/label='+_label);
		var sReport = encodeURI(_source+'?utm_category='+_category+'&utm_action='+_action+'&utm_label='+_label);
	
		try{
			urchinTracker(sReport);
			// Only uncomment during debugging
			//console.log("urchinTracker being called with: %s", sReport);
			//console.dir(oArgs);
		}
		catch(e){}
	}
}

/* Sample tracking calls
PrimeEventTracking.MapSelect('san+marcos');
PrimeEventTracking.MapLink('pismo+beach');
PrimeEventTracking.MapDownload('st.+augustine');
*/

// prevent errors from console calls to browsers that don't provide firebug's debugging console.
if (!window.console || !console.firebug)
{
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {}
}