var thumb_grid_y=0;
var thumb_scroll_speed=0;
var acceleration=.03;
var max_speed=2;
var current_scroll_direction=null;
var scroll_interval=0;
var visible_height=300;
var up_arrow_state="normal";
var down_arrow_state="normal";

function check_is_ie_6(){
	if(browser=="Internet Explorer" ){
		if(version < 7){
			return true;
		}
	}
	return false;
}

function scroll_grid_up(){
	thumb_scroll_speed=0;
	current_scroll_direction="up";
	scroll_interval=setInterval("do_grid_scroll()",10);
	var thumb_grid=document.getElementById("thumb_grid");
	if(thumb_grid_y > (-1 * (thumb_grid.offsetHeight-visible_height))){
		make_down_arrow_rolled_over();
	}
}

function scroll_grid_down(){
	thumb_scroll_speed=0;
	current_scroll_direction="down";
	scroll_interval=setInterval("do_grid_scroll()",10);
	if(thumb_grid_y<0){
		make_up_arrow_rolled_over();
	}
}


function make_up_arrow_normal(){
	if(up_arrow_state=="rolled over"){
		var up_arrow=document.getElementById("up_arrow");
		var up_arrow_over=document.getElementById("up_arrow_over");
		up_arrow.style.visibility="visible";
		up_arrow_over.style.visibility="hidden";
		up_arrow_state="normal";
	}
}


function make_down_arrow_normal(){
	if(down_arrow_state=="rolled over"){
		var down_arrow=document.getElementById("down_arrow");
		var down_arrow_over=document.getElementById("down_arrow_over");
		down_arrow.style.visibility="visible";
		down_arrow_over.style.visibility="hidden";
		down_arrow_state="normal";
	}
}

function make_up_arrow_rolled_over(){
	if(up_arrow_state=="normal"){
		var up_arrow=document.getElementById("up_arrow");
		var up_arrow_over=document.getElementById("up_arrow_over");
		up_arrow.style.visibility="hidden";
		up_arrow_over.style.visibility="visible";
		up_arrow_state="rolled over";
	}
}

function make_down_arrow_rolled_over(){
	if(down_arrow_state=="normal"){
		var down_arrow=document.getElementById("down_arrow");
		var down_arrow_over=document.getElementById("down_arrow_over");
		down_arrow.style.visibility="hidden";
		down_arrow_over.style.visibility="visible";
		down_arrow_state="rolled over";
	}
}

function do_grid_scroll(){
	if(current_scroll_direction=="down"){
		thumb_scroll_speed+=acceleration;
	}else{
		thumb_scroll_speed-=acceleration;
	}
	if(Math.abs(thumb_scroll_speed)>max_speed){
		if(current_scroll_direction=="down"){
			thumb_scroll_speed=max_speed;
		}else{
			thumb_scroll_speed=-1*max_speed;
		}
	}
	thumb_grid_y=thumb_grid_y+thumb_scroll_speed
	var thumb_grid=document.getElementById("thumb_grid");
	
	if(thumb_grid_y>0){
		thumb_grid_y=0;
		make_up_arrow_normal();
	}else if(thumb_grid_y < (-1 * (thumb_grid.offsetHeight-visible_height))){
		thumb_grid_y= -1 * (thumb_grid.offsetHeight-visible_height);
		make_down_arrow_normal();
	}
	thumb_grid.style.top=thumb_grid_y+"px";
}

function stop_grid_scroll(){
	make_up_arrow_normal();
	make_down_arrow_normal();
	clearInterval(scroll_interval);
}

function make_all_thumbs_not_rolled_over(){
	for(i=0;i<item_image_filenames_array.length;i++){
		if(selected_arr_pos!=i){
			document.getElementById("thumb"+i).style.borderColor="#000000";
		}
	}
}

function thumb_rollover(arr_pos){
	make_all_thumbs_not_rolled_over();
	document.getElementById("thumb"+arr_pos).style.borderColor="#ED1C24";
}

function thumb_rollout(){
	make_all_thumbs_not_rolled_over();
}

