var sxsw_current_filters = {};

function flashContent(name, src, w, h, bgcolor, quality, align, version, vars) {
	var embed_string = '<embed src="' + src + '?1" quality="' + quality + '" width="' + w + '" height="' + h + '" bgcolor="' + bgcolor + '" name="' + name + '" align="' + align + '" ';
	if (vars) {
		embed_string += 'flashVars="' + vars + '" ';
	}
	embed_string += 'allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	var obj_string = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" width="' + w + '" height="' + h + '" id="' + name + '" align="' + align + '">';
	obj_string += '<param name="movie" value="' + src + '?1" />';
	obj_string += '<param name="bgcolor" value="' + bgcolor + '" />';
	obj_string += '<param name="quality" value="' + quality + '" />';
	obj_string += '<param name="allowScriptAccess" value="always" />';
	if (vars) {
		obj_string += '<param name="flashVars" value="' + vars + '" />';
	}
	obj_string += embed_string;
	obj_string += '</object>';
	document.write(obj_string);
}

function callFlashLoadData(filters) {
	var movie = getFlashMovie("sxsw");
	movie.initLoadData("SXSWparties.txt", "sxsw", {filters: filters});
    //movie.initLoadXML(type, filters);
}
function getFlashMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}
function showMapPoints(sxsw_array, filters) {
	sxsw_current_filters = filters;
	var map_points = {};
    var venues = sxsw_array; //alert(venues.length);
	for (var i=0; i < venues.length; i++) {
	    var venue_obj = new Object(); //sxsw_map_points[venues[i].address];
	    for (var j in venues[i]) {
	        venue_obj[unescape(j)] = unescape(venues[i][j]);
		}
		venue_obj.showAddress = true;
		venue_obj.showDirections = true;
		//venue_obj.icon = "http://alt.coxnewsweb.com/statesman/google_maps/marker_red.png";
		if (venues[i].address != null) {
			map_points[venues[i].address] = venue_obj;
		}
	}
	sxsw_map_points = map_points;
    sxsw_map_obj.display();
	/*if (filters.init) {
	    sxsw_map_points = map_points;
        sxsw_map_obj.display();
	}
	else {
    	sxsw_map_obj.update(map_points);
    }*/
}

function showSXSWEventInfo(id, address_obj) {
	var movie = getFlashMovie("sxsw");
	var event_info = movie.sxswGetEventInfo(id, sxsw_current_filters);
	var venue = event_info.venue;
    var events = event_info.events;
    var venue_txt = "<b>" + venue.name + "</b><br />";
    venue_txt += address_obj.street + ", ";
    venue_txt += address_obj.city + ", " + address_obj.state + " " + address_obj.zip;
    document.getElementById("sxsw_venue").innerHTML = venue_txt;
    var event_txt = "";
    for (var i=0; i < events.length; i++) {
        event_txt += '<div class="event">';
    	event_txt += "<h3>"+ events[i].name +"</h3>";
    	event_txt += events[i].date +", " + events[i].time + "<br /><br />";
    	if (events[i].types) {
    	    var icons = {"Free" : "free.gif", "Free Drinks" : "freedrinks.gif", "Best Pick" : "bestpick.gif", "Invite/Badge Required" : "invite.gif"};
    	    for (var j=0; j < events[i].types.length; j++) {
    	        if (icons[events[i].types[j]]) {
    	        	event_txt += '<img src="icon_'+ icons[events[i].types[j]] +'" style="vertical-align:middle; margin-right: 5px" />' + events[i].types[j] + "<br />";
    	        }
    	    }
    	    event_txt += "<br />";
		}
    	event_txt += "<strong>Performers:</strong><br />";
    	for (var j=0; j < events[i].artists.length; j++) {
			event_txt += events[i].artists[j] + "<br />";
		}
		event_txt += "</div><br />";
	}
	document.getElementById("sxsw_contents").innerHTML = event_txt;
    document.getElementById("sxsw_tint").style.display = "block";
    document.getElementById("sxsw_event").style.display = "block";
}

function closeSXSWEventInfo() {
    document.getElementById("sxsw_tint").style.display = "none";
    document.getElementById("sxsw_event").style.display = "none";
}

function showMapPointInfo(str) {
	var movie = getFlashMovie("sxsw");
    movie.showAddressInfo(str);
}

function mapTop() {
	document.getElementById("sxsw_map").style.visibility = "visible";
	document.getElementById("sxsw_map").style.zIndex = 2;
}

function alertContents(str) {
	alert(str);
}

function trim (str) {
    str = this != window ? this : str;
    return str.replace(/^s+/, '').replace(/s+$/, '');
}

function gotoLink(url) {
	try {
		if (window.opener && !window.opener.closed) {
			window.opener.focus();
			window.opener.location = url;
		}
		else {
	    	window.open(url);
		}
	}
	catch(err) {
	    window.open(url);
	}
}

