/*********************
Author: Timothy Grindall
Copyright: Timothy Grindall, 2008

Note: the array "city_name" is passed to this script by another script that is loaded on the same page and does not need to be included in this script.

Liscense: GNU Public Liscense. Note: if you don't know what the GNU public liscense is, you can probably find out by searching in Wikipedia at "http://www.wikipedia.org". A GNU Public Liscense basically means that you can use this code in any way you like as long as you don't sell the whole or any part of it in the original javascript or in a translated and/or compiled form.
*********************/


/**************************
*    format and print     *
**************************/

//calculate length of each of the three columns
city_count = city_name.length;//initialize city_count to number of entries in city_name array
column_size = city_count / 3;//divide by number of columns to get column size
raw_col = column_size;//debugging variable
column_size = Math.floor(column_size);//round down to an integer

dif = (city_count - (column_size*3));//calculate difference between rounded column_size and unrounded column_size
if ( dif != 0 ) {//if there is a difference we need to compensate for extra cities/entries by making slightly longer columns
column_size = column_size + 1;
}

//variable for passing count from one "for" function to the next
count_pass = 0;

document.write("<div id='cities_wrapperL'>");//begin cities_wrapperL

for (i=0; i < (column_size); i++) {//loop to display first and second columns
    //prepare a link name from the city name
    link_name = city_name[i].split(" (")[0];//#1 finds the first part of the name minus the "()"s on the end
    /*link_name_temp = link_name.split(" ")[0] + link_name.split(" ")[1];//#2 takes out the space in the name
    if (!link_name.split(" ")[1]) { link_name = link_name; }//#3 if it has no spaces, forget taking them out
    else { link_name = link_name_temp; }//#4 otherwise, finish taking them out*/
    
    document.write("<div id='cityL'><a href='fixjava.htm' onclick='javascript: window.location = \"store_info_map.html?img=\" + this_image + \"&city=" + link_name + "\"; return false;'>" + city_name[i] + "</ a></div>");
    i += column_size;
    
    //prepare a link name from the city name
    link_name = city_name[i].split(" (")[0];//#1 finds the first part of the name minus the "()"s on the end
    /*link_name_temp = link_name.split(" ")[0] + link_name.split(" ")[1];//#2 takes out the space in the name
    if (!link_name.split(" ")[1]) { link_name = link_name; }//#3 if it has no spaces, forget taking them out
    else { link_name = link_name_temp; }//#4 otherwise, finish taking them out*/
    
    document.write("<div id='cityC'><a href='fixjava.htm' onclick='javascript: window.location = \"store_info_map.html?img=\" + this_image + \"&city=" + link_name + "\"; return false;'>" + city_name[i] + "</ a></div>");
    i -= column_size;
    
    count_pass = i;//book-keeping for later (variable for passing count)
}

document.write("</div><div id='cities_wrapperR'>");//end of cities_wrapperL and start of "R"

for (i=((count_pass*2) +2); i < city_count; i++) {//loop to display third column 
    //prepare a link name from the city name
    link_name = city_name[i].split(" (")[0];//#1 finds the first part of the name minus the "()"s on the end
    /*link_name_temp = link_name.split(" ")[0] + link_name.split(" ")[1];//#2 takes out the space in the name
    if (!link_name.split(" ")[1]) { link_name = link_name; }//#3 if it has no spaces, forget taking them out
    else { link_name = link_name_temp; }//#4 otherwise, finish taking them out*/
    
    document.write("<div id='cityR'><a href='fixjava.htm' onclick='javascript: window.location = \"store_info_map.html?img=\" + this_image + \"&city=" + link_name + "\"; return false;'>" + city_name[i] + "</ a></div>");
    
    //OLD document.write("<div id='cityR'><a href='store_info_map.html?img=" + this_image + "&city=" + link_name + "'>" + city_name[i] + "</a></div>");
}

/* window.location = "store_info_map.html?img=" + this_image + "&city=" + link_name; return false; */


document.write("</div>");//end of cities_wrapperR

//debugging code for debugging column size changes
/*
document.write("<div style='float: left; clear: left;'>");
document.write("elem#: " + city_count + "<br>" + "raw: " + raw_col + "<br>" + "col-size: " + column_size + "<br>" + "dif: " + dif);
document.write("</div>");
*/


var content = document.getElementsByName("content")[0];
//if (!main) alert("main was not detected");
//else alert("main was detected");
content.id = "short-back" + (column_size - 3);//set to id that has the same positioning, but a different background image
if ( column_size < 4 ) content.id = "short-back";//in case there is three or less
if ( column_size > 9 ) content.id = "main-content_stores";


/**************************
* target example          *
**************************/



/**************************
*     target example      *
**************************/

/*
<div id="cities_wrapperL">
    <div id="cityL"><a href="Aberdeen.htm">Aberdeen</a></div>
        <div id="cityC"><a href="Gold Bar.htm">Gold Bar</a></div>
    <div id="cityL"><a href="Anacortes.htm">Anacortes</a></div>
        <div id="cityC"><a href="Granite_Falls.htm">Granite Falls</a></div>
    <div id="cityL"><a href="Arlington.htm">Arlington (2)</a></div>
        <div id="cityC"><a href="Hoodsport.htm">Hoodsport</a></div>
    <div id="cityL"><a href="Bellingham.htm">Bellingham (2)</a></div>
        <div id="cityC"><a href="Joyce.htm">Joyce (2)</a></div>
</div>
<div id="cities_wrapperR">
    <div id="cityR"><a href="Port_Angeles.htm">Port Angeles</a></div>
    <div id="cityR"><a href="Port_Townsend.htm">Port Townsend (2)</a></div>
    <div id="cityR"><a href="Poulsbo.htm">Poulsbo (2)</a></div>
    <div id="cityR"><a href="Randle.htm">Randle</a></div>
</div>
*/