// JavaScript Document



var window_width;
var window_height;

function get_window_size() {
	var win_w = parseInt(document.documentElement.clientWidth);
	var win_h = parseInt(document.documentElement.clientHeight);
		if (window.innerWidth) {
			win_w = parseInt(window.innerWidth);
		}
		if (window.innerHeight) {
			win_h = parseInt(window.innerHeight);
		}
	window_width = win_w;
	window_height = win_h;
}





var current_row = 0;
var current_item = 0;

var clicked_row = 0;
var clicked_item = 0;

var is_scrolling_vert = false;
var item_spacing = 20;
var nav_width = 216;

var row_height = 356;

var current_y = item_spacing;
var row_y = item_spacing;


var is_scrolling = false;




var IE = (window.navigator.userAgent.indexOf("MSIE")>-1)?true:false;
var IE6 = false;
if (IE) {
	var _ua = window.navigator.userAgent;
	var _msie = _ua.indexOf("MSIE");
	var _vMsie = _ua.substring(_msie+5, (_msie+8));
	IE6 = (IE && parseInt(_ua.substring(_msie+5, _msie+8)) >= 6) ? true : false; 
}

var section_rows = new Array();

function new_item() {
	this.title = null;
	this.extra = null;
	this.callout = null;
	this.content = null;
	this.media = null;
	this.item_width = 0;
	this.content_width = 0;
	this.item_height = 0;
}





function section_row() {
	this.row_id = null;
	this.items = new Array();
	this.local_current_item = 0;
	this.nav_text = "";
	this.scroll_y = 0;
	this.timeout = null;

//**** scroll left function
	this.scrollRowLeft = function() {
	var total_x = 0;
		if (this.items[this.local_current_item+1] != null) {
			total_x = this.items[this.local_current_item].item_width + item_spacing;
			// not my comment //if (this.local_current_item == 0) total_x+=2;
			scrollLeft(this.row_id, total_x);
			this.local_current_item++;
		} else {
			//items.length
			for (i=0; i<this.visible_items-1; i++) {
			total_x += this.items[i].item_width + item_spacing;
			}
		scrollRight(this.row_id, total_x);
		this.local_current_item = 0;
		}
	}

//**** scroll right function
	this.scrollRowRight = function() {
	var total_x = 0;
		if (this.local_current_item > 0) {
		this.local_current_item--;
		total_x = this.items[this.local_current_item].item_width + item_spacing;
		scrollRight(this.row_id, total_x);
		} else {
			//items.length
			for (i=0; i<this.visible_items-1; i++) {
			total_x += this.items[i].item_width + item_spacing;
			}
		scrollLeft(this.row_id, total_x);
		//items.length
		this.local_current_item = this.visible_items-1;
		}
	}




//**** scroll to here function
	this.scrollToHere = function(item_num) {
		var total_x = 0;
		if (row_positions[this.id][0] < item_num) {
			for (i=row_positions[this.id][0];i<item_num;i++) {
			total_x += section_rows[this.id].items[i].item_width+item_spacing;
			}
		} else {
			for (i=item_num;i<row_positions[this.id][0];i++) {
			total_x += section_rows[this.id].items[i].item_width+item_spacing;
			}
		}
		if (row_positions[this.id][0] < clicked_item) {
		scrollLeft(this.row_id, total_x);
		} else if (row_positions[this.id][0] != clicked_item){
		scrollRight(this.row_id, total_x);
		} else {
			show_hide_mask(clicked_row+'.'+clicked_item);
		}
	}

}






function slideRowLeft(rowIndex) {
	section_rows[rowIndex].scrollRowLeft();
}


function slideRowRight(rowIndex) {
	section_rows[rowIndex].scrollRowRight();
}


function slideRowToHere(rowIndex,item_num) {
	section_rows[rowIndex].scrollToHere(item_num);
}


function scrollLeft(divID, total_x) {
	is_scrolling = true;
	var obj = document.getElementById(divID);
	var x = parseInt(obj.style.left);
	var delta = 0;
	if (total_x > 3) {
		delta = Math.floor(total_x/3);
	} else {
		delta = 1;
	}

	obj.style.left = x - delta + "px";
	total_x -= delta;
	if (total_x > 0) {
		setTimeout('scrollLeft("'+divID+'", '+total_x+')', 50);
	} else {
	var main_x = parseInt(obj.scrollLeft);
	if (main_x > 0) {
		scrollMainLeft();
	}
	show_hide_subheader();
	show_hide_mask(clicked_row+'.'+clicked_item);
	items_on(clicked_row,clicked_item);
	is_scrolling = false;
	}
}


function scrollRight(divID, total_x) {
	is_scrolling = true;
	var obj = document.getElementById(divID);
	var x = parseInt(obj.style.left);
	var delta = 0;
	if (total_x > 3) {
		delta = Math.floor(total_x/3);
	} else {
		delta = 1;
	}

	obj.style.left = x + delta + "px";
	total_x -= delta;
	if (total_x > 0) {
		setTimeout('scrollRight("'+divID+'", '+total_x+')', 50);
	} else {
	var main_x = parseInt(obj.scrollLeft);
	if (main_x > 0) {
		scrollMainLeft();
	}
	show_hide_subheader();
	show_hide_mask(clicked_row+'.'+clicked_item);
	items_on(clicked_row,clicked_item);
	is_scrolling = false;
	}
}




function scrollMainUp(total_y, func) {
	var obj = document.getElementById("div_row_container");
	var y = parseInt(obj.scrollTop);
	var delta = 0;
	if (total_y > 3)
		delta = Math.floor(total_y/3);
	else
		delta = 1;
	obj.scrollTop = y - delta;
	total_y -= delta;
	if (total_y > 0) {
		setTimeout('scrollMainUp('+total_y+', "'+func+'")', 50);
	} else {
	var obj = document.getElementById("div_row_container");
	var x = parseInt(obj.scrollLeft);
	if (x > 0) {
		scrollMainLeft(func);
	} else {
		eval(func);
		is_scrolling = false;
	}
	}
}

function scrollMainDown(total_y, func) {
	var obj = document.getElementById("div_row_container");
	var y = parseInt(obj.scrollTop);
	var delta = 0;
	if (total_y > 3) {
		delta = Math.floor(total_y/3);
	} else {
		delta = 1;
	}

	obj.scrollTop = y + delta;
	total_y -= delta;
	if (total_y > 0) {
		setTimeout('scrollMainDown('+total_y+', "'+func+'")', 50);
	} else {
	var obj = document.getElementById("div_row_container");
	var x = parseInt(obj.scrollLeft);
	if (x > 0) {
		scrollMainLeft(func);
	} else {
		eval(func);
		is_scrolling = false;
	}
	}
}


function scrollMainLeft() {
	var obj = document.getElementById("div_row_container");
	var x = parseInt(obj.scrollLeft);
	var delta = 0;
	if (x > 3)
		delta = Math.floor(x/3);
	else
		delta = 1;
	obj.scrollLeft = x - delta;
	x -= delta;
	if (x > 0) {
		setTimeout('scrollMainLeft('+x+')', 50);
	} else {
		eval(func);
		is_scrolling = false;
	}
}


function scroll_into_view(rowIndex, func) {
    var scroll_height = parseInt(document.getElementById("div_row_container").scrollHeight);
    var div_height = parseInt(document.getElementById("div_row_container").style.height);
    var current_y = parseInt(document.getElementById("div_row_container").scrollTop);
    var max_y = scroll_height - div_height+20;
    var row_y = section_rows[rowIndex].scroll_y;
	if (row_y > current_y) {
		if (row_y < max_y) {
			scrollMainDown(row_y - current_y, func);
		} else if (current_y < max_y) {
			scrollMainDown(max_y - current_y, func);
		} else {
			eval(func);
		}
	} else {
		scrollMainUp(current_y - row_y, func);
	}
}























