//initialize z-index 'top' tracker

var hiZ = 2;

//arrays for all items

calcheight = 0;

var currentitems = new Array();
var items = new Array();

//distribution of catagories; print/id/web/play; 0=off, 1=on.

colwidth = new Array();
coldiv = new Array();

colwidth[1] = 0;
colwidth[2] = 0;
colwidth[3] = 0;
colwidth[4] = 0;
colwidth[5] = 0;
colwidth[6] = 0;
colwidth[7] = 0;
colwidth[8] = 0;
colwidth[9] = 0;


coldiv[1] = 1;
coldiv[2] = 1;
coldiv[3] = 1;
coldiv[4] = 1;
coldiv[5] = 1;
coldiv[6] = 1;
coldiv[7] = 1;
coldiv[8] = 1;
coldiv[9] = 1;

function findRow(maxrows, maxwidth, imgwidth){
lowestwidth = 10000;
lowestrow = 0;
    for(d=0;d<(maxrows+1);d++){
        if (colwidth[d]<lowestwidth) {
            lowestwidth = colwidth[d];
            lowestrow = d;
        }
    }
    if ((lowestwidth+imgwidth) > maxwidth)
        lowestrow = 'STOP';
    return lowestrow;
}


var coolcats = new Array();
coolcats['identity'] = 'ID';
coolcats['print'] = 'CMYK';
coolcats['interactive'] = 'RGB';
coolcats['play'] = 'Play';

//link texts for the bottom menu options;

var linktext = new Array();

linktext['EmotionAsPromotion'] = 'Emotion As Promotion: A book of Thirst is an upcoming book by the Monacelli Press showcasing the last 15 years of Thirst work. <br><br><a href="http://www.emotionaspromotion.com/" target="_new">www.emotionaspromotion.com</a>';

linktext['RickValicenti.com'] = 'If you want a glimpse behind my professional curtain, this is the place to visit. Be forewarned, your perception of me will be manipulated. <br><br><a href="http://www.rickvalicenti.com/" target="_new">www.rickvalicenti.com</a>';

linktext['MovingDesign'] = 'Here is where we sell soulful goods &mdash; not our souls.<br><br><a href="http://www.movingdesign.com/" target="_new">www.movingdesign.com</a>';

linktext['Contact'] = '1440 W Hubbard St Floor 2<br>Chicago IL 60622<br><br>T 312.334.2550<br>F 312.334.2549<br><br><a href="#">info@3st.com</a>';

linktext['Explore'] = 'This episode of the Thirst story is an exploration of  organized chaos programmed by <a href="#" onclick="showcredit(\'RI\');">Robb Irrgang</a>/3ST with narration by <a href="#" onclick="showcredit(\'RV\');">Rick Valicenti</a>. all imagery is rendered on the fly from a database filled with a combination of a wide variety of items from the depths of the Thirst archives as well as continually updated recent work. <br><br>For more randomness, hit the aste<i>Rick*</i> to shake things up.';

linktext['About Thirst'] = 'Thirst is a collective of designers, typographers, writers, illustrators and programmers founded by <a href="#" onclick="showcredit(\'RV\');">Rick Valicenti</a>. <br>Thirst aims to push the envelope without having to resort<br> to cliches like "pushing the envelope." This site features<br> a collection of recent work.';

//bios

var biotext = new Array();
var bioname = new Array();

bioname['RV'] = 'Rick Valicenti';
bioname['GV'] = 'Gina Vieceli';
bioname['RI'] = 'Rob Irrgang';
bioname['JP'] = 'John Pobojewski';

biotext['RV'] = 'Founder/Design Director of Thirst  in 1981 and Thirstype  in 1993.  Rick\'s passion for design and willingness to embrace new technologies make for a dynamic marriage of imagery and inspiration. Thirst\'s creative versatility continues to lead the discourse and pursue the elusive ideals of intelligence and real human presence within today\'s world of commerce.';

biotext['GV'] = 'Gina Vieceli joined Thirst in 2002. At Thirst her design work has published in Print, GDUSA, How, Faesthtic and Rick Valicenti\'s Playground. Gina\'s contributions to the Thirst canon are included in <a href="#" onclick="showlink(\'EmotionAsPromotion\'); return false;">Emotion as Promotion</a>, to be published in early 2005. Recently promoted to Senior Designer, Gina personally services over 12 clients including Lyric Opera of Chicago, Gilbert Paper, DHLA, Holly Hunt, and Dragon Motor Sports.';

