function templateNoResultsFound() {
    return '<h3>Oops! We\'re sorry, but it appears there are no showings anywhere near you! You can request an Emerging Cinemas location near you by clicking <a href="http://emergingpictures.com/emerging-pictures/contact/request-emerging-cinema/">here</a>.</h3>';
}
function templateBubbleLocationTab(name, address, address2, city, state, zip, country, phone, fax, homeAddress, url) {
    var html = '';
    html += '        <h3>' + name + '</h3>';
    html += '        <p>' + address;
                    if (address2 != '') {
    html += '            <br />' + address2;
                    }
    html += '        <br />' + city + ' ' + state + ' ' + zip + '</p>';
                    if (phone != '') {
    html += '            <p>' + phone;
                        if (fax != '') {
    html += '                <br />Fax: ' + fax;
                        }
    html += '            </p>';
                    }
                    else if (fax != '') {
    html += '            <p>Fax: ' + fax + '</p>';
                    }
                    var dir_address = address + ',' + city;
                    if (address2) { dir_address += ',' + address2; }
                    if (state) { dir_address += ',' + state; }
                    if (zip) { dir_address += ',' + zip; }
                    if (country) { dir_address += ',' + country; }
    html += '        <p class="bubble_links"><a href="http://google.com/maps?q=' + homeAddress + ' to ' + dir_address + '" target="_blank">' + get_directions_text + '</a>';
                    if (url != '') {
    html += '            &nbsp;|&nbsp;<a href="' + url + '" title="Open \'' + name + '\' in a new window" target="_blank">' + visit_website_text + '</a>';
                    }
    html += '        </p>';
    return html;
}
function templateFormatScreeningsArray(page_type, options, formatFor, location_id, tabName, screeningsArray) {
    var html = '';
    var monthShortNames = new Array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
    var dayFullNames = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    
	var today = new Date();
	var tomorrow = new Date();
	tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));
	var dayAfterTomorrow = new Date();
	dayAfterTomorrow.setTime(dayAfterTomorrow.getTime() + 2*(1000*3600*24));
	var daysToProcess = new Array(today.getFullYear() + '-' + addLeadingZeroIfNeeded((today.getMonth()+1)) + '-' + addLeadingZeroIfNeeded(today.getDate()),
	                              tomorrow.getFullYear() + '-' + addLeadingZeroIfNeeded((tomorrow.getMonth()+1)) + '-' + addLeadingZeroIfNeeded(tomorrow.getDate()),
	                              dayAfterTomorrow.getFullYear() + '-' + addLeadingZeroIfNeeded((dayAfterTomorrow.getMonth()+1)) + '-'
                                      + addLeadingZeroIfNeeded(dayAfterTomorrow.getDate()));
	                              // daysToProcess[0] = today, daysToProcess[1] = tomorrow, daysToProcess[2] = day after tomorrow, formatted like SQL dates

    if (tabName == 'Now Playing' || tabName == '_nowplaying') { // 'Now Playing' = part of the locations template
		var screeningsByDay = createScreeningsByDayArray(screeningsArray, page_type, options, daysToProcess, monthShortNames);
	    // Okay! We have now assembled the screeningsByDay array, e.g. screeningsByDay[0]["The Wizard of Oz"] = "The Wizard of Oz: 7:00, 9:30 pm" where 0 = today

        switch(formatFor) {
            case "markers":
                html += '<div class="marker_nowplaying_showtimes" id="' + formatFor + 'NowPlaying' + location_id + '">'; // Wrapper
                if (screeningsByDay[0]) { // We only show today's snowtimes here; TO-DO: this currently always evaluates as true
                    html += '    <div class="nowplaying_day" id="' + formatFor + 'NowPlaying' + location_id + '-0">';
                    for (var j in screeningsByDay[0]) { // Loop through our pseudo-associative array of objects
                        html += screeningsByDay[0][j] + '<br />'; // Just using 'j' would return only the key (the title) rather than the value (the HTML)
                    }
                    html += '    </div>';
                }
                html += '</div>'; // Close wrapper
            break;
            case "results":
            	var hideComingSoon = 1;
                html += '<div class="result_nowplaying_showtimes" id="' + formatFor + 'NowPlaying' + location_id + '">'; // Wrapper
                html += '    <ul class="nowplaying_nav">';

                if (tabName == '_nowplaying')
                	hideComingSoon = 0; // 0 = show, 1 = hide

                var tabpanelshtml = ''; // Body (jQuery tab panels, with a panel for each day):
                var tabIndex = 0; // We can't just use the i variable in the following for loop, since the tab index MUST be 0, 1, 2 even if a day is skipped
                for (i = 0; i < screeningsByDay.length-hideComingSoon; i++) { // For each day (except possibly the final 'day' that is 'Coming Soon'):
                	var newDay = true;
                	var dayHasScreenings = false;
	                for (var j in screeningsByDay[i]) { // Loop through our pseudo-associative array of objects
 						if (newDay) { // Header (Today, Tomorrow, Day After Tomorrow links which are really jQuery tabs):
 							html += '        <li><a href="#' + formatFor + 'NowPlaying' + location_id + '-' + tabIndex + '"><span>';
 							switch (i) {
								case 0:
									html += 'Today';
								break;
								case 1:
									html += dayFullNames[tomorrow.getDay()];
								break;
								case 2:
									html += dayFullNames[dayAfterTomorrow.getDay()];
								break;
								case 3:
									html += 'Coming Soon';
								break;
 							}
 							html += '</span></a></li>';
			                tabpanelshtml += '    <div class="nowplaying_day" id="' + formatFor + 'NowPlaying' + location_id + '-' + tabIndex + '">';
			                dayHasScreenings = true;
			                tabIndex++;
						}
						newDay = false;
	                    tabpanelshtml += screeningsByDay[i][j] + '<br />'; // Just using 'j' would return only the key (the title) rather than the value (the HTML)
                    }
                    if (dayHasScreenings)
                    	tabpanelshtml += '    </div>';
                }
                html += '    </ul>';
                html += tabpanelshtml;
                html += '</div>'; // Close wrapper
                jQueryTabsToInit.push('#' + formatFor + 'NowPlaying' + location_id);
            break;
        }
	} else if (tabName == "Coming Soon" || tabName == '_comingsoon') {
        // We don't need to mess with any date stuff here because the SQL query already formatted the dates and filtered out screenings in the next 3 days
        // All we need to do is group by month to avoid output like "The Wizard of Oz: Oct 22, Oct 31"
		var screeningsByDay = createScreeningsByDayArray(screeningsArray, page_type, options, daysToProcess, monthShortNames);
        // The 'Coming Soon' info, with screenings sorted by film, is in the last 'day' of the screeningsByDay array
        
        html += '<div class="' + formatFor + '_comingsoon_showtimes" id="' + formatFor + 'ComingSoon' + location_id + '">'; // Wrapper
        for (var i in screeningsByDay[screeningsByDay.length-1]) { // For each film:
        	html += screeningsByDay[screeningsByDay.length-1][i] + '<br />';
        }
        html += '</div>'; // Close wrapper
	}
    return html;
}
function templateFormatFilmsArray(page_type, options, series_id, filmsArray) {
	var html = '';
	if (page_type == 'seriesgroup') {
        var titlesArray = new Array();
        for (var i = 0; i < filmsArray.length; i++)
            titlesArray.push(new Array(filmsArray[i].getAttribute('title'),
                '<li><a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress=' + escape(options.getAttribute('namequery'))
                + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories=' + options.getAttribute('categories')
                + '&page_type=film&content=' + filmsArray[i].getAttribute('film_id') + '&geographically_limited=' + options.getAttribute('geographically_limited') + '" rel="history">'
                + filmsArray[i].getAttribute('title') + '</a>' + ((filmsArray[i].getAttribute('composer')) ? ', <em>' + filmsArray[i].getAttribute('composer')
                + '</em>' : '') + '</a></li>')); // 2D array: first dimension is film title, second is HTML code to display linked title on seriesgroup page

        titlesArray.sort(function(a, b) { // Sort by the first column of the multidimensional array, in this case the titles
            var x = a[0].toLowerCase();
            var y = b[0].toLowerCase();
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
        });

		html += '<ul>';
		for (var i = 0; i < titlesArray.length; i++)
            html += titlesArray[i][1]; // Return the HTML stored in the second column of the multidimensional array
		html += '</ul>';
	}
	return html;
}
function templateFormatPartOfSeriesArray(page_type, options, partOfSeriesArray) {
	var html = '';
	if (page_type != 'seriesgroup') {
		for (var i = 0; i < partOfSeriesArray.length; i++) {
			html += ((i > 0) ? ', ' : ' ') + '<a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress='
                + escape(options.getAttribute('namequery')) + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories='
                + options.getAttribute('categories') + '&page_type=series&content=' + partOfSeriesArray[i].getAttribute('partof_series_id') + '&geographically_limited='
                + options.getAttribute('geographically_limited') + '" rel="history">' + partOfSeriesArray[i].getAttribute('partof_name') + '</a>';
		}
	}
	return html;
}