var row_positions = new Array();

function make_row_positions_array(pos,id,subid) {
	for (i=0;i<section_rows.length;i++) {
		row_positions[i] = new Array();
		row_positions[i][0] = pos; // pos
		row_positions[i][1] = id; // id
		row_positions[i][2] = subid; // subid
	}
}




//////////////////////////////////////////////////////////////////////
// first


var is_first = true;

function get_first() {
first_row = 0;
first_item = section_rows[0].items[0].entry_id;
sub_id = null;
//alert(first_item);
//	hide_div('div_row1_section_subheader0');
//	hide_div('div_row3_section_subheader0');

	if (get_first_page) {
		page_info_array = get_first_page.split('.');
		first_row = page_info_array[0];
		first_item = page_info_array[1];
		sub_id = (page_info_array[2]) ? page_info_array[2] : null;
		//alert(first_row+','+first_item+','+sub_id);
	}

	make_row_positions_array(first_row,first_item,sub_id);
	show_item(first_row,first_item,sub_id);

	for (k=0; k<section_rows.length; k++) { 
	//items.length
		for (j=0; j<section_rows[k].visible_items; j++) {
		show_hide_div("div_row_content_container"+k+'.'+j);
		}
	}
	document.getElementById("div_row_section_header"+first_row).className = "div_row_section_header";
}




//////////////////////////////////////////////////////////////////////
// show item


// from nav

function show_item_nav(row_num,item_num,subitem_num) {

	for(i=0;i<section_rows[row_num].items.length;i++) {
	if (subitem_num) {
			if (section_rows[row_num].items[i].subsection_id == subitem_num && section_rows[row_num].items[i].item_position == item_num) {
			item_id = section_rows[row_num].items[i].entry_id;
			}
		} else {
			if (section_rows[row_num].items[i].item_position == item_num) {
			item_id = section_rows[row_num].items[i].entry_id;
			}
		}
	}


	if (item_num && item_num >= 0) {
	show_item(row_num,item_id,subitem_num);

	// writing static header
		if (row_num == 1) {
				
			if (item_num == 0) {
				document.getElementById("link_row_section_header1").innerHTML = writing_subs[0][1].toLowerCase();
			} else if (item_num == writing_subs[1][2]) {
				document.getElementById("link_row_section_header1").innerHTML = writing_subs[1][1].toLowerCase();
			} else if (item_num == writing_subs[2][2]) {
				document.getElementById("link_row_section_header1").innerHTML = writing_subs[2][1].toLowerCase();
			}

		}

		// press static header
		if (row_num == 3) {
			if (item_num == 0) {
				document.getElementById("link_row_section_header3").innerHTML = press_subs[0][1].toLowerCase();
			} else if (item_num == press_subs[1][2]) {
				document.getElementById("link_row_section_header3").innerHTML = press_subs[1][1].toLowerCase();
			} else if (item_num == press_subs[2][2]) {
				document.getElementById("link_row_section_header3").innerHTML = press_subs[2][1].toLowerCase();
			}
		}

	// no sub
	} else {
	show_item(row_num,section_rows[row_num].items[0].entry_id);
	}
}



// from header click

function show_item_header(row_num) {
show_item(row_num,row_positions[row_num][1],row_positions[row_num][2]);
}



// all

function get_position(row_num,item_id,subitem_num) {
	for(i=0;i<section_rows[row_num].items.length;i++) {
	if (subitem_num) {
			if (section_rows[row_num].items[i].subsection_id == subitem_num && section_rows[row_num].items[i].entry_id == item_id) {
			item_num = section_rows[row_num].items[i].item_position;
			}
		} else {
			if (section_rows[row_num].items[i].entry_id == item_id) {
			item_num = section_rows[row_num].items[i].item_position;
			}
		}
	}
	return item_num;
}

function show_item(row_num,item_id,subitem_num) {
	
	item_num = get_position(row_num,item_id,subitem_num);

	// stop all movies
	if (!is_first) {
		stop_movies();
	}

	// does item exist
	if (!document.getElementById('div_row'+row_num+'_item'+item_num)) {
		if (current_row != row_num && current_item != 0) {
		show_item(row_num,0);
		} else {
			return false;
		}
	}

	var selfclick = (item_num == row_positions[row_num][1] && row_num == current_row) ? true : false;

	if ((!selfclick || is_first) && !is_scrolling) {
	
	is_scrolling = true;
	
	show_hide_div("div_row_content_container_off"+current_row+'.'+current_item);
	
	clicked_row = row_num;
	clicked_item = item_num;
	items_off(row_num,item_num);

	// content arrows
	
	var current_cols_num = section_rows[current_row].items[current_item]['columns'];
//console.log("current: " + current_cols_num);
		if (current_cols_num > cols_max) {
		hide_div("div_more_arrow"+current_row+"."+current_item);
		hide_div("div_back_arrow"+current_row+"."+current_item);
		}


	// reset content divs
	reset_content_divs();

//items.length
	if (item_num >= section_rows[row_num].visible_items) {
		show_item(row_num,0);
		return false;
	}


	
	// writing
	if (row_num == 1) {
	var writing_length = writing_subs.length;
		if (writing_length > 2) {
			if (item_num < writing_subs[1][2]) {
			show_hide_subnav(1,0);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[0][1].toLowerCase();
			} else if (item_num >= writing_subs[1][2] && (item_num < writing_subs[2][2] || !writing_subs[2][2])) {
			show_hide_subnav(1,1);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[1][1].toLowerCase();
			} else if (writing_subs[2][2] && item_num >= writing_subs[2][2]) {
			show_hide_subnav(1,2);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[2][1].toLowerCase();
			}
		} else if (writing_length < 2) {
			show_hide_subnav(1,0);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[0][1].toLowerCase();
		} else {
			if (item_num < writing_subs[1][2]) {
			show_hide_subnav(1,0);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[0][1].toLowerCase();
			} else if (item_num >= writing_subs[1][2]) {
			show_hide_subnav(1,1);
			document.getElementById("link_row_section_header1").innerHTML = writing_subs[1][1].toLowerCase();
			}
		}

	} else 	if (row_num == 3) {

	var press_length = press_subs.length;
		if (press_length > 2) {
			if (item_num < press_subs[1][2]) {
			show_hide_subnav(3,0);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[0][1].toLowerCase();
			} else if (item_num >= press_subs[1][2] && (item_num < press_subs[2][2] || !press_subs[2][2])) {
			show_hide_subnav(3,1);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[1][1].toLowerCase();
			} else if (press_subs[2][2] && item_num >= press_subs[2][2]) {
			show_hide_subnav(3,2);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[2][1].toLowerCase();
			}
		} else if (press_length < 2) {
			show_hide_subnav(3,0);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[0][1].toLowerCase();
		} else {
			if (item_num < press_subs[1][2]) {
			show_hide_subnav(3,0);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[0][1].toLowerCase();
			} else if (item_num >= press_subs[1][2]) {
			show_hide_subnav(3,1);
			document.getElementById("link_row_section_header3").innerHTML = press_subs[1][1].toLowerCase();
			}
		}



	} else 	if (row_num == 0) {

    	var blog_length = blog_subs.length;
			if (item_num < blog_subs[1][2]) {
			document.getElementById("link_row_section_header0").innerHTML = blog_subs[0][1].toLowerCase();
			} else if (item_num >= blog_subs[1][2]) {
			document.getElementById("link_row_section_header0").innerHTML = blog_subs[1][1].toLowerCase();
			}



    } else {

		show_hide_subnav(row_num,item_num);
	}
	
	hilight_nav(row_num);
	
	
	func = "set_current("+row_num+","+item_id+","+subitem_num+")";
	scroll_into_view(row_num,func);

	is_first = false;
	
	}
}