function show_portfolio_piece(arr_pos){
	selected_arr_pos=arr_pos;
	thumb_rollover(arr_pos);
	var this_img_url=item_image_filenames_array[arr_pos];
	var this_img_width=item_image_widths_array[arr_pos];
	var this_img_height=item_image_heights_array[arr_pos];
	var img_div=document.getElementById("large_picture_holder");
	img_div.style.visibility="visible";
	
	img_div.style.width=this_img_width+"px";
	img_div.style.height=this_img_height+"px";
	var img_html="<img src='"+this_img_url+"' height='"+this_img_height+"' width='"+this_img_width+"' border='0' />";
	
	var this_description="<div id='description_inner_text'>"+item_descriptions_array[arr_pos]+"</div>";
	var this_url=item_urls_array[arr_pos];
	
	var external_link=document.getElementById("main_piece_external_link");
	if(trim(this_url)!=""){
		external_link.style.visibility="visible";
		external_link.innerHTML="<a href='"+this_url+"' target='new_window' id='description_link_text'>click for website</a>";
		img_html="<a href='"+this_url+"' target='new_window'>"+img_html+"</a>";
	}else{
		external_link.style.visibility="hidden";
	}
	
	img_div.innerHTML=img_html;
	//img_div.innerHTML="<br /><br />";
	
	var center_x=592;
	var center_y=228;
	var shadow_offset=3;
	var left_edge=Math.round(center_x-this_img_width/2);
	var top_edge=Math.round(center_y-this_img_height/2);
	img_div.style.left=left_edge+"px";
	img_div.style.top=top_edge+"px";
	//apply_drop_shadow(img_div,"shadow1");
	/**/
	var main_shadow=document.getElementById("main_shadow");
	main_shadow.style.visibility="visible";
	main_shadow.style.width=(this_img_width-20)+"px";
	main_shadow.style.height=(this_img_height-20)+"px";
	main_shadow.style.left=(left_edge+20+shadow_offset)+"px";
	main_shadow.style.top=(top_edge+20+shadow_offset)+"px";
	
	var bl_shadow=document.getElementById("bl_shadow");
	bl_shadow.style.width="10px";
	bl_shadow.style.height="10px";
	bl_shadow.style.visibility="visible";
	bl_shadow.style.left=(left_edge+10+shadow_offset)+"px";
	bl_shadow.style.top=(top_edge+this_img_height+shadow_offset)+"px";
	
	var tl_shadow=document.getElementById("tl_shadow");
	tl_shadow.style.width="10px";
	tl_shadow.style.height="10px";
	tl_shadow.style.visibility="visible";
	tl_shadow.style.left=(left_edge+10+shadow_offset)+"px";
	tl_shadow.style.top=(top_edge+10+shadow_offset)+"px";
	
	
	var tr_shadow=document.getElementById("tr_shadow");
	tr_shadow.style.width="10px";
	tr_shadow.style.height="10px";
	tr_shadow.style.visibility="visible";
	tr_shadow.style.left=(left_edge+this_img_width+shadow_offset)+"px";
	tr_shadow.style.top=(top_edge+10+shadow_offset)+"px";
	
	
	var br_shadow=document.getElementById("br_shadow");
	br_shadow.style.width="10px";
	br_shadow.style.height="10px";
	br_shadow.style.visibility="visible";
	br_shadow.style.left=(left_edge+this_img_width+shadow_offset)+"px";
	br_shadow.style.top=(top_edge+this_img_height+shadow_offset)+"px";
	
	var top_shadow=document.getElementById("top_shadow");
	top_shadow.style.width=(this_img_width-20)+"px";
	top_shadow.style.height="10px";
	top_shadow.style.visibility="visible";
	top_shadow.style.left=(left_edge+20+shadow_offset)+"px";
	top_shadow.style.top=(top_edge+10+shadow_offset)+"px";
	
	var bottom_shadow=document.getElementById("bottom_shadow");
	bottom_shadow.style.width=(this_img_width-20)+"px";
	bottom_shadow.style.height="10px";
	bottom_shadow.style.visibility="visible";
	bottom_shadow.style.left=(left_edge+20+shadow_offset)+"px";
	bottom_shadow.style.top=(top_edge+this_img_height+shadow_offset)+"px";
	
	var left_shadow=document.getElementById("left_shadow");
	left_shadow.style.width="10px";
	left_shadow.style.height=(this_img_height-20)+"px";
	left_shadow.style.visibility="visible";
	left_shadow.style.left=(left_edge+10+shadow_offset)+"px";
	left_shadow.style.top=(top_edge+20+shadow_offset)+"px";
	
	var right_shadow=document.getElementById("right_shadow");
	right_shadow.style.width="10px";
	right_shadow.style.height=(this_img_height-20)+"px";
	right_shadow.style.visibility="visible";
	right_shadow.style.left=(left_edge+this_img_width+shadow_offset)+"px";
	right_shadow.style.top=(top_edge+20+shadow_offset)+"px";
	
	var description_holder=document.getElementById("item_description");
	description_holder.style.visibility="visible";
	description_holder.style.width="200px";
	description_holder.style.left=(left_edge-220+shadow_offset)+"px";
	description_holder.style.top=(center_y+30+shadow_offset)+"px";
	description_holder.innerHTML=this_description;

	external_link.style.left=(left_edge)+"px";
	external_link.style.top=(top_edge+this_img_height+20)+"px";
	
}

function hide_left_side_texts(){
	for(i=0;i<left_side_content_names_array.length;i++){
		var this_name=left_side_content_names_array[i];
		var text_div=document.getElementById("left_side_"+this_name);
		text_div.style.visibility="hidden";
	}
}

function revert_left_side_menu(){
	for(i=0;i<left_side_content_names_array.length;i++){
		var this_name=left_side_content_names_array[i];
		var menu_item=document.getElementById(this_name+"_menu_link");
		var this_html='<a href="javascript:display_left_side_text(\''+this_name+'\');" >'+this_name+'</a>';
		menu_item.innerHTML=this_html;
	}
}

function make_left_side_menu_item_selected(item_text){
	var menu_item=document.getElementById(item_text+"_menu_link");
	var this_html='<font color="#ED1C24">'+item_text+'</font>';
	menu_item.innerHTML=this_html;
}

function display_left_side_text(text_to_display){
	hide_left_side_texts();
	revert_left_side_menu();
	var text_div=document.getElementById("left_side_"+text_to_display);
	text_div.style.visibility="visible";
	make_left_side_menu_item_selected(text_to_display);
}