	//var normal_block_style = "asset";
	//var selected_block_style = "asset_selected";
	//var last_selected_block_style = "asset_last_selected";

	function fixup_blocks(){
		var new_blocks = document.getElementsByClassName('asset');
		blocks = new Array();
		selection_states = new Array();
		for (var x=0; x<new_blocks.length; x++){
			blocks[x] = new_blocks[x].id;
			selection_states[x] = false;
		}
		was_clicked(blocks[0]);
	}

	function open_frame(the_frame, the_url){
                parent.frames[the_frame].location.href = the_url;
        }

	var doit = true;
	function doityes(){
		doit = true;
	}

	function open_detail(asset_id){
                        var link = dpo2_path_base + "detail.mhtml?asset=" + asset_id + '&close=' + (($('detail').className == "detail") ? '0' : '1');
                        new Ajax.Updater( 'detail', link, { method: 'get'}  ) ;
			//open_detail_tab();
	}

	function was_clicked(a_block, e){

		if (doit != true){
			return;
		}
		reset_lightbox();
		doit = false;
		setTimeout("doityes()", 5);

		the_block = document.getElementById(a_block);

		if (is_unselected(the_block)){
			//Wasn't clicked, therefore show details
			var tmp = a_block;
			tmp = tmp.replace("asset_","").replace("lightbox_","");
			open_detail(tmp);
		}

		if ( is_shift(e) ){
			if (check_it('ie')){
                        	document.selection.clear();
			}
			if (last_selected){
				var select_from = index_of(last_selected);
				var select_to = index_of(the_block);
				if (select_from > select_to){
					var temp_select = select_from;
					select_from = select_to;
					select_to = temp_select;
				}

				for(var x=select_from; x <= select_to; x++){
					set_selected(document.getElementById(blocks[x]));
				}

			}else{
				select_toggle(the_block);
			}
			//set_selected(last_selected);
			last_selected = the_block;
			//set_last_selected(the_block);
		}else{
			if (is_ctrl(e) == false){
				reset_all();
			}

			
			if (last_selected && (is_selected(last_selected))){
				set_selected(last_selected);
			}
	                last_selected = the_block;
			select_toggle(the_block);
			//if (is_selected(the_block)){
		        //        set_last_selected(the_block);
			//}
		}
		// CSS bug, make sure IE doesn't fsck up the layout.
		//select_toggle( document.getElementById(blocks[0]) );
		//select_toggle( document.getElementById(blocks[0]) );
	}


	function select_toggle(a_block){
		if (is_unselected(a_block)) {
			set_selected(a_block);
		}else{
			set_normal(a_block);
		}
	}

	function is_shift(e){
		if (e != undefined){
			return e.shiftKey;
		}
		return false;
	}
	function is_ctrl(e){
                if (e != undefined){
		if (e.metaKey == undefined){
			return e.ctrlKey;
		}else{
			return e.ctrlKey || e.metaKey;
		}
		}else{
		return false;
		}
	}

	function is_selected(a_block){
		return (a_block.className == selected_block_style) || (a_block.className == last_selected_block_style);
	}

	function is_unselected(a_block){
		return !(is_selected(a_block));
	}

	function index_of(a_block){
		for(var x=0;x<blocks.length;x++){
			if (blocks[x] == a_block.id){
				return x;
			}
		}
	}

	function set_selected(a_block){
		a_block.className = selected_block_style;
		selection_states[index_of(a_block)] = true;
	}

	function set_last_selected(a_block){
		if (reset_frame){
			reset_frame.reset_last_selected();
		}
                a_block.className = last_selected_block_style;
        }

	function reset_all(){
		for(var x=0;x<blocks.length;x++){
				set_normal( document.getElementById(blocks[x]) );
		}
		last_selected = null;

	}
        function set_all(){
                for(var x=0;x<blocks.length;x++){
                                set_selected( document.getElementById(blocks[x]) );
                }
                last_selected = null;

        }


	function set_normal(a_block){
		if (a_block == last_selected){
			last_selected = null;
		}
		a_block.className = normal_block_style;
		selection_states[index_of(a_block)] = false;

	}

	function dump_values(){

		var output = "Button Values:\n";

		for(var x=0;x<blocks.length;x++){
				output += blocks[x] + ":\t" + selection_states[x] + "\n";
		}

		return output;
	}

	function selected_querystring(a){
		var output = '?';
		if (a == 'noquestion'){
			output = '';
		}
		if(a == 'noargs'){
			output = '?1=1';
		}

                for(var x=0;x<blocks.length;x++){
			if (selection_states[x] == true){
				var tmp = blocks[x]
				tmp = tmp.replace("asset_","")
				output += '&asset_' + x + '=' +  tmp 
			}
                }
		return output;
        }
	
	function selected_id_array(){
		var output = new Array();
		for(var x=0;x<blocks.length;x++){
                        if (selection_states[x] == true){
                                var tmp = blocks[x]
                                tmp = tmp.replace("asset_","")
                                output.push( tmp );
                        }
                }
                return output;
	}

	

	function link_selected(link,frame){
		var arg = '';
		if (link.indexOf('?') == -1){
			arg = 'noargs';
		}
		link = link + selected_querystring(arg);
		if (frame){
			open_frame(frame, link);
		}else{
			document.location = link;
		}
	}

	function link_last_selected(link,frame){
		if (last_selected)
                link = link + '?' + last_selected.id + '=1';
                if (frame){
                        open_frame(frame, link);
                }else{
                        document.location = link;
                }
        }
	
	function reset_last_selected(){
		if (last_selected){
			if (is_selected(last_selected)){
				set_selected(last_selected);
			}else{
				set_normal(last_selected);
			}
			last_selected = null;
		}
	}