function set_current(row_num,item_id,subitem_num) {
	item_num = get_position(row_num,item_id,subitem_num);
	if (get_first_page) {
	alert(row_num+','+item_num+','+subitem_num);
	}

	if (section_rows[row_num].items[item_num]['media'] && (section_rows[row_num].items[item_num]['media_type'] == 'gif' || section_rows[row_num].items[item_num]['media_type'] == 'jpg')) {
		document.images['entry_img'+row_num+'.'+item_num].src = media_path+section_rows[row_num].items[item_num]['media'];
	}

	slideRowToHere(row_num,item_num);
	current_row = row_num;
	current_item = item_num;
	row_positions[row_num][0] = item_num;
	row_positions[row_num][1] = item_id;
	row_positions[row_num][2] = subitem_num;
	
	if (!is_scrolling) {
	show_hide_mask(row_num+'.'+item_num);
	}
document.getElementById("link_row_section_header"+row_num).className = "link_row_section_header";
	items_on(row_num,item_num);


// writing
	if (current_row == 1) {
		for(i=0;i<writing_subs.length;i++) {
		show_div('div_row1_section_subheader'+i);
		}
	}

// press
	if (current_row == 3) {
		for(i=0;i<press_subs.length;i++) {
		show_div('div_row3_section_subheader'+i);
		}
	}

/*	if (current_row == 3) {
	show_div('div_row3_section_subheader0');
	show_div('div_row3_section_subheader'+press_subs[1][1]);
	show_div('div_row3_section_subheader'+press_subs[2][1]);
	}
*/	
	// content arrows
	var cols_num = section_rows[row_num].items[item_num]['columns'];
	if (cols_num > cols_max) {
	show_div("div_more_arrow"+row_num+"."+item_num);
	//show_div("div_back_arrow"+row_num+"."+item_num);
	}
}


function show_hide_subheader() {

/*if (current_row == 1) {
	if (current_item < writing_subs[1][2]) {
		hide_div('div_row1_section_subheader0');
	} else if (item_num >= writing_subs[1][2] && (item_num < writing_subs[2][2] || !writing_subs[2][2])) {
		hide_div('div_row1_section_subheader'+writing_subs[1][1]);
	} else if (writing_subs[2][2] && item_num >= writing_subs[2][2]) {
		hide_div('div_row1_section_subheader'+writing_subs[2][1]);
	}
}

*/

if (current_row == 1) {
	var writing_length = writing_subs.length;

	if (writing_length > 2) {
		if (current_item < writing_subs[1][2]) {
			hide_div('div_row1_section_subheader0');
		} else if (current_item >= writing_subs[1][2] && current_item < writing_subs[2][2]) {
			hide_div('div_row1_section_subheader1');
		} else if (current_item >= writing_subs[2][2]) {
			hide_div('div_row1_section_subheader2');
		}
	} else if (writing_length < 2) {
		hide_div('div_row1_section_subheader0');
	} else {
		if (current_item < writing_subs[1][2]) {
			hide_div('div_row1_section_subheader0');
		} else if (current_item >= writing_subs[1][2]) {
			hide_div('div_row1_section_subheader1');
		}
	}
}



if (current_row == 3) {
	var press_length = press_subs.length;

	if (press_length > 2) {
		if (current_item < press_subs[1][2]) {
			hide_div('div_row3_section_subheader0');
		} else if (current_item >= press_subs[1][2] && current_item < press_subs[2][2]) {
			hide_div('div_row3_section_subheader1');
		} else if (current_item >= press_subs[2][2]) {
			hide_div('div_row3_section_subheader2');
		}
	} else if (press_length < 2) {
		hide_div('div_row3_section_subheader0');
	} else {
		if (current_item < press_subs[1][2]) {
			hide_div('div_row3_section_subheader0');
		} else if (current_item >= press_subs[1][2]) {
			hide_div('div_row3_section_subheader1');
		}
	}
}



/*	if (current_row == 3) {
		if (current_item == 0) {
			hide_div('div_row3_section_subheader0');
		} else if (current_item >= press_subs[1][1] && current_item < press_subs[2][1]) {
			hide_div('div_row3_section_subheader'+press_subs[1][1]);
		} else if (current_item >= press_subs[2][1]) {
			hide_div('div_row3_section_subheader'+press_subs[2][1]);
		}
	}
*/
}




function items_off(row_num,item_num) {
	var divs = new Array('div_row_content_title','div_row_content_extra','link_row_content_title','link_row_content_extra');
	for (k=0; k<section_rows.length; k++) { 
	//items.length
		for (j=0; j<section_rows[k].visible_items; j++) {
			for (i=0;i<divs.length;i++) {
			document.getElementById(divs[i]+k+'.'+j).className = divs[i]+"_off";
			}
			if (j>0) {
			document.getElementById("arrow-l"+k+'.'+j).src = "/img/common/arrows/arrow-l.gif";
			}
			//items.length
			if (j<section_rows[k].visible_items-1) {
			document.getElementById("arrow-r"+k+'.'+j).src = "/img/common/arrows/arrow-r.gif";
			}
		}
//		document.getElementById("div_row_section_header"+k).className = "div_row_section_header_off";
		if (k != clicked_row) {
			document.getElementById("link_row_section_header"+k).className = "link_row_section_header_off";
		}
	}
}


function items_on(row_num,item_num) {
	document.getElementById("div_row_content_title"+row_num+'.'+item_num).className = "div_row_content_title";
	document.getElementById("div_row_content_extra"+row_num+'.'+item_num).className = "div_row_content_extra";
	document.getElementById("link_row_content_title"+row_num+'.'+item_num).className = "link_row_content_title";
	document.getElementById("link_row_content_extra"+row_num+'.'+item_num).className = "link_row_content_extra";

	//document.getElementById("link_row_section_header"+row_num).className = "link_row_section_header";

	if (item_num>0) {
	document.getElementById("arrow-l"+row_num+'.'+item_num).src = "/img/common/arrows/arrow-l-on.gif";
	}
	//items.length
	if (item_num<section_rows[row_num].visible_items-1) {
	document.getElementById("arrow-r"+row_num+'.'+item_num).src = "/img/common/arrows/arrow-r-on.gif";
	}
}


function hilight_nav(nav_num) {
	for (i=0; i<section_rows.length; i++) { 
	document.getElementById("link_nav_main_item"+i).className = "link_nav_main";
	document.getElementById("div_row_section_header"+nav_num).className = "div_row_section_header_off";
	}

	for (i=0; i<section_rows.length; i++) { 
	//document.getElementById("link_nav_active_item"+i).className = "link_nav_active";
	document.getElementById("div_row_section_header"+nav_num).className = "div_row_section_header_off";
	}

	document.getElementById("link_nav_main_item"+nav_num).className = "link_nav_main_on";
	//document.getElementById("link_nav_active_item"+nav_num).className = "link_nav_active_on";
	document.getElementById("div_row_section_header"+nav_num).className = "div_row_section_header";
	
}



function show_hide_subnav(nav_num,item_num) {
	
	function highlight_sub(nav_num,sub_num) {
		for (i=0;i<writing_subs.length;i++) {
		document.getElementById("link_nav_main_writing_sub"+i).className = "link_nav_main_sub";
		//document.getElementById("link_nav_active_writing_sub"+i).className = "link_nav_active_sub";
/*		document.getElementById("link_nav_main_press_sub"+i).className = "link_nav_main_sub";
		document.getElementById("link_nav_active_press_sub"+i).className = "link_nav_active_sub";
*/		}
		for (i=0;i<press_subs.length;i++) {
		document.getElementById("link_nav_main_press_sub"+i).className = "link_nav_main_sub";
		}
		sub_item = (nav_num == 1) ? 'writing' : 'press';
		if (sub_num >= 0) {
			document.getElementById("link_nav_main_"+sub_item+"_sub"+sub_num).className = "link_nav_main_sub_on";
			//document.getElementById("link_nav_active_"+sub_item+"_sub"+sub_num).className = "link_nav_active_sub_on";
		}
	}

	highlight_sub(nav_num);
	// "writing" subnav
	if (nav_num == 1) {
		if (nav_num == 1 && current_row != 1) {
		hide_div("div_link_nav_main1");
		show_div("subnav_main1");
/*		hide_div("div_link_nav_main1");
		show_div("subnav_main1");*/
		show_div("div_link_nav_main3");
		hide_div("subnav_main3");
/*		show_div("div_link_nav_main3");
		hide_div("subnav_main3");*/
		highlight_sub(nav_num,item_num);
		} else 	if (nav_num == 1 && current_row == 1) {
		highlight_sub(nav_num,item_num);
		}
	} else {
	show_div("div_link_nav_main1");
	hide_div("subnav_main1");
/*	show_div("div_link_nav_main1");
	hide_div("subnav_main1");*/
	}
	



	// "press" subnav
	
	if (nav_num == 3) {
		if (nav_num == 3 && current_row != 3) {
		hide_div("div_link_nav_main3");
		show_div("subnav_main3");
/*		hide_div("div_link_nav_main3");
		show_div("subnav_main3");*/
		show_div("div_link_nav_main1");
		hide_div("subnav_main1");
/*		show_div("div_link_nav_main1");
		hide_div("subnav_main1");*/
		highlight_sub(nav_num,item_num);
		} else 	if (nav_num == 3 && current_row == 3) {
		highlight_sub(nav_num,item_num);
		}
	} else {
	show_div("div_link_nav_main3");
	hide_div("subnav_main3");
	show_div("div_link_nav_main3");
	hide_div("subnav_main3");
	}

}



function mouseover_subnav_writing() {
	show_div('subnav_main1');
	hide_div('div_link_nav_main1');
	hide_div('subnav_main3');
	show_div('div_link_nav_main3');
}


function mouseout_subnav_writing() {
	if (current_row == 1 || clicked_row == 1) {
	mouseover_subnav_writing();
	} else {
	hide_div('subnav_main1');
	show_div('div_link_nav_main1');
		if (current_row == 3) {
			show_div('subnav_main3');
			hide_div('div_link_nav_main3');
		} else {
			hide_div('subnav_main3');
			show_div('div_link_nav_main3');
		}
	}
}


function mouseover_subnav_press() {
	show_div('subnav_main3');
	hide_div('div_link_nav_main3');
	hide_div('subnav_main1');
	show_div('div_link_nav_main1');
}


function mouseout_subnav_press() {
	if (current_row == 3 || clicked_row == 3) {
	mouseover_subnav_press();
	} else {
	hide_div('subnav_main3');
	show_div('div_link_nav_main3');
		if (current_row == 3) {
		show_div('subnav_main1');
		hide_div('div_link_nav_main1');
		} else {
		hide_div('subnav_main1');
		show_div('div_link_nav_main1');
		}
	}
}









function show_hide_mask(item_num) {

	var divs = new Array('div_row_content_container_off_link','div_row_content_container_off');
	
	for (k=0; k<section_rows.length; k++) { 
	//items.length
		for (j=0; j<section_rows[k].visible_items; j++) {
			for (i=0;i<divs.length;i++) {
			div_name = divs[i]+k+'.'+j;
			var el = document.getElementById(div_name);
			el.style.display = "";
			el.style.zIndex = '100';
			}
		}
	}
	for (i=0;i<divs.length;i++) {
	div_name = divs[i]+item_num;
	var el = document.getElementById(div_name);
	el.style.display = "none";
	el.style.zIndex = "0";
	}
}



function show_hide_div(id,zindex) {
	var el = document.getElementById(id);
	if (el.style.display != "none") {
	el.style.display = "none";
		if (zindex) {
		el.style.zIndex = "0";
		}
	}
	else {
	el.style.display = "";
		if (zindex) {
		el.style.zIndex = zindex;
		}
	}
}


function show_div(id,zindex) {
	var el = document.getElementById(id);
	el.style.display = "";
}

function hide_div(id,zindex) {
	var el = document.getElementById(id);
	el.style.display = "none";
}




function position_quote() {
	var obj = document.getElementById("div_row_container");
	var x = parseInt(obj.scrollLeft);
	document.getElementById("div_quote").style.left = x + "px";
}




var current_content_div = 0;


function arrow_content(direction,row_num,item_num,content_num) {
	var cols = section_rows[row_num].items[item_num]['columns'];
	//var content_divs = 
	//div_row_content'+i+'.'+j+'.'+z'
	var divide_num = parseInt(cols/cols_max);
	var mod = cols % cols_max;
	var content_divs = (mod) ? divide_num+1 : divide_num;

	if (direction == "next" && current_content_div < content_divs) {
		show_div('div_row_content'+row_num+'.'+item_num+'.'+(current_content_div+1));
		hide_div('div_row_content'+row_num+'.'+item_num+'.'+current_content_div);
		show_div("div_back_arrow"+row_num+"."+item_num);
		if (current_content_div == (content_divs-2) || content_divs < 3) {
			hide_div("div_more_arrow"+row_num+"."+item_num);
		}			
		current_content_div++;
	} else if (direction == "back" && current_content_div > 0) {
		show_div('div_row_content'+row_num+'.'+item_num+'.'+(current_content_div-1));
		hide_div('div_row_content'+row_num+'.'+item_num+'.'+current_content_div);
		if (current_content_div == 1) {
			hide_div("div_back_arrow"+row_num+"."+item_num);
		}
		if (current_content_div <= content_divs) {
			show_div("div_more_arrow"+row_num+"."+item_num);
		}			
		current_content_div--;
	}
}


function reset_content_divs() {
	hide_div('div_row_content'+current_row+'.'+current_item+'.'+current_content_div);
	show_div('div_row_content'+current_row+'.'+current_item+'.0');
	current_content_div = 0;
}








function do_archive(row_num) {
	row_id = "div_row"+row_num;
	row_width = document.getElementById(row_id).style.width;
	row_width = parseInt(row_width.substring(0,(row_width.length-2)));
	row_width = row_width+292;
	document.getElementById(row_id).style.width = row_width+'px';
}


function write_archive(row_num) {
	//
	
//archive_html = '<div class="div_row_item_divider div_common"></div>';

var archive_html = '<div class="div_row_item_container div_common" style="width: 292px;">';

// extra item
archive_html += '<div class="div_row_content_extra_off" id="div_row_content_extra_archive'+row_num+'" style="width: 262px;"><a href="#" onclick="show_item(); return false;" class="link_row_content_extra" id="link_row_content_extra_archive'+row_num+'"> </a></div>';			

// title
archive_html += '<div class="div_row_content_title_off" id="div_row_content_title_archive'+row_num+'" style="width: 262px;"><a href="#" onclick="show_item(); return false;" class="link_row_content_title" id="link_row_content_title_archive'+row_num+'">ARCHIVE</a>';

archive_html += '</div>';

archive_html += '<div class="div_row_content_container" id="div_row_content_container_archive'+row_num+'" style="width: 292px;">';

archive_html += '<div class="div_row_content_archive" id="div_row_content_archive'+row_num+'0" style="width: 262px;">';

archive_html += '<a href="#" onclick="write_row('+row_num+',3,5); return false;" class="link_copy">older posts &gt;</a>';

archive_html += '</div>';

archive_html += '</div>';


/*// off state
archive_html += '<div id="div_row_content_container_off_preview" class="div_row_content_container_off" style="width: 262px;"><div class="div_row_content_off div_common"><div class="link_entry_quote" id="link_1">&#8220;test&#8221;</div></div></div>';

// link
archive_html += '<div id="div_row_content_container_off_link_preview" class="div_row_content_container_off_link" style="width: 262px;"><a href="#" onclick="show_archive(0); return false;" onmouseover="roll_link(\'yes\',\'1\');" onmouseout="roll_link(\'no\',\'1\');"><img src="img/common/x.gif" alt="" title="" width="262" height="269" border="0" /></a></div>';
*/
archive_html += '</div>';
return archive_html;
			
}