biotext['RI'] = 'With a Business degree and an Engineering title and close to ten years of experience in the field of web development as well as more recent extensive experience with identity- and print design, Rob is currently one of the three designers at Thirst. Rob hails from the Amsterdam area, fears American diner and restaurant coffee, Budweiser and Miller prefers <a href="http://www.douwe-egberts.com/">Douwe Egberts</a> and <a href="http://www.grolschlager.com/" target="_new">Grolsch</a> &mdash; but he\'s adjusting just fine to his new home.';

biotext['JP'] = 'John joins Thirst (probably because he and Rick share the proportion of syllables in their names) after graduating from Northern Illinois University with degrees in graphic design and music. He hopes to one day combine the two disciplines both to explore how another sense can be used within design, and to free up his time. In the meantime he continues to explore how design can help others.';

//new naming convention for the catagories

cats = new Array();
cats['cid'] = 'identity';
cats['cpr'] = 'print';
cats['cwb'] = 'interactive';
cats['cpl'] = 'play';


revcats = new Array();
revcats['identity'] = 'cid';
revcats['print'] = 'cpr';
revcats['interactive'] = 'cwb';
revcats['play'] = 'cpl';

var newcats = new Array();
newcats['cid'] = 'ID';
newcats['cpr'] = 'CMYK';
newcats['cwb'] = 'RGB';
newcats['cpl'] = 'Play';

//start out with everything on

var catstat = new Array();
catstat['cid'] = catstat['cpr'] = catstat['cwb'] = catstat['cpl'] = 1;

initcid = initcpr = initcwb = initcpl = 0;
//startdiv = catsdiv[catstat['cid']+''+catstat['cpr']+catstat['cwb']+catstat['cpl']];

//setup onload event

