// Last updated September 11, 2009 6:30pm - AB 
//
/* ------------		Row Constructor  (See below for other GALLERY SCRIPTS) 	-------------*/


var gr = new Array();

addEvent(window,'load',loadgallery);

function loadgallery(e) {
	window.name = 'mdsgallery';
}


function MakeGalleryThumbRows(numRows)
{
//	alert("make constructor"+numRows);
	for (var i = 0; i < numRows; i++) {
		gr[i] = new rowConstructor(i);
	}
}



function rowConstructor(id)
{
	/* define properties */
	this.ID            = 'thumbrow'+id; // the Current row ID
	this.timerID       = -1; // the Current Menu's Delay timer
	this.isExpanded = false; // the Current Menu's Display Status
	this.numCells	= 0;
	this.name		= name;
	
	this.ii	= new Array(); //ids for each table cell within
	this.w		= new Array(); //std width for each table cell within
	this.h		= new Array(); //std ht for each table cell within
	this.path		= new Array();
	this.tbpath	= new Array();
	this.bigw		= new Array();
	this.bigh		= new Array();
	
	/* define methods */
	this.updaterowcells = update_rowcells;
	this.test		= testalertii;
	this.insertcell	= insert_cell;
	this.testreturnall	= returnall;

	return this;
}

function returnall() {

	var xx = 'ID ' + this.ID + ' \n timerID: ' + this.timerID + ' \n isExpanded: ' + this.isExpanded + ' \n numCells: ' + this.numCells + ' \n name:' +
		this.name + ' \n ii: (' + this.ii.join(',') + ') \n w: (' +
		this.w.join(',') + ') \n h: (' +
		this.h.join(',') + ') \n bigw: (' +
		this.bigw.join(',') + ') \n bigh: (' +
		this.bigh.join(',') + ') \n path: (' +
		this.path.join(',') + ') \n tbpath: (' +
		this.tbpath.join(',') + ' \n';
	alert(xx);
}

function update_rowcells(ids,w,h,wbig,hbig,truew,trueh,paths,tbpaths,maxrowht) 
{
	//ARRAYS
	this.ii 	= ids; 
	this.w			= w; //std width for each table cell within
	this.h			= h; //std ht for each table cell within
	this.bigw		= wbig;
	this.bigh		= hbig;
	this.path		= paths;
	this.tbpath		= tbpaths;
	this.numCells	= ids.length;
	
	this.truew		= truew;
	this.trueh		= trueh;

	//SINGLE VARIABLES
	this.maxrowht	= maxrowht;
}

function insert_cell (row,ids,w,h,wbig,hbig,path,tbpath) {
	this.ii.push(ids);
	this.w.push(w);
	this.h.push(h);
	this.bigw.push(wbig);
	this.bigh.push(hbig);
	this.path.push(path);
	this.tbpath.push(tbpath);
	
	this.numCells++;
}

function testalertii() {
	var strng = '';
	for (i=0; i < this.numCells; i++) {
		strng = strng + i + '. (' + this.ii[i] + ')    \n';
	}
	alert(strng);
}


/* //--------------------------------------------------------------------------------------// JavaScript Document */

/*

											if (gr[r].ii[i] > 0) {
												var thumbht = ((gr[r].h[i]/gr[r].w[i])*(gr[r].w[i]-smallwdiff));
												var tcellname = \"t_cell\"+i+gr[r].ii[i];
												$(tcellname).setAttribute(\"style\",\"height: ".($rowht)."px; width: "
													.($cellw-$small_w_diff)."px; left: \"+leftpos+\"px; ".$tcell_style."\");
													
												var imageframename = \"image_frame\"+gr[r].ii[i];
												
												$(imageframename).setAttribute(\"style\",\"width: \"+gr[r].w[i]+framemargin-smallwdiff+\"px; height: \"+(thumbht+framemargin)+\"px; ".$imageframesstyle."  \");
												
												var thumbname = \"thumb\"+gr[r].ii[i];
												$(thumbname).setAttribute(\"style\",\"height: \"+thumbht+\"px; width: \"+(gr[r].w[i]-smallwdiff)+\"px; ".$imagestyle."\");	
											} /* END make sure gr[r].ii[i] is greater than zero. We inserted a blank to make an array > 1 
*/	