function write_row(row_num,begin_num,end_num) {
	
	
	var i = 0;
		var row_width = (190+item_spacing);
		
			for (j=begin_num; j<end_num; j++) {
			row_width += item_spacing + section_rows[i].items[j].item_width;
			}

			// first space
		var row_item_html = '<div class="div_row_item_first_space div_common"></div>';

			for (j=0; j<section_rows[i].visible_items; j++) {

			var item_width = section_rows[i].items[j]['item_width'];
			var title_width = section_rows[i].items[j]['title_width']-15; // minus indent
			var content_width = section_rows[i].items[j]['content_width'];
	
			// begin content item
			row_item_html += '<div id="div_row'+i+'_item'+j+'" class="div_row_item_container div_common" style="width: '+item_width+'px;">';
			
			
			
			
				if (section_rows[i].visible_items > 0) {
	
					// writing subheaders
					if (i == 1) {
						for(r=0;r<writing_subs.length;r++) {
							if (j == writing_subs[r][2]) {
							row_item_html += '<div id="div_row1_section_subheader'+r+'" class="div_row_section_subheader_off"><a href="#" onclick="show_item('+i+','+j+'); return false;">'+writing_subs[r][1].toLowerCase()+'</a></div>';
							}
						}
					}
					
	
	
	
					// press subheaders
					if (i == 3) {
						for(r=0;r<press_subs.length;r++) {
							if (j == press_subs[r][2]) {
							row_item_html += '<div id="div_row3_section_subheader'+r+'" class="div_row_section_subheader_off"><a href="#" onclick="show_item('+i+','+j+'); return false;">'+press_subs[r][1].toLowerCase()+'</a></div>';
							}
						}
					}
			
				}


			// extra item_width
			row_item_html += '<div id="div_row_content_extra'+i+'.'+j+'" class="div_row_content_extra_off" style="width: '+title_width+'px;"><a href="#" onclick="show_item('+i+','+j+'); return false;" id="link_row_content_extra'+i+'.'+j+'" class="link_row_content_extra_off">'+section_rows[i].items[j]['extra']+'</a></div>';
			
			// title
			row_item_html += '<div id="div_row_content_title'+i+'.'+j+'" class="div_row_content_title_off" style="width: '+title_width+'px;"><a href="#" onclick="show_item('+i+','+j+'); return false;" id="link_row_content_title'+i+'.'+j+'" class="link_row_content_title_off">'+section_rows[i].items[j]['title']+'</a>';
			
			// arrows
			row_item_html += '<div class="div_row_arrow" style="left: '+title_width+'px;">';
			
				if (j>0) {
					row_item_html += '<a href="#" onclick="show_item('+i+','+(j-1)+'); return false;"><img src="/img/common/arrows/arrow-l.gif" alt="" title="" border="0" id="arrow-l'+i+'.'+j+'" /></a>';
				}
			//items.length
				if (j<section_rows[i].visible_items-1) {
					row_item_html += '<a href="#" onclick="show_item('+i+','+(j+1)+'); return false;"><img src="/img/common/arrows/arrow-r.gif" alt="" title="" border="0" id="arrow-r'+i+'.'+j+'" style="margin-left: 3px;" /></a>';
				}
			
			row_item_html += '</div></div>';


			// content
			
			var content_array = section_rows[i].items[j]['content'].split('<x>');			
			var has_media = (section_rows[i].items[j]['media']) ? true : false;
			var total_content_items = content_array.length;
			var total_content_count = (has_media) ? total_content_items+1 : total_content_items;
			section_rows[i].items[j]['columns'] = total_content_count;
//			var total_content_items = (has_media) ? content_array.length+1 : content_array.length;
			
			row_item_html += '<div id="div_row_content_container'+i+'.'+j+'" class="div_row_content_container" style="display: none; width: '+content_width+'px;">';
			
			// next arrow

			var more_pos = (cols_max > 2) ? (cols_max*262)+((cols_max-2)*20) : cols_max*262;

				if (total_content_count > cols_max) {
					row_item_html += '<div id="div_more_arrow'+i+'.'+j+'" class="div_more_arrow" style="display: none; left: '+more_pos+'px;"><a href="#" onclick="arrow_content(\'next\','+i+','+j+'); return false;"><img src="/img/common/arrows/arrow-more.gif" alt="" title="" border="0"></a></div>';
//					row_item_html += '<div id="div_more_arrow'+i+'.'+j+'" class="div_more_arrow" style="display: none; left: '+more_pos+'px;"><a href="#" onclick="arrow_content(\'next\','+i+','+j+','+z+'); return false;"><img src="img/common/arrows/arrow-more.gif" alt="" title="" border="0"></a></div>';
				}
	
			// back arrow

				if (total_content_count > cols_max) {
					row_item_html += '<div id="div_back_arrow'+i+'.'+j+'" class="div_back_arrow" style="display: none;"><a href="#" onclick="arrow_content(\'back\','+i+','+j+'); return false;"><img src="/img/common/arrows/arrow-back.gif" alt="" title="" border="0"></a></div>';
				}
	
			row_item_html += '<div id="div_row_content'+i+'.'+j+'.0" class="div_row_content" style="width: '+content_width+'px;">';
			

				if (i == 2) {
					for(r=0;r<writing_subs.length;r++) {
						if (j == writing_subs[r][2]) {
						var subsection_id = writing_subs[r][3];
						}
					}
				}
			
			var div_point = cols_max;
			var media_placement = cols_max-2;
			
			var content_count = 0;
			
			for (z=0;z<total_content_items;z++) {	
			var this_content = content_array[z].replace(/\\'/g,"'"); // remove slash apostrophe
			row_item_html += this_content;

				if (has_media && ((total_content_count >= cols_max && content_count == media_placement) || (total_content_count < cols_max && content_count == (total_content_items-1)))) {
				var media_type = section_rows[i].items[j]['media_type'];
					// is movie
					if (media_type == "mov" || media_type == "mp4") {
					row_item_html += '<div id="player'+i+'.'+j+'.'+r+'" class="content_column_getflash">To view the associated movie, you will need to download the latest Flash Player plugin.<br><br> <a href="http://www.adobe.com/products/flashplayer/" target="_blank"><img src="/img/common/flashplayer.png" alt="" title="" border="0"></a></div>';
					place_movie(media_path+section_rows[i].items[j]['media'],section_rows[i].items[j]['media_height'],i+'.'+j+'.'+r);
						
					// is image
					} else {
						row_item_html += '<div class="content_column div_common"><img src="/img/common/x.gif" alt="" title="" border="0" class="img_row_media" name="entry_img'+i+'.'+j+'"></div>';
//						row_item_html += '<div class="content_column div_common"><img src="'+media_path+section_rows[i].items[j]['media']+'" alt="" title="" border="0" class="img_row_media" name="entry_img'+i+'.'+j+'"></div>';
					}
			content_count++;
				}

				
				if (total_content_count > cols_max && (parseInt((content_count+1)/div_point) == parseFloat((content_count+1)/div_point))) {
					row_item_html += '</div>';
					row_item_html += '<div id="div_row_content'+i+'.'+j+'.'+((content_count+1)/div_point)+'" class="div_row_content" style="width: '+content_width+'px; display: none;">';
				}


			content_count++;

			}
			row_item_html += '</div>';		
			row_item_html += '</div>';

			
			// off state
			row_item_html += '<div id="div_row_content_container_off'+i+'.'+j+'" class="div_row_content_container_off" style="width: '+item_width+'px;"><div class="div_row_content_off div_common"><div class="link_entry_quote" id="link_'+i+'.'+j+'">&#8220;'+section_rows[i].items[j]['off_quote']+'&#8221;</div></div></div>';

			// link
			row_item_html += '<div id="div_row_content_container_off_link'+i+'.'+j+'" class="div_row_content_container_off_link" style="width: '+item_width+'px;"><a href="#" onclick="show_item('+i+','+j+'); return false;" onmouseover="roll_link(\'yes\',\''+i+'.'+j+'\');" onmouseout="roll_link(\'no\',\''+i+'.'+j+'\');"><img src="/img/common/x.gif" alt="" title="" width="'+item_width+'" height="269" border="0" /></a></div>';
	
			row_item_html += '</div>';

			row_item_html += '<div class="div_row_item_divider div_common"></div>';
			
// archive
/*			if (j == 3) {
				archive_bit = write_archive();
				row_item_html += archive_bit;
				continue;
			}*/


			}


/*		var row_item_html = '<div class="div_row_item_first_space div_common"></div>';


			// begin content item
			row_item_html += '<div id="div_rowx" class="div_row_item_container div_common" style="width: 262px;"><div id="div_row_content_containerx" class="div_row_content_container" style="width: 262px;">test</div></div>';
*/

	show_item(0,0);
	document.getElementById("div_row0").innerHTML =  row_item_html;//div_row_html;
}




























var blog_row_width = 0;

var all_rows_height;


var item_limit = 102;


function init() {

//**** create main nav and row content

//**** main nav
	var nav_main_html = "";


//**** active nav
	//var nav_active_html = "";


	for (i=0; i<section_rows.length; i++) { 
	var section_id = section_rows[i].section_id;
//items.length


has_archive = ((section_id == '1' || section_id == '3') && section_rows[i].items.length > item_limit) ? true : false;
//items.length


var max_items = (has_archive) ? item_limit : section_rows[i].items.length;

/*
// horizontal scrolling positions // not used
		var previousMaxWidth = 0;
		section_rows[i].items[0].scroll_x = 0;
			for (var j=1; j<section_rows[i].items.length; j++) {
			section_rows[i].items[j].scroll_x = previousMaxWidth + section_rows[i].items[j-1]['item_width'] + item_spacing;
			}*/



//**** create nav items
		nav_main_html += '<div id="div_link_nav_main'+i+'" style="clear: both;">';
		nav_main_html += '<a class="link_nav_main" id="link_nav_main_item'+i+'" href="#" onclick="show_item_nav('+i+'); return false;">'+section_rows[i].nav_text+'</a></div>';

//**** create active nav items
//		nav_active_html += '<div id="div_link_nav_active'+i+'" style="clear: both;">';
//		nav_active_html += '<a class="link_nav_active" id="link_nav_active_item'+i+'" href="#" onclick="show_item_nav('+i+'); return false;">'+section_rows[i].nav_text+'</a></div>';

		// "writing" subnav
			if (section_id == 2) {
				nav_main_html += '<div class="div_common" id="subnav_main'+i+'" style="display: none;">';
				for (f=0;f<writing_subs.length;f++) {
					nav_main_html += '<a class="link_nav_main_sub" id="link_nav_main_writing_sub'+f+'" href="#" onclick="show_item_nav('+i+','+writing_subs[f][2]+','+writing_subs[f][3]+'); return false;">'+writing_subs[f][1]+"</a><br>";
				}
			nav_main_html += '</div>';
			}

		// "press" subnav
			if (section_id == 4) {
				nav_main_html += '<div class="div_common" id="subnav_main'+i+'" style="display: none;">';
				for (f=0;f<press_subs.length;f++) {
					nav_main_html += '<a class="link_nav_main_sub" id="link_nav_main_press_sub'+f+'" href="#" onclick="show_item_nav('+i+','+press_subs[f][2]+','+press_subs[f][3]+'); return false;">'+press_subs[f][1]+"</a><br>";
				}
			nav_main_html += '</div>';
			}



/*		// "writing" active subnav
			if (section_rows[i]['section_id'] == 2) {
				nav_active_html += '<div class="div_common" id="subnav_active'+i+'" style="display: none; width: 190px;">';
				for (f=0;f<writing_subs.length;f++) {
					nav_active_html += '<a class="link_nav_active_sub" id="link_nav_active_writing_sub'+f+'" href="#" onclick="show_item_nav('+i+','+writing_subs[f][2]+'); return false;">'+writing_subs[f][1]+"</a><br>";
				}
			nav_active_html += '</div>';
			}

		// "press" active subnav
			if (section_rows[i]['section_id'] == 4) {
				nav_active_html += '<div class="div_common" id="subnav_active'+i+'" style="display: none; width: 190px;"">';
				for (f=0;f<press_subs.length;f++) {
					nav_active_html += '<a class="link_nav_active_sub" id="link_nav_active_press_sub'+f+'" href="#" onclick="show_item_nav('+i+','+press_subs[f][2]+'); return false;">'+press_subs[f][1]+"</a><br>";
				}
			nav_active_html += '</div>';
			}
*/



	}








get_window_size();
var mid_point = parseInt((window_height/2) - (row_height/2) - 50); // half of row height minus header

all_rows_height = (section_rows.length) * (row_height+item_spacing);


//**** content

// quote
		var div_quote_html = '<div id="div_row_left"></div><div id="div_quote"><div class="div_name">Noah Hawley</div><div class="div_quote_text">'+main_quote+'</div></div>';
		
		var div_row_html = '';


	for (i=0; i<section_rows.length; i++) { 
	
	var row_id = section_rows[i].id;
	
		if (i > 0) {

//**** getting scroll position plus quote height

			var previousMaxHeight = section_rows[i-1].scroll_y;				

			if (i == 1) {
				section_rows[i].scroll_y = 266 + row_height + item_spacing - mid_point;
			} else {
				section_rows[i].scroll_y = row_height + previousMaxHeight + item_spacing;
			}
		}


//**** define the width of the row
		var row_width = (190+item_spacing);
		//items.length
			for (j=0; j<section_rows[i].visible_items; j++) {
			row_width += item_spacing + section_rows[i].items[j].item_width;
			}

		if (i == 0) {
			blog_row_width = row_width;
		}
		//row_width += 190;


//**** create the slide rows
		section_rows[i].row_id = "div_row" + i;
		
		
		var title_top = (i == 0) ? 286 : title_top += row_height+item_spacing;

//**** row header
		var row_item_html = '<div id="div_row_section_header'+i+'" class="div_row_section_header" style="top: '+title_top+'px;"><a href="#" onclick="show_item_header('+i+'); return false;" id="link_row_section_header'+i+'" class="link_row_section_header_off">'+section_rows[i]['header_text']+'</a></div>';

//**** begin row
		row_item_html += '<div id="div_row'+i+'" style="overflow: hidden; position: relative; float: left; clear: both; left: 0px; width: '+row_width+'px; height: '+row_height+'px; padding: 0px; margin-top: 20px; z-index: 1;">';

		//**** first space
		row_item_html += '<div class="div_row_item_first_space div_common"></div>';

	has_archive = ((section_rows[i].section_id == '1' || section_rows[i].section_id == '3') && section_rows[i].items.length > item_limit) ? true : false;

//items.length
			for (j=0;j<section_rows[i].visible_items;j++) {

			var item_width = section_rows[i].items[j]['item_width'];
			var title_width = section_rows[i].items[j]['title_width']-15; // minus indent
			var content_width = section_rows[i].items[j]['content_width'];
			var subid = (i == 1 || i == 3) ? section_rows[i].items[j]['subsection_id'] : null;

			// ::VS:: Changed to columnized data
    		//var content_array = section_rows[i].items[j]['content'].split('<x>');			
			// the one that works below
			//var content_array = document.getElementById("content"+[i]+"."+[j]).innerHTML.split('<x></x>');
			
			var content_array = document.getElementById(section_rows[i].items[j]['type']+"-"+section_rows[i].items[j]['entry_id']).innerHTML.split('<x></x>');
			
			content_array.pop();
			
			//section_rows[i].items[j]['off_quote'] = document.getElementById(section_rows[i].items[j]['type']+"-"+section_rows[i].items[j]['entry_id']+"-callout").innerHTML;
			//console.log(document.getElementById(section_rows[i].items[j]['type']+"-"+section_rows[i].items[j]['entry_id']+"-callout").innerHTML);
			
			var has_media = (section_rows[i].items[j]['media']) ? true : false;
			var total_content_items = content_array.length;
			var total_content_count = (has_media) ? total_content_items+1 : total_content_items;
			section_rows[i].items[j]['columns'] = total_content_count;
			
			//console.log(total_content_count);
			
			if( total_content_count == 2 ) {
			    content_width = section_rows[i].items[j]['content_width'] = item_width = section_rows[i].items[j]['item_width'] = 574;
			} else if ( total_content_count == 1 ) {
			    content_width = section_rows[i].items[j]['content_width'] = item_width = section_rows[i].items[j]['item_width'] = 292;
			}
			title_width = section_rows[i].items[j]['content_width']-61-15;

			// begin content item
			row_item_html += '<div id="div_row'+i+'_item'+j+'" class="div_row_item_container div_common" style="width: '+item_width+'px;">';
			
			
			
			
			// writing subheaders
			//items.length 
				if (section_rows[i].visible_items> 0) {

					// blog subheaders
					if (i == 0) {
						for(r=0;r<blog_subs.length;r++) {
							if (j == blog_subs[r][2]) {
							row_item_html += '<div id="div_row1_section_subheader'+r+'" class="div_row_section_subheader_off"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;">'+blog_subs[r][1].toLowerCase()+'</a></div>';
							}
						}
					}
	
					// writing subheaders
					if (i == 1) {
						for(r=0;r<writing_subs.length;r++) {
							if (j == writing_subs[r][2]) {
							row_item_html += '<div id="div_row1_section_subheader'+r+'" class="div_row_section_subheader_off"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;">'+writing_subs[r][1].toLowerCase()+'</a></div>';
							}
						}
					}
					
	
	
	
					// press subheaders
					if (i == 3) {
						for(r=0;r<press_subs.length;r++) {
							//alert(subid);
							if (j == press_subs[r][2]) {
							row_item_html += '<div id="div_row3_section_subheader'+r+'" class="div_row_section_subheader_off"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;">'+press_subs[r][1].toLowerCase()+'</a></div>';
							}
						}
					}
			
				}


			// extra
			row_item_html += '<div id="div_row_content_extra'+i+'.'+j+'" class="div_row_content_extra_off" style="width: '+title_width+'px;"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;" id="link_row_content_extra'+i+'.'+j+'" class="link_row_content_extra_off">'+section_rows[i].items[j]['extra']+'</a></div>';
			
			// title
			row_item_html += '<div id="div_row_content_title'+i+'.'+j+'" class="div_row_content_title_off" style="width: '+title_width+'px;"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;" id="link_row_content_title'+i+'.'+j+'" class="link_row_content_title_off">'+section_rows[i].items[j]['title']+'</a>';
			
			// arrows
			row_item_html += '<div class="div_row_arrow" style="left: '+title_width+'px;">';
			
				if (j>0) {
					row_item_html += '<a href="#" onclick="show_item('+i+','+section_rows[i].items[j-1]['entry_id']+'); return false;"><img src="/img/common/arrows/arrow-l.gif" alt="" title="" border="0" id="arrow-l'+i+'.'+j+'" /></a>';
				}
			//items.length
				if (j<section_rows[i].visible_items-1) {
					row_item_html += '<a href="#" onclick="show_item('+i+','+section_rows[i].items[j+1]['entry_id']+'); return false;"><img src="/img/common/arrows/arrow-r.gif" alt="" title="" border="0" id="arrow-r'+i+'.'+j+'" style="margin-left: 3px;" /></a>';
				}
			
			row_item_html += '</div></div>';


			// content
			

			
//			var total_content_items = (has_media) ? content_array.length+1 : content_array.length;
			
			
			row_item_html += '<div id="div_row_content_container'+i+'.'+j+'" class="div_row_content_container" style="display: none; width: '+content_width+'px;">';
			
			// next arrow

			var more_pos = (cols_max > 2) ? (cols_max*262)+((cols_max-2)*20) : cols_max*262;

				if (total_content_count > cols_max) {
					row_item_html += '<div id="div_more_arrow'+i+'.'+j+'" class="div_more_arrow" style="display: none; left: '+more_pos+'px;"><a href="#" onclick="arrow_content(\'next\','+i+','+j+'); return false;"><img src="/img/common/arrows/arrow-more.gif" alt="" title="" border="0"></a></div>';
//					row_item_html += '<div id="div_more_arrow'+i+'.'+j+'" class="div_more_arrow" style="display: none; left: '+more_pos+'px;"><a href="#" onclick="arrow_content(\'next\','+i+','+j+','+z+'); return false;"><img src="img/common/arrows/arrow-more.gif" alt="" title="" border="0"></a></div>';
				}
	
			// back arrow

				if (total_content_count > cols_max) {
					row_item_html += '<div id="div_back_arrow'+i+'.'+j+'" class="div_back_arrow" style="display: none;"><a href="#" onclick="arrow_content(\'back\','+i+','+j+'); return false;"><img src="/img/common/arrows/arrow-back.gif" alt="" title="" border="0"></a></div>';
				}
	
			row_item_html += '<div id="div_row_content'+i+'.'+j+'.0" class="div_row_content" style="width: '+content_width+'px;">';
			

				if (i == 2) {
					for(r=0;r<writing_subs.length;r++) {
						if (j == writing_subs[r][2]) {
						var subsection_id = writing_subs[r][3];
						}
					}
				}
			
			var div_point = cols_max;
			var media_placement = cols_max-2;
			
			var content_count = 0;
			
			for (z=0;z<total_content_items;z++) {	
			var this_content = content_array[z].replace(/\\'/g,"'"); // remove slash apostrophe
			row_item_html += this_content;

				if (has_media && ((total_content_count >= cols_max && content_count == media_placement) || (total_content_count < cols_max && content_count == (total_content_items-1)))) {
				var media_type = section_rows[i].items[j]['media_type'];
					// is movie
					if (media_type == "mov" || media_type == "mp4") {
					row_item_html += '<div id="player'+i+'.'+j+'.'+r+'" class="content_column_getflash">To view the associated movie, you will need to download the latest Flash Player plugin.<br><br> <a href="http://www.adobe.com/products/flashplayer/" target="_blank"><img src="/img/common/flashplayer.png" alt="" title="" border="0"></a></div>';
					place_movie(media_path+section_rows[i].items[j]['media'],section_rows[i].items[j]['media_height'],i+'.'+j+'.'+r);
						
					// is image
					} else {
						row_item_html += '<div class="content_column div_common"><img src="/img/common/x.gif" alt="" title="" border="0" class="img_row_media" name="entry_img'+i+'.'+j+'"></div>';
//						row_item_html += '<div class="content_column div_common"><img src="'+media_path+section_rows[i].items[j]['media']+'" alt="" title="" border="0" class="img_row_media" name="entry_img'+i+'.'+j+'"></div>';
					}
			content_count++;
				}

				
				if (total_content_count > cols_max && (parseInt((content_count+1)/div_point) == parseFloat((content_count+1)/div_point))) {
					row_item_html += '</div>';
					row_item_html += '<div id="div_row_content'+i+'.'+j+'.'+((content_count+1)/div_point)+'" class="div_row_content" style="width: '+content_width+'px; display: none;">';
				}


			content_count++;

			}
			row_item_html += '</div>';		
			row_item_html += '</div>';

			
			// off state
			row_item_html += '<div id="div_row_content_container_off'+i+'.'+j+'" class="div_row_content_container_off" style="width: '+item_width+'px;"><div class="div_row_content_off div_common"><div class="link_entry_quote" id="link_'+i+'.'+j+'">&#8220;'+section_rows[i].items[j]['off_quote']+'&#8221;</div></div></div>';

			// link
			row_item_html += '<div id="div_row_content_container_off_link'+i+'.'+j+'" class="div_row_content_container_off_link" style="width: '+item_width+'px;"><a href="#" onclick="show_item('+i+','+section_rows[i].items[j]['entry_id']+','+subid+'); return false;" onmouseover="roll_link(\'yes\',\''+i+'.'+j+'\');" onmouseout="roll_link(\'no\',\''+i+'.'+j+'\');"><img src="/img/common/x.gif" alt="" title="" width="'+item_width+'" height="269" border="0" /></a></div>';
	
			row_item_html += '</div>';

			row_item_html += '<div class="div_row_item_divider div_common"></div>';
			
// archive
/*			if (has_archive && j == item_limit-1) {
				archive_bit = write_archive();
				row_item_html += archive_bit;
			}*/


			}


		div_row_html += row_item_html+'</div>';

}

	div_row_html += '<div id="div_row_bottomspace" class="div_common"><br /></div>';
	
	div_row_html = div_quote_html + div_row_html;

	document.getElementById("div_row_container").innerHTML = div_row_html;
	document.getElementById("div_nav_main_items").innerHTML = nav_main_html;
	//document.getElementById("div_nav_active_items").innerHTML = nav_active_html;


}















var mov_array = new Array();
var mov_array_index = 0;

function place_movie(file_name,file_height,player_num) {
mov_array[mov_array_index] = new Array();
mov_array[mov_array_index]['name'] = file_name;
mov_array[mov_array_index]['height'] = file_height;
mov_array[mov_array_index]['num'] = player_num;
mov_array_index++;
}






function roll_link(is_hover,link_num) {
class_name = (is_hover == "yes") ? "link_entry_quote_roll" : "link_entry_quote";
document.getElementById("link_"+link_num).className = class_name;
}








function resize_main_div() {
	var win_w = parseInt(document.documentElement.clientWidth);
	var win_h = parseInt(document.documentElement.clientHeight);
		if (window.innerWidth) {
			win_w = parseInt(window.innerWidth);
		}
		if (window.innerHeight) {
			win_h = parseInt(window.innerHeight);
		}
		
	var half_win_h = win_h/2;
	var bottom_space = 20;
	
	if(IE6) {
	mainnav_position = win_w - nav_width - 17;
	quote_width = win_w - 240 - 17;
	} else {
	mainnav_position = win_w - nav_width;
	quote_width = win_w - 240;
	}
	document.getElementById("div_row_container").style.width = win_w + "px";	
	document.getElementById("div_row_container").style.height = win_h + "px";
	document.getElementById("div_quote").style.width = quote_width + "px";
	document.getElementById("div_nav_main").style.left = mainnav_position + "px";
	document.getElementById("div_nav_main_bgcolor").style.left = mainnav_position + "px";
	document.getElementById("div_row_bottomspace").style.height = bottom_space + "px";
	document.getElementById("div_row_left").style.height = all_rows_height + bottom_space+"px";
	if (window.navigator.userAgent.indexOf("Safari") > -1) {
		document.getElementById("div_nav_main").style.width = "200px";
		document.getElementById("div_nav_main_bgcolor").style.width = "200px";
	}
	
}



function browser_detect() {
	var msg = "This website works best with IE 6+, Firefox 2+, and Safari 3+. Please use one of these browsers for the best possible experience.";
	var show_alert = false;
	var userAgent = window.navigator.userAgent;
	if (userAgent.indexOf("Firefox") > -1) {
		var version = parseInt(userAgent.substring(userAgent.indexOf("Firefox/")+8));
		if (version < 2)
			show_alert = true;
	} else if (userAgent.indexOf("MSIE") > -1) {
		var version = parseInt(userAgent.substring(userAgent.indexOf("MSIE")+5));
		if (version < 6)
			show_alert = true;
	} else if (userAgent.indexOf("Safari") > -1) {
		var version = parseInt(userAgent.substring(userAgent.indexOf("Safari/")+7));
		if (version < 522)
			show_alert = true;
	} else {
		show_alert = true;
	}
	if (show_alert) {
		alert(msg);
	}
}








function id_nav() {
	if (IE) {
// writing
	document.getElementById("subnav_main1").attachEvent("onmouseover",mouseover_subnav_writing);
	document.getElementById("div_link_nav_main1").attachEvent("onmouseover",mouseover_subnav_writing);
	document.getElementById("subnav_main1").attachEvent("onmouseout",mouseout_subnav_writing);
	document.getElementById("div_link_nav_main1").attachEvent("onmouseout",mouseout_subnav_writing);

// press
	document.getElementById("subnav_main3").attachEvent("onmouseover",mouseover_subnav_press);
	document.getElementById("div_link_nav_main3").attachEvent("onmouseover",mouseover_subnav_press);
	document.getElementById("subnav_main3").attachEvent("onmouseout",mouseout_subnav_press);
	document.getElementById("div_link_nav_main3").attachEvent("onmouseout",mouseout_subnav_press);
	} else {
// writing
	document.getElementById("subnav_main1").addEventListener("mouseover",mouseover_subnav_writing,false);
	document.getElementById("div_link_nav_main1").addEventListener("mouseover",mouseover_subnav_writing,false);
	document.getElementById("subnav_main1").addEventListener("mouseout",mouseout_subnav_writing,false);
	document.getElementById("div_link_nav_main1").addEventListener("mouseout",mouseout_subnav_writing,false);

// press
	document.getElementById("subnav_main3").addEventListener("mouseover",mouseover_subnav_press,false);
	document.getElementById("div_link_nav_main3").addEventListener("mouseover",mouseover_subnav_press,false);
	document.getElementById("subnav_main3").addEventListener("mouseout",mouseout_subnav_press,false);
	document.getElementById("div_link_nav_main3").addEventListener("mouseout",mouseout_subnav_press,false);

	}
}