window.onload = function()
{
	//find y-coords for menu + tagline
    
	if (document.all) {  xc=document.body.clientWidth; yc=document.body.clientHeight; }
	else { yc=window.innerHeight; xc=window.innerWidth; }

    calcheight = Math.floor((yc - 176)/144)*144;
    
    calcdiff = (yc - 176)-calcheight;
    
    calcrows = calcheight/144;
    
    document.getElementById('newarea').style.width = xc - 16;
    document.getElementById('newimg').style.width = xc - 16;
    document.getElementById('newarea').style.height = calcheight;
    document.getElementById('newimg').style.height = calcheight;
    document.getElementById('newarea').style.top = calcdiff+6;
    document.getElementById('newarea').style.visibility = 'visible';
 
	showlink('Explore');

	//init menus
      	document.getElementById('menuid').innerHTML = '<div id="menuidup"><a href="#" onmouseover="doscrollup(\'id\',1);" onmouseout="doscrollup(\'id\',0);"><img src="img/up.gif" border="0"></a></div><div id="menuiddn"><a href="#" onmouseover="doscrolldn(\'id\',1)" onmouseout="doscrolldn(\'id\',0)"><img src="img/dn.gif" border="0"></a></div><br><div id="menuidtext">';
      	document.getElementById('menupr').innerHTML = '<div id="menuprup"><a href="#" onmouseover="doscrollup(\'pr\',1)" onmouseout="doscrollup(\'pr\',0)"><img src="img/up.gif" border="0"></a></div><div id="menuprdn"><a href="#" onmouseover="doscrolldn(\'pr\',1)" onmouseout="doscrolldn(\'pr\',0)"><img src="img/dn.gif" border="0"></a></div><br><div id="menuprtext">';
      	document.getElementById('menuwb').innerHTML = '<div id="menuwbup"><a href="#" onmouseover="doscrollup(\'wb\',1)" onmouseout="doscrollup(\'wb\',0)"><img src="img/up.gif" border="0"></a></div><div id="menuwbdn"><a href="#" onmouseover="doscrolldn(\'wb\',1)" onmouseout="doscrolldn(\'wb\',0)"><img src="img/dn.gif" border="0"></a></div><br><div id="menuwbtext">';
      	document.getElementById('menupl').innerHTML = '<div id="menuplup"><a href="#" onmouseover="doscrollup(\'pl\',1)" onmouseout="doscrollup(\'pl\',0)"><img src="img/up.gif" border="0"></a></div><div id="menupldn"><a href="#" onmouseover="doscrolldn(\'pl\',1)" onmouseout="doscrolldn(\'pl\',0)"><img src="img/dn.gif" border="0"></a></div><br><div id="menupltext">';

favprint = '';
favplay = '';

cidmenu = '<b>Recent additions</b><br>';
cprmenu = '<b>Recent additions</b><br>';
cplmenu = '<b>Recent additions</b><br>';
cwbmenu = '<b>Recent additions</b><br>';

cidmenu2 = '';
cprmenu2 = '';
cplmenu2 = '';
cwbmenu2 = '';

    	for(var i=0;i<cidall.length;i++) {
    	    if (items[cidall[i]]["newish"] == 1)
		        cidmenu += '<a href="#" onclick="showitem('+cidall[i]+');">'+items[cidall[i]]["client"]+'_'+items[cidall[i]]['title']+'</a><br>'; 
            else
		        cidmenu2 += '<a href="#" onclick="showitem('+cidall[i]+');">'+items[cidall[i]]["client"]+'_'+items[cidall[i]]['title']+'</a><br>';
		}
		
		cidmenu += '<br><b>Previous work</b><br>'+cidmenu2;

		cidmenu += '<br><img src="/2005/matrix.php?weight=bold&value=+Archives"><br><a href="http://archive.3st.com/thirst_1999">Thirst 1998-1999</a><br><a href="http://archive.3st.com/thirst_2000">Thirst 2000-2002</a><br><br>';

    	for(var i=0;i<cprall.length;i++) { 
    	    if (items[cprall[i]]["newish"] == 1)
		        cprmenu += '<a href="#" onclick="showitem('+cprall[i]+');">'+items[cprall[i]]["client"]+'_'+items[cprall[i]]['title']+'</a><br>'; 
            else {
                if (items[cprall[i]]["favorite"]=='no')
                		cprmenu2 += '<a href="#" onclick="showitem('+cprall[i]+');">'+items[cprall[i]]["client"]+'_'+items[cprall[i]]['title']+'</a><br>'; 
                else
                		favprint += '<a href="#" onclick="showitem('+cprall[i]+');">'+items[cprall[i]]["client"]+'_'+items[cprall[i]]['title']+'</a><br>'; 
		    }
}

        cprmenu += '<br><b>Previous work</b><br>'+cprmenu2;
		cprmenu += '<br><img src="/2005/matrix.php?weight=bold&value=+Archives"><br><a href="http://archive.3st.com/thirst_1999">Thirst 1998-1999</a><br><a href="http://archive.3st.com/thirst_2000">Thirst 2000-2002</a><br><br><br>';

cprmenu += '<br><img src="/2005/img/fav.gif" style="position: relative; top:-4px;"><img src="/2005/matrix.php?weight=bold&value=+Rick\'s+Favorites"><br>'+favprint;


    	for(var i=0;i<cwball.length;i++) { 
    	    if (items[cwball[i]]["newish"] == 1)
		        cwbmenu += '<a href="#" onclick="showitem('+cwball[i]+');">'+items[cwball[i]]["client"]+'_'+items[cwball[i]]['title']+'</a><br>'; 
            else
		        cwbmenu2 += '<a href="#" onclick="showitem('+cwball[i]+');">'+items[cwball[i]]["client"]+'_'+items[cwball[i]]['title']+'</a><br>';
		}

        cwbmenu += '<br><b>Previous work</b><br>'+cwbmenu2;

		cwbmenu += '<br><img src="/2005/matrix.php?weight=bold&value=+Archives"><br><a href="http://archive.3st.com/thirst_1999">Thirst 1998-1999</a><br><a href="http://archive.3st.com/thirst_2000">Thirst 2000-2002</a><br><br>';

       for(var i=0;i<cplall.length;i++) { 
	    if (items[cplall[i]]["newish"] == 1)
	        cplmenu += '<a href="#" onclick="showitem('+cplall[i]+');">'+items[cplall[i]]["client"]+'_'+items[cplall[i]]['title']+'</a><br>'; 
        else {
            if (items[cplall[i]]["favorite"]=='no')
            		cplmenu2 += '<a href="#" onclick="showitem('+cplall[i]+');">'+items[cplall[i]]["client"]+'_'+items[cplall[i]]['title']+'</a><br>'; 
            else
            		favprint += '<a href="#" onclick="showitem('+cplall[i]+');">'+items[cplall[i]]["client"]+'_'+items[cplall[i]]['title']+'</a><br>'; 
	    }
}

cplmenu += '<br><b>Previous work</b><br>'+cplmenu2;

		cplmenu += '<br><img src="/2005/matrix.php?weight=bold&value=+Archives"><br><a href="http://archive.3st.com/thirst_1999">Thirst 1998-1999</a><br><a href="http://archive.3st.com/thirst_2000">Thirst 2000-2002</a><br>';

cplmenu += '<br><img src="/2005/img/fav.gif" style="position: relative; top:-4px;"><img src="/2005/matrix.php?weight=bold&value=+Rick\'s+Favorites"><br>'+favplay;

fillarea = 0;
randallcnt = 0;

//alert(calcrows);

for(zz=0;zz<calcrows;zz++){
    document.getElementById('newrow'+(zz+1)).innerHTML = '<div id="newrow'+(zz+1)+'00"></div><div id="newrow'+(zz+1)+'01"></div><div id="newrow'+(zz+1)+'01"></div><div id="newrow'+(zz+1)+'02"></div><div id="newrow'+(zz+1)+'01"></div><div id="newrow'+(zz+1)+'03"></div><div id="newrow'+(zz+1)+'04"></div><div id="newrow'+(zz+1)+'05"></div><div id="newrow'+(zz+1)+'06"></div><div id="newrow'+(zz+1)+'07"></div><div id="newrow'+(zz+1)+'08"></div><div id="newrow'+(zz+1)+'09"></div><div id="newrow'+(zz+1)+'10"></div><div id="newrow'+(zz+1)+'11"></div><div id="newrow'+(zz+1)+'12"></div><div id="newrow'+(zz+1)+'13"></div><div id="newrow'+(zz+1)+'14"></div><div id="newrow'+(zz+1)+'15"></div><div id="newrow'+(zz+1)+'16"></div><div id="newrow'+(zz+1)+'17"></div><div id="newrow'+(zz+1)+'18"></div><div id="newrow'+(zz+1)+'19"></div><div id="newrow'+(zz+1)+'20"></div><div id="newrow'+(zz+1)+'21"></div><div id="newrow'+(zz+1)+'22"></div><div id="newrow'+(zz+1)+'23"></div><div id="newrow'+(zz+1)+'24"></div><div id="newrow'+(zz+1)+'25"></div><div id="newrow'+(zz+1)+'26"></div><div id="newrow'+(zz+1)+'27"></div><div id="newrow'+(zz+1)+'28"></div><div id="newrow'+(zz+1)+'29"></div><div id="newrow'+(zz+1)+'30"></div>';
document.getElementById('newrow'+(zz+1)+'00').nwidth = 0;    
}

tempje = 0;

//debuggah = '';
while (fillarea!=1){
    currentitem = items[randall[randallcnt]];
//alert(randall[randallcnt]);
    //alert(randall[randallcnt]+'_'+currentitem['client']+'_'+currentitem['title']);
//debuggah += randall[randallcnt]+"\n";

    currentimgs = currentitem['img'];
    randimg = Math.round(Math.random()*(currentimgs.length-1));
    if (randimg<0) randimg=0;
    if (randimg>currentimgs.length) randimg=currentimgs.length-1;
   // alert(currentimgs.length+'_'+randimg+'_'+currentitem['img'][randimg]);
    currentimg = currentitem['img'][randimg];
    currentwidth = currentitem['widths'][randimg];
    currentheight = currentitem['heights'][randimg];
    ratio = 144/currentheight;
    newwidth = Math.floor(ratio*currentwidth);

    startrow = findRow(calcrows, xc-16, newwidth);

    if (startrow=='STOP')
        fillarea = 1;
    else 
    {
        if (coldiv[startrow]<10)
             modif = '0';
         else
          modif = '';
    mover = 'newrow'+startrow+modif+coldiv[startrow];
    ele = xGetElementById(mover);
    xMoveTo(ele, colwidth[startrow], 10);
    document.getElementById('newrow'+startrow+modif+coldiv[startrow]).innerHTML = '<a href="#" onclick="showItemNew('+startrow+modif+coldiv[startrow]+'); return false;"><img src="/2005/resize_new.php?s=img/'+currentimg+'&w='+newwidth+'&h=144" width="'+newwidth+'" height="144" border="0" alt="" title="'+currentitem['client']+' '+currentitem['title']+'"></a>';
    document.getElementById('newrow'+startrow+modif+coldiv[startrow]).itemid = randall[randallcnt];
    document.getElementById('newrow'+startrow+modif+coldiv[startrow]).flag = currentitem['flag'];
    document.getElementById('newrow'+startrow+modif+coldiv[startrow]).nwidth = newwidth;
    document.getElementById('newrow'+startrow+modif+coldiv[startrow]).pos = colwidth[startrow];
    items[randall[randallcnt]]['onscreen'] = 1;
    items[randall[randallcnt]]['rpos'] = startrow+modif+coldiv[startrow];
    coldiv[startrow]++;
    colwidth[startrow] += newwidth; 
        
    randallcnt++;
    }
}
    //alert(debuggah);
}