function setCellSize(r , i , smallwdiff , framemargin , leftpos , cellw , maxrowht , tcellstyle , imageframestyle , imagestyle) {
	if (gr[r].ii[i] > 0) {
		var thumbht = ((gr[r].h[i]/gr[r].w[i])*(gr[r].w[i]-smallwdiff));
		var tcellname = "t_cell"+i+gr[r].ii[i];
		
		
//		$(tcellname).setAttribute("style","height: "+maxrowht+"px; width: "+(cellw-smallwdiff)+"px; left: "+leftpos+"px; " + tcellstyle + " ");
		setAstyle($(tcellname),"height: "+maxrowht+"px; width: "+(cellw-smallwdiff)+"px; left: "+leftpos+"px; " + tcellstyle + " ");			
		var imageframename = "image_frame"+gr[r].ii[i];
		
/* 		$(imageframename).setAttribute("style","width: "+gr[r].w[i]+framemargin-smallwdiff+"px; height: "+(thumbht+framemargin)+"px; "+ imageframestyle +"  "); */

		setAstyle($(imageframename),"width: "+gr[r].w[i]+framemargin-smallwdiff+"px; height: "+(thumbht+framemargin)+"px; "+ imageframestyle +"  ");
		
		var thumbname = "thumb"+gr[r].ii[i];
		setAstyle($(thumbname),"height: "+thumbht+"px; width: "+(gr[r].w[i]-smallwdiff)+"px; "+ imagestyle +" ");	
/*		$(thumbname).setAttribute('style',"height: "+thumbht+"px; width: "+(gr[r].w[i]-smallwdiff)+"px; "+ imagestyle +" ");			 */
	}
	
	/* END make sure gr[r].ii[i] is greater than zero. We inserted a blank to make an array > 1 */	
}

/*function resetCellSize(str) {
	alert(str);*/
function resetCellSize(r , smallwdiff , framemargin , leftpos , cellw , maxrowht , tcellstyle , imageframestyle , imagestyle) {
	for (i=0; i < gr[r].numCells; i++) {
		setCellSize(r , i , smallwdiff , framemargin , (leftpos*i) , cellw , maxrowht , tcellstyle , imageframestyle , imagestyle);
	}
}


var imageframestyle,imagestyle,tcellstyle;

function ss(r,smallwdiff,framemargin,partleftpos,cellw,mrowht) {
//	gr[r].isExpanded = false;
	if (document.getElementsByName('shift'+r)) {
		multipleSetByName('shift'+r,'class','show');
	}
	resetCellSize(r , smallwdiff , framemargin , partleftpos , cellw , mrowht , tcellstyle , imageframestyle , imagestyle);
	$('thumbrow'+r).style.height = 	(mrowht+2)+'px';
	rem_el("toolbox");	
}

function getStyleObjectz(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
	} else {
		return false;
	}
} 





/* ------------		GALLERY BROWSER 	--------------------- */


function end_browser() {
	rem_el("blankbg"); 
	rem_el("browser_underlay");
	return;
}

function end_browser_and_scroll(scrolltoID) {
	rem_el("blankbg"); 
	rem_el("browser_underlay");
	if ($(scrolltoID)) {
		ScrollToElement(scrolltoID);
	}
	return;
}


function new_upload_form(formnum,targetdiv) {
	//create new upload form to replace form on submit 
	//make_el_dom("div","show","",targetdiv,"upformdiv"+formnum);
	
	var upformd = document.createElement("div");
	$(targetdiv).appendChild(upformd);
	upformd.id = "upformdiv"+formnum+'';
	upformd.style.border ='1px solid green';
	
	make_el_dom("form","","","upformdiv"+formnum,"upform"+formnum);

	formEl = $("upform"+formnum);
	formEl.style.marginLeft = "1em";
	formEl.style.marginRight = "1em";
	formEl.name='uploadimages'+formnum;
	formEl.enctype = 'multipart/form-data';

	make_el_dom("p","para_medtxt"," ","upform"+formnum,"formp"+formnum);

	make_el_dom("div","para_medtxt graywriting","","upform"+formnum,"photo_browse"+formnum);
	
	
	var photo_browse = $('photo_browse'+formnum);
	photo_browse.style.border = "1px solid red";
	photo_browse.appendChild(document.createTextNode('Photo: '));
	
	var fileinp = document.createElement("input");
	fileinp.id = "file_browser"+formnum;
	fileinp.name = " photo"+formnum+"_filename[]";
	fileinp.type = "file";
	fileinp.onchange = function () {
						var formnum = $('formnumber').value;
						var whichcat = get_radio_value('which_catj');
						var ind = $('selcid').selectedIndex;
						var selectedcid = $('selcid').options[ind].value;
						var newformnum = (parseInt(formnum) + 1);
						new_upload_form(newformnum,'singleuploadf');
	fileUpload(this.form,'../galleryfiles/upload_image.php?formnumber='+formnum+'&which_cat='+whichcat+'&selectedcid='+selectedcid,'upload'+formnum);
						$('formnumber').value = newformnum;
						rem_el('photo_browse'+formnum);
	}
	$('photo_browse'+formnum).appendChild(fileinp);
	
	make_el_dom("div","para_medtxt"," ","upform"+formnum,"upload"+formnum);
	$('upload'+formnum).style.margin = "1em";

}