function templateBigSearchResultForLocations(marker, name, address, address2, city, state, zip, country, distance, homeAddress,
        phone, fax, url, category, tags, resultsExtraInfo, options) {
    var html = '';

    // Left column
    html += '<div class="result_col1">';
    
        // Name & distance
        html += '<div class="result_name"><h3>' + name;
        if (distance.toFixed(1) != 'NaN') {
            if (units == 'mi') {
	            html+= ' <small>' + distance.toFixed(1) + ' miles</small>';
            }
            else if (units == 'km') {
	            html+= ' <small>' + (distance * 1.609344).toFixed(1) + ' km</small>';
            }
        }
        html += '</h3></div>';

        // Address
        html += '<div class="result_address"><address>';

        // city, state zip (includes all American, Australian and New Zealander dependencies)
        if (country == 'US' || country == 'AU' || country == 'NZ' || country == 'AS' || country == 'CA' || country == 'CC' || country == 'CK' || country == 'CX' || country == 'DO' 
            || country == 'GU' || country == 'HM' || country == 'ID' || country == 'IN' || country == 'JO' || country == 'LV' || country == 'MP' || country == 'NF' || country == 'NU' 
            || country == 'PR' || country == 'SA' || country == 'SG' || country == 'TK' || country == 'TZ' || country == 'UA' || country == 'UM' || country == 'VI')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ', ' + state : '') + ((zip != '') ? ' ' + zip : '');
        // city, state, zip (includes all British dependencies)
        else if (country == 'GB' || country == 'AI' || country == 'BM' || country == 'FK' || country == 'GG' || country == 'GI' || country == 'GS' || country == 'IM' || country == 'IO' 
            || country == 'JE' || country == 'KY' || country == 'MM' || country == 'MS' || country == 'PN' || country == 'SH' || country == 'TC' || country == 'VG')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ', ' + state : '') + ((zip != '') ? ', ' + zip : '');
        // city, state<br />zip
        else if (country == 'AE' || country == 'ZA')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ', ' + state : '') + ((zip != '') ? '<br />' + zip : '');
        // city<br /> state zip
        else if (country == 'TH' || country == 'VN')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((city != '') ? city + '<br />' : '') + ((state != '') ? state + ' ' : '') + zip;
        // city<br />state<br />zip
        else if (country == 'EG' || country == 'KE' || country == 'KZ' || country == 'RU')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((city != '') ? city + '<br />' : '') + ((state != '') ? state + '<br />' : '') + ((zip != '') ? zip + '<br />' : '');
        // city zip state
        else if (country == 'PG')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((zip != '') ? ' ' + zip : '') + ((state != '') ? ' ' + state : '');
        // city zip, state
        else if (country == 'VE')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((zip != '') ? ' ' + zip : '') + ((state != '') ? ', ' + state : '');
        // city<br />zip state
        else if (country == 'HK' || country == 'PH') // Philippines is more complicated than this; see http://docs.google.com/viewer?url=http://www.upu.int/post_code/en/countries/PHL.pdf
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((city != '') ? city + '<br />': '') + ((zip != '') ? zip + ' ' : '') + state;
        // zip city, state
        else if (country == 'AM' || country == 'AR' || country == 'CO' || country == 'MX')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ' ': '') + city + ((state != '') ? ', ' + state : '');
        // zip city<br />state
        else if (country == 'MY')
        	html += address + '<br />' + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ' ' : '') + city + ((state != '') ? '<br />' + state : '');
        // zip, city<br />state
        else if (country == 'IL' || country == 'PA')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ', ': '') + city + ((state != '') ? '<br />' + state : '');
        // zip<br />city, state
        else if (country == 'EC')
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + '<br />': '') + city + ((state != '') ? ', ' + state : '');
        // state, city zip
        else if (country == 'CR')
            html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((state != '') ? state + ', ' : '') + city + ((zip != '') ? ' ' + zip : '');

        else if (country == 'AL') // Albania likes a hyphen after its postal code.
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + '&ndash;': '') + ((state != '') ? state + ', ' : '') + city;
        else if (country == 'BD') // Bangladesh likes ' - ' separating its city from its postal code.
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ', ' + state : '') + ((zip != '') ? ' &ndash; ' + zip : '');
        else if (country == 'BR') // Brazil likes ' - ' separating its city from its state. Technically the postal code should be on the following line.
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ' &ndash; ' + state : '') + ((zip != '') ? '<br />' + zip : '');
        else if (country == 'CN') // China likes the country/postal code first, then everything else on one long line (assuming the address is in Chinese):
        	html += ((zip != '') ? 'P.R. China ' + zip + '<br />' : '')
                + ((state != '') ? state + ' ' : '') + ((city != '') ? city + ' ' : '') + address + ((address2 != '') ? ' ' + address2 : '');
        else if (country == 'CU') // Cuba adds 'CP ' before its zip.
            html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((state != '') ? state + '<br />' : '') + ((zip != '') ? 'CP ' + zip + ' ' : '') + city;
        else if (country == 'HT') // Haiti should read 'postcode district' so we put 'state, city', with the comma only if both nonblank.
            html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? 'HT' + zip + ' ' : '') + state + ((state != '' && city != '') ? ', ' : '') + city;
        else if (country == 'HU') // Hungary puts its street address between its city and postcode.
        	html += city + '<br />' + address + '<br />' + ((address2 != '') ? address2 + '<br />' : '')
                + ((state != '') ? state : '') + ((zip != '') ? zip : '');
        else if (country == 'IE') // Ireland has no postcodes! Though Dublin has postal ZONES, so if someone mistakenly enters the zone number in the zip field 
            // instead of as part of the city field, we put it after; ditto if the state field is used to store the county
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((zip != '') ? ' ' + zip : '') + ((state != '') ? ', ' + state : '');
        else if (country == 'IT') // Italy encloses its province name in parentheses.
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ' ' : '') + city + ((state != '') ? ' (' + state + ')' : '');
        else if (country == 'JP') // Japan; assumes address is in Japanese, and precedes postal code with the Japanese postal mark symbol.
            html += ((zip != '') ? '&#x3012;' + zip + '<br />' : '') + ((state != '') ? state + ' ' : '') + ((city != '') ? city + ' ' : '')
                + address + ((address2 != '') ? ' ' + address2 : '');
        else if (country == 'KR') // South Korea; assumes address is in Korean.
            html += ((zip != '') ? zip + ' ' : '') + ((state != '') ? state + ' ' : '') + ((city != '') ? city + ' ' : '') + '<br />'
                + address + ((address2 != '') ? ' ' + address2 : '');
        else if (country == 'NG') // Nigeria likes 'city zip<br />state State'
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((zip != '') ? ' ' + zip : '') + ((state != '') ? '<br />' + state + ' State' : '');
        else if (country == 'PK') // Pakistan likes a dash before its postal code; shouldn't be a state/province here.
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + city + ((state != '') ? ', ' + state : '') + ((zip != '') ? '&ndash;' + zip : '');
        else if (country == 'SV') // El Salvador adds 'CP ' before its zip and a dash after it.
            html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                 + ((zip != '') ? 'CP ' + zip + '&ndash;' : '') + city + ((state != '') ? '<br />' + state : '');
        else if (country == 'TR') // Turkey uses slashes to separate its city and province.
            html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ' ' : '') + city + ((state != '') ? ' / ' + state : '');
        else if (country == 'TW') // Taiwan seems to have no standard for where the line breaks should be, so I'll use the Western standard.
        	html += ((zip != '') ? zip : '') + ((state != '') ? state + ' ' : '') + ((city != '') ? city + ' ' : '') + '<br />'
                + address + ((address2 != '') ? ' ' + address2 : '');

        else // zip state, city (includes all Danish, Dutch, French and Norwegian dependencies)
            // Most other countries format this way, usually assuming that the state field is left blank.
            // Includes: AG, AN, AT, AW, BB, BE, BG, BL, BV, CH, CL, CY, CZ, DE, DK, DZ, EE, ES, ET, FI, FO, FR, GF, GL, GP, HN, HR, HU,
            // IR, IS, JM, LI, LT, LU, LV, MA, MD, MF, MK, MO, MQ, NC, NL, NO, PE, PF, PL, PM, PT, RE, RO, SI, SE, SK, TF, UA, WF, YT
        	html += ((address != '') ? address + '<br />' : '') + ((address2 != '') ? address2 + '<br />' : '')
                + ((zip != '') ? zip + ' ' : '') + ((state != '') ? state + ', ' : '') + city;
            // See http://www.upu.int/post_code/en/countries and http://www.addressdoctor.de/en/countries_data/addressformats.asp
		html += '</address></div>';
        	
        // Phone & fax numbers
        html += '<div class="result_phone">';
        if (phone != '') {
              html += 'Phone: ' + phone;
        }
        if (fax != '') {
              html += '<br />Fax: ' + fax;
        }
        html += '</div>'; // Close phone section

        // Visit Website and Get Directions links
        html += '<div class="result_links"><ul class="result_links_list">';
        if (url != 'http://' && url != '') {
            html += '<li><a href="' + url + '" title="' + name + '" target="_blank">' + visit_website_text + '</a>';
        }

        // Get Directions link
        if (distance.toFixed(1) != 'NaN') {
            var dir_address = address + ',' + city;
            if (state) { dir_address += ',' + state; }
            if (zip) { dir_address += ',' + zip; }
            if (country) { dir_address += ',' + country; }
            html += '<li><a href="http://google.com/maps?q=' + homeAddress + ' to ' + dir_address + '" target="_blank">' + get_directions_text + '</a>';
        }
        html += '</ul></div>';
        
    html += '</div>';

    // Right column
    html += '<div class="result_col3">';
    
        // Coming Soon
     	html += '<div class="result_comingsoon"><h4><a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress='
            + escape(options.getAttribute('namequery')) + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories='
            + options.getAttribute('categories') + '&page_type=series&content=_comingsoon&geographically_limited=' + options.getAttribute('geographically_limited')
            + '" rel="history">Coming Soon</a></h4>';
        for (tab = 0; tab < resultsExtraInfo.length; tab++) { // resultsExtraInfo[tab] = tab number; resultsExtraInfo[tab][0] = tab name; resultsExtraInfo[tab][1] = tab text
            if (resultsExtraInfo[tab][0] == "Coming Soon") {
                html += '<div class="result_comingsoon_showtimes">' + resultsExtraInfo[tab][1] + '</div>';
            }
        }
        html += '</div>';
    
    html += '</div>';

    // Middle column
    html += '<div class="result_col2">';

        // Now Playing
     	html += '<div class="result_nowplaying"><h4><a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress='
            + escape(options.getAttribute('namequery')) + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories='
            + options.getAttribute('categories') + '&page_type=series&content=_nowplaying&geographically_limited=' + options.getAttribute('geographically_limited')
            + '" rel="history">Now Playing</a></h4>';
        for (tab = 0; tab < resultsExtraInfo.length; tab++) { // resultsExtraInfo[tab] = tab number; resultsExtraInfo[tab][0] = tab name; resultsExtraInfo[tab][1] = tab text
            if (resultsExtraInfo[tab][0] == "Now Playing") {
                html += '<div class="result_nowplaying_showtimes">' +  resultsExtraInfo[tab][1] + '</div>';
            }
        }
        html += '</div>';
    
    html += '</div>';
    
    return html;
}
function templateBigSearchResultForSeries(row, options) { // 'row' can refer to each film for a series page, or a series for a seriesgroup page
	var html = '';
	var thumbnail_size_h = options.getAttribute('thumbnail_size_h');
	var thumbnail_size_w = options.getAttribute('thumbnail_size_w');
	var medium_size_h = options.getAttribute('medium_size_h');
	var medium_size_w = options.getAttribute('medium_size_w');
	if (!thumbnail_size_h) thumbnail_size_h = 150;
	if (!thumbnail_size_w) thumbnail_size_h = 150;
	if (!medium_size_h) medium_size_h = 300;
	if (!medium_size_w) medium_size_w = 300;
	var primary_image_width = medium_size_w;
	var page_type = options.getAttribute('page_type');
	if (page_type != 'seriesgroup') var id = row.getAttribute('film_id');
		else var id = row.getAttribute('series_id');
	if (row.getElementsByTagName('screening')[0]) // If there's at least one element of tag name 'screening'
		var showtimes = templateFormatScreeningsArray(page_type, options, 'results', id, options.getAttribute('content'), row.getElementsByTagName('screening'));
	var films = templateFormatFilmsArray(page_type, options, id, row.getElementsByTagName('film'));
	var partOfSeries = templateFormatPartOfSeriesArray(page_type, options, row.getElementsByTagName('partof_series'));
	
	html += '<div class="result_row_primary_image_col" id="primary_image_col' + id + '" style="width: ' + primary_image_width + 'px">';
	if (nodeHas(row, 'primary_image'))
		html += row.getAttribute('primary_image_medium').substring(0,5) + 'id ="primary_image_for_row' + id + '" '
        + row.getAttribute('primary_image_medium').substring(5, row.getAttribute('primary_image_medium').length); // Insert id=primary_image32 for example into the <img /> tag
		
	html += '</div><div id="row_body_col' + id + '" class="result_row_body_col" style="margin-left: ' + primary_image_width + 'px">';
	
	html += '<div class="result_row_title"><h3>';
	if (page_type != 'seriesgroup') 
		html += '<a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress=' + escape(options.getAttribute('namequery'))
        + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories=' + options.getAttribute('categories')
        + '&page_type=film&content=' + row.getAttribute('film_id') + '&geographically_limited=' + options.getAttribute('geographically_limited') + '" rel="history">'
        + row.getAttribute('title') + '</a>';
	else
		html += '<a href="#q=h&lat=' + options.getAttribute('center_lat') + '&lng=' + options.getAttribute('center_lng') + '&homeAddress=' + escape(options.getAttribute('namequery'))
        + '&source=' + (options.getAttribute('source')) + '&mapLock=' + options.getAttribute('map_lock') + '&categories=' + options.getAttribute('categories') 
        + '&page_type=series&content=' + id + '&geographically_limited=' + options.getAttribute('geographically_limited') + '" rel="history">' + row.getAttribute('name') + '</a>';
	html += ifExistsOutputWithWrapper(ifExistsOutputWithSpan(row.getAttribute('composer'), 'result_row_composer'),', ','') + '</h3>';
	html += ifExistsOutputWithDiv(row.getAttribute('subtitle'), 'result_row_subtitle') + '</div>';
	
	html += '<div class="result_row_tabs" id="row' + id + '">'; // Wrapper
    html += '<ul class="result_row_tabs_nav">';
	if (nodeHas(row, 'cast') || nodeHas(row, 'crew') || nodeHas(row, 'synopsis') || nodeHas(row, 'press_quotes') || nodeHas(row, 'description') || nodeHas(row, 'media_item')
            || nodeHas(row, 'poster') || nodeHas(row, 'trailer') || showtimes) // If there's any data for the other tabs, add this first one
		html += '<li><a href="#row' + id + '-0"><span>' + ((page_type != 'seriesgroup') ? 'Details' : 'Titles') + '</span></a></li>';
	if (nodeHas(row, 'cast'))
		html += '<li><a href="#row' + id + '-1"><span>Cast</span></a></li>';
	if (nodeHas(row, 'crew'))
		html += '<li><a href="#row' + id + '-2"><span>Crew</span></a></li>';
	if (nodeHas(row, 'synopsis'))
		html += '<li><a href="#row' + id + '-3"><span>Synopsis</span></a></li>';
	if (nodeHas(row, 'press_quotes'))
		html += '<li><a href="#row' + id + '-4"><span>Reviews</span></a></li>';
//	if (nodeHas(row, 'description'))
//		html += '<li><a href="#row' + id + '-5"><span>Description</span></a></li>';
	if (nodeHas(row, 'media_item') || nodeHas(row, 'poster'))
		html += '<li><a href="#row' + id + '-5"><span>Photos</span></a></li>';
	if (nodeHas(row, 'trailer'))
		html += '<li><a href="#row' + id + '-6"><span>Trailer</span></a></li>';
	if (showtimes)
		html += '<li><a href="#row' + id + '-7"><span>Showtimes</span></a></li>';
	html += '</ul>';
	
	// Body (jQuery tab panels, with a panel for each tab):
	html += '<div class="result_row_tab" id="row' + id + '-0">';
	if (page_type != 'seriesgroup') { // Details tab for a film:
		html += '<div class="result_row_group result_row_group_top result_row_group_key_people">';
		html += ifExistsOutputWithDiv(ifExistsOutputWithWrapper(row.getAttribute('conductor'), 'Conducted by ', ''), 'result_row_conductor');
		html += ifExistsOutputWithDiv(ifExistsOutputWithWrapper(row.getAttribute('director'), 'Directed by ',''), 'result_row_director');
		html += ifExistsOutputWithDiv(ifExistsOutputWithWrapper(row.getAttribute('choreographer'), 'Choreography by ', ''), 'result_row_choreographer');
		html += ifExistsOutputWithDiv(ifExistsOutputWithWrapper(row.getAttribute('starring'), 'Starring ', ''), 'result_row_starring');
		html += '</div><div class="result_row_group result_row_group_essential_data">';
		html += ifExistsOutputWithDiv(row.getAttribute('language'), 'result_row_language');
		html += ifExistsOutputWithDiv(ifExistsOutputWithSpan(formatRuntime(row.getAttribute('runtime')), 'result_row_runtime') 
            + ifExistsOutputWithWrapper(ifExistsOutputWithSpan(row.getAttribute('intermission'), 'result_row_intermission'), ' ', '')
            + ifExistsOutputWithWrapper(ifExistsOutputWithSpan(row.getAttribute('rating'), 'result_row_rating'), ', rated ', ''), 'result_row_runtime_and_intermission_and_rating');
		html += ifExistsOutputWithDiv(ifExistsOutputWithSpan(ifExistsOutputWithWrapper(row.getAttribute('imdb_url'),
            '<a href="', '" target="_new">IMDb</a>&emsp;'), 'result_row_imdb_url')
            + ifExistsOutputWithSpan(ifExistsOutputWithWrapper(row.getAttribute('url'),
            '<a href="', '" target="_new">Official Site</a>'), 'result_row_url'), 'result_row_imdb_url_and_url');
		html += '</div>';
		if (partOfSeries.length > 0)
			html += '<div class="result_row_group result_row_group_partof result_row_partof">Part of ' + partOfSeries + '</div>';
	} else { // Films tab for a series:
		html += '<div class="result_row_group result_row_group_top result_row_group_series_films">';
		if (films.length > 0)
			html += ifExistsOutputWithDiv(films, 'result_row_films') + '</div>';
	}
	html += '</div>';		
	if (nodeHas(row, 'cast'))
		html += '<div class="result_row_tab" id="row' + id + '-1">'
            + ifExistsOutputWithDiv(row.getElementsByTagName('cast')[0].childNodes[0].nodeValue, 'result_row_cast') + '</div>';
	if (nodeHas(row, 'crew'))
		html += '<div class="result_row_tab" id="row' + id + '-2">'
            + ifExistsOutputWithDiv(row.getElementsByTagName('crew')[0].childNodes[0].nodeValue, 'result_row_crew') + '</div>';
	if (nodeHas(row, 'synopsis'))
		html += '<div class="result_row_tab" id="row' + id + '-3">'
            + ifExistsOutputWithDiv(row.getElementsByTagName('synopsis')[0].childNodes[0].nodeValue, 'result_row_synopsis') + '</div>';
	if (nodeHas(row, 'press_quotes'))
		html += '<div class="result_row_tab" id="row' + id + '-4">'
            + ifExistsOutputWithDiv(row.getElementsByTagName('press_quotes')[0].childNodes[0].nodeValue, 'result_row_press_quotes') + '</div>';
	if (row.getElementsByTagName('media_item').length > 0 || nodeHas(row, 'poster')) {
		html += '<div class="result_row_tab" id="row' + id + '-5"><div id="photos' + id + '"><ul>';
		if (nodeHas(row, 'poster')) {
			html += '<li><a href="' + plugin_url + 'actions/create-img-html.php?attachment_id='
                + ifExistsOutput(row.getAttribute('poster_attachment_id')) + '&max_width=640">';
			html += ifExistsOutputWithSpan(row.getAttribute('poster_thumbnail'), 'result_row_poster');
			html += '</a></li>';
		}
		for (var i = 0; i < row.getElementsByTagName('media_item').length; i++) {
			html += '<li><a href="' + plugin_url + 'actions/create-img-html.php?attachment_id=' 
                + ifExistsOutput(row.getElementsByTagName('media_item')[i].getAttribute('media_item_attachment_id')) + '&max_width=640">';
			html += ifExistsOutputWithSpan(row.getElementsByTagName('media_item')[i].getAttribute('media_item_thumbnail'), 'result_row_media_item_thumbnail');
			html += '</a></li>';
		}
		jQueryAjaxTabsToInit.push('#photos' + id);
		html += '</ul></div></div>';
	}
	if (nodeHas(row, 'trailer'))
		html += '<div class="result_row_tab" id="row' + id + '-6">'
            + ifExistsOutputWithDiv(row.getElementsByTagName('trailer')[0].childNodes[0].nodeValue, 'result_row_trailer') + '</div>';
	if (showtimes)
		html += '<div class="result_row_tab" id="row' + id + '-7">'
            + ifExistsOutputWithDiv(showtimes, 'result_row_showtimes') + '</div>';
		
	html += '</div>'; // Close wrapper
	html += '</div>'; // Close result_row_body_col

   	// Setup tabs and animation:
   	if (nodeHas(row, 'cast') || nodeHas(row, 'crew') || nodeHas(row, 'synopsis') || nodeHas(row, 'press_quotes') || nodeHas(row, 'description') || nodeHas(row, 'media_item')
        || nodeHas(row, 'poster') || nodeHas(row, 'trailer') || showtimes) { // If more than one tab
    	jQueryTabsToInit.push('#row' + id); // Create jQuery tabs
    	if (nodeHas(row, 'primary_image')) {
			// If there are tabs for the media list or the trailer, add the event binding that moves the primary image out of the way
			jQueryTabsToBindEvents['row' + id + '-0'] = ['resizePrimaryImage', id, [primary_image_width] ];
			if (nodeHas(row, 'cast'))
				jQueryTabsToBindEvents['row' + id + '-1'] = ['resizePrimaryImage', id, [primary_image_width] ];
			if (nodeHas(row, 'crew'))
				jQueryTabsToBindEvents['row' + id + '-2'] = ['resizePrimaryImage', id, [primary_image_width] ];
			if (nodeHas(row, 'synopsis'))
				jQueryTabsToBindEvents['row' + id + '-3'] = ['resizePrimaryImage', id, [primary_image_width] ];
			if (nodeHas(row, 'press_quotes'))
				jQueryTabsToBindEvents['row' + id + '-4'] = ['resizePrimaryImage', id, [primary_image_width] ];
			if (row.getElementsByTagName('media_item').length > 0 || nodeHas(row, 'poster'))
				jQueryTabsToBindEvents['row' + id + '-5'] = ['resizePrimaryImage', id, ['120px'] ];
			if (nodeHas(row, 'trailer')) // If there are tabs for the media list or the trailer, add the event binding that moves the primary image out of the way
				jQueryTabsToBindEvents['row' + id + '-6'] = ['resizePrimaryImage', id, ['120px'] ];
			if (showtimes)
				jQueryTabsToBindEvents['row' + id + '-7'] = ['resizePrimaryImage', id, [primary_image_width] ];
		}
	}
	
	return html;
}

function jQueryTabsSelectActions(action, id, attributesArray) { // Support function for templateBigSearchResultForSeries(); called from jQueryTabsToInit
	switch (action) {
		case 'resizePrimaryImage':
			var newWidth = parseInt(attributesArray[0]);
			var primaryImageHeight = jQuery('#primary_image_for_row' + id).height();
			var primaryImageWidth = jQuery('#primary_image_for_row' + id).width();
			var primaryImageColWidth = jQuery('#primary_image_col' + id).width();
			var rowBodyColMarginLeft = jQuery('#row_body_col' + id).css('margin-left');
			var primaryImageHeight = primaryImageHeight * newWidth / primaryImageWidth; // Resize height proportionally
			jQuery('#primary_image_for_row' + id).animate({ width: newWidth, height: primaryImageHeight }, { queue: false, duration: 600 });
			jQuery('#primary_image_col' + id).animate({ width: newWidth }, { queue: false, duraction: 600 });
			jQuery('#row_body_col' + id).animate({ marginLeft: newWidth }, { queue: false, duration: 525 });
		break;
	}
}