function last_update() {
	document.title = 'Updated ' + last_update_date;
	document.getElementById('last_update').innerHTML = 'This page was last updated on ' + last_update_date + '.';
}

function avail_menu(selected_div) {
	var menu = '';
	var data = avail_menu_data;
	var div_id = 'avail_menu';
    the_menu_div = document.getElementById(div_id);
	var tab_bar_width = the_menu_div.clientWidth;
	var tab_width = Math.round(tab_bar_width/data.length) - 2;
	for(var i in data) {
		if(data[i][0] == selected_div) {
			menu += '<DIV STYLE="width:' + tab_width + 'px" ID=' + data[i][0] + ' CLASS="tab_item_selected">' + 
        	data[i][1] + '</DIV>\n';
		}
		else {
			menu += '<DIV STYLE="width:' + tab_width + 'px" ID=' + data[i][0] + ' CLASS=tab_item ' + 
			'onMouseOver="this.style.backgroundColor=\'#b0c4de\'" onMouseOut="this.style.backgroundColor=\'#fff\'"' +
        	' onClick="draw_dogs(\'available_saints\',\'' + data[i][0] + '\');return false;">' + data[i][1] +
			'</DIV>\n';
		}
	}
	document.getElementById(div_id).innerHTML = menu;
}

function draw_all_dogs() {
	var content = '';
	for (var i in all_avail) {
		content += draw_dogs('',all_avail[i]);
	}
	document.getElementById('available_saints').innerHTML = content;
}

function draw_dogs(div_id,menu_div_id) {
	if (menu_div_id == 'all_avail') {
		draw_all_dogs();
		avail_menu(menu_div_id);
		return false;
	}
	if(div_id != '') {
		avail_menu(menu_div_id);
	}
    var content = '';
	if (avail_intros[menu_div_id]) {
		content = '<DIV CLASS=page_text STYLE="font-weight:bold;width:99%"><B>' + avail_intros[menu_div_id] + '</B></DIV>\n';
	}
	for (var i in avail_list[menu_div_id]) {
		content += draw_dog(avail_list[menu_div_id][i]);
	}
	if (div_id) {
		document.getElementById(div_id).innerHTML = content;
	}
	else {
		return content;
	}
}

function light_avail_tab(new_tab_id) {
	try{
		if (selected_avail_menu_item) {
			document.getElementById(selected_avail_menu_item).className = 'tab_item';
		}
	}
	catch(err) {
		//
	}
	selected_avail_menu_item = new_tab_id;
	document.getElementById(new_tab_id).className = 'tab_item_selected';
}

function draw_dog(dog) {
	if(dog) {
    	var uppername = '';
		if(dog.match(/\./)){
			uppername = dog.toUpperCase();
		}
		else{
    		uppername = dog.substring(0,1).toUpperCase() + dog.substring(1);
		}
    	var string = '<DIV CLASS=href_frame onclick="javascript:show_dog(\'' + dog + '\');">\n' + 
                     '<DIV CLASS=pic>\n<IMG BORDER=0 SRC=foster_pics/th_' + dog + '.jpg ALT=' + uppername + 
                     '></A><BR>\n' + uppername + '<BR>' + dog_data[dog]['age'] +
                     '</DIV>\n<DIV CLASS=bio>' + dog_data[dog]['bio'] + '\n</DIV>\n<DIV CLASS=stats>\n' + 
					 '<SPAN CLASS=bold_blue><BR>Rescued:<BR>' + dog_data[dog]['received'] + '</SPAN>\n<BR><BR><BR><BR>' +
					 '<SPAN CLASS=bold_blue><B>Adoption Fee: ' + dog_data[dog]['fee'] + '</SPAN><BR>';
		if(dog_data[dog]['fosternotes']) {
			string += 'Foster Notes Available';
		}
		if(dog_data[dog]['adoptionpending']) {
			string += '<BR><SPAN STYLE="color:#f00">Adoption Pending</SPAN>';
		}
		return string + '<BR>\n</DIV>\n</DIV>\n';
	}
}

// div: 600h X 600w
//     film_strip - 400h
//     bio/foster_notes - 180
function show_dog(dog){
	var pic_count = 0;
	var pics = '';
	var strip_width = 0;
	for (var i in parent.foster_pics[dog]){
		pic_count++;
		var href = '<A HREF="foster_pics/' + foster_pics[dog][i] + '" TARGET="_blank">';
		pics += '<DIV ID="fsdiv' + i + '" STYLE="margin:10px;width:380px">' + href + '<IMG SRC="/foster_pics/fs_' + 
                 foster_pics[dog][i] + '" BORDER=0></A></DIV>';
		strip_width += 400;
	}
	if(pics == ''){
		pics = '<DIV ID=fsdiv0 STYLE="width:360px;text-align:center;vertical-align:middle">' + href + '<IMG SRC="foster_pics/' + 
                dog + '.jpg" BORDER=0></A></DIV>';
		strip_width = 350;
		pic_count = 1;
	}
	var fosternotes = '';
	if(dog_data[dog]['fosternotes'] == undefined){
		fosternotes = '';
	}
	else{
		fosternotes = '<SPAN COLOR="#cdcdcd"><FONT color=red>Foster Notes:</FONT></SPAN> ' + dog_data[dog]['fosternotes'];
	}
	var lmarg = 0;
	var fswidth = 590;
	if(pic_count == 1){
		lmarg = 90;
		fswidth = 500;
	}
   	var uppername = dog.substring(0,1).toUpperCase() + dog.substring(1);
	var infoline = '<DIV ID=dog_dtls STYLE="width:100%;height:25px;background-color:#b0c4de">' +
                   '<DIV CLASS=bio STYLE="width:70px">   ' + uppername + '</DIV>' +
                   '<DIV CLASS=bio STYLE="width:190px">Intake Date: ' + dog_data[dog]['received'] + '</DIV>' +
                   '<DIV CLASS=bio STYLE="width:170px">Age at Intake: ' + dog_data[dog]['age'] + '</DIV>' +
                   '<DIV CLASS=bio STYLE="width:140px">Adoption Fee: ' + dog_data[dog]['fee'] + '</DIV>' +
				   '</DIV>';
    var content = infoline +
                  '<DIV CLASS=filmstrip ID=dog_filmstrip STYLE="width:' + fswidth + 'px;height:380px;margin-left:' + lmarg + 
                  '"><DIV STYLE="width:' + strip_width + 'px">' + pics + '</DIV></DIV>' + 
                  '<DIV CLASS=bio STYLE="background-color:#b0c4de;height:170px;width:98%"><B>' +  
                   dog_data[dog]['bio'] + '</B><BR><BR>' + fosternotes + '</DIV>' + 
                  '<DIV STYLE="width:99%;text-align:center"><A HREF="javascript:hide_dog();">Return to List</A></DIV>';
	fade_swap('page','dynamic',20);
	pop_div('dynamic',600,600,content);
}

function hide_dog(dog){
	fade_swap('dynamic','page',20);
	toggle_div('dynamic','none');
}

