// JavaScript Document

		var mouse_position = 0;
		var current_sub = '';
		var parent_sub = '';
		var menui_width = 0;
		var scroll_lr = false;
		var scroll_rl = false;
		var control_width = 400;
		var current_project = 0;
		var project = Array();
		var onprocess = false;
		
		function remove_mouse() {
			mouse_position = 0;
		}
		
		function load_label (tag) {
			//Element.fade('label_text');
			$('label_text').innerHTML = tag;
			//Effect.Appear('lable_text');
		}
		
		function unload_label () {
			//Element.fade('label_text');
			$('label_text').innerHTML = "View labels";	
			//Effect.Appear('label_text');
		}
		
		function show_project(project_id) {
			var check = 0;
			if ( !onprocess ) {
				onprocess = true;
				if ( $('project_container_'+project_id).getStyle('display') == 'none' ) {
				
					
					var projects = $('project_container').getElementsByClassName('project_body');
					for ( var i = 0 ; i < projects.length ; i++ ) {
						if ( projects[i].getStyle('display') != 'none' ) {
							var imgbox = projects[i].getElementsByClassName('imagebox');
							for ( var ii = 0 ; ii < imgbox.length ; ii++ ) {
								imgbox[ii].innerHTML = '';
							}
							Effect.SlideUp(projects[i]);
							check++;
						}
					}
	
					current_project = project_id;
					if ( check > 0 )
						window.setTimeout('slide("'+project_id+'")',100);
					else
						slide(project_id);
				
				}else {
					Effect.SlideUp('project_container_'+project_id,{afterFinish: setprocessfalse});
					//$('project_container_'+project_id).focus();
					//window.setTimeout('setprocessfalse();',1200);
				}
			}
			
		}
		
		function set_image ( obj ) 
		{ 
			var project_id = obj.element.id.replace('project_container_','');
			if ( project[project_id] != null ) {
				$('imagebox_'+project_id).innerHTML = project[project_id];
				//var a = new Effect.Opacity('imagebox_'+project_id, {from:0.0, to:1.0});		
			}
			setprocessfalse();
		}
		
		function slide(project_id) {
			Effect.SlideDown('project_container_'+project_id,{afterFinish: set_image});
			//$('project_container_'+project_id).focus();
			//window.setTimeout('setprocessfalse();',1200);
		}
		
		function setprocessfalse() {
			onprocess = false;
		}
		
		function load_project_detail(project_id) {
			$('imagebox_'+project_id).innerHTML = '';
			//var a = new Effect.Opacity('imagebox_'+project_id, {duration:0.5,from:1.0, to:0.0});		
			show_project(project_id);
			if ( project[project_id] == null ) {
				var opt = {
					method: 'post',
					parameters:'project_id='+project_id,
					onSuccess: function(t) {
						project[project_id] = t.responseText;
						$('imagebox_'+project_id).innerHTML = t.responseText;
						//var a = new Effect.Opacity('imagebox_'+project_id, {from:0.0, to:1.0});		
					},
					on404: function(t) {
						alert('Error 404: location "' + t.statusText + '" was not found.');
					},
					onFailure: function(t) {
						alert('Error ' + t.status + ' -- ' + t.statusText);
					}
				}
				new Ajax.Request('load_project_detail.php', opt);
			}
			return false;
		}
		
		
		
		function load_project(tag_id) {
			current_project = 0;
			document.getElementById('project_container').style.display = 'none';
			document.getElementById('initial_box').style.display = 'none';
			document.getElementById('preloader').style.display = '';
			var opt = {
				// Use POST
				method: 'post',
				// Send this lovely data
				parameters:'tag_id='+tag_id,
				// Handle successful response
				onSuccess: function(t) {
					document.getElementById('project_container').innerHTML = t.responseText;
					document.getElementById('preloader').style.display='none';
					Effect.Appear('project_container');
				},
				// Handle 404
				on404: function(t) {
				alert('Error 404: location "' + t.statusText + '" was not found.');
				},
				// Handle other errors
				onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
				}
			}
			
			new Ajax.Request('load_project.php', opt);
		}
				
		function load_sub(sub_id) {
			sub_i = 1;
			subname = "sub_"+sub_id+sub_i;
			while ( document.getElementById(subname) ) {
/*				if ( $('sub_'+sub_id).getStyle('display') == 'none' ) {
					Effect.Appear('sub_'+sub_id);
				}else{
					unload_sub(sub_id);	
				}
*/
				if ( $(subname).getStyle('display') == 'none' ) {
					Effect.Appear(subname);
				}else{
					unload_sub(subname);	
				}
				sub_i++;
				subname = "sub_"+sub_id+sub_i;				
			}
			return false;
		}
		function unload_sub(sub_id) {
			
			Element.fade(sub_id,{queue:'end'});
			return false;
		}
		/*
		function unload_sub(sub_id) {
			
			Element.fade('sub_'+sub_id,{queue:'end'});
			return false;
		}
		*/
		
		function unload_sub_all() {
			var subs = $('menui').getElementsByClassName('sub_tag');
			for ( var i = 0 ; i < subs.length ; i++ ) {
				if ( subs[i].getStyle('display') != 'none' ) {
					Element.fade(subs[i]);
				}
			}
		}

		function calculate_w() {
			var base = document.getElementById('menui');
			var as = base.getElementsByTagName('a');

			var lng = 0;
			var ratio = 24.5;//8.5;
			var spratio = 11;//4;
			var spcnt = ( 26 * parseFloat(spratio) );
			var extspcnt = 0;
			for ( var i = 0 ; i < as.length ; i++ ) {
				if ( as[i].className == 'tag' ) {
					var style = Element.readAttribute(as[i].parentNode,'style');
					if ( style.indexOf('display: none') == -1 && style.indexOf('display:none') == -1 ) {
//					if ( as[i].parentNode.getStyle('display') != 'none' ) {
						lng = parseFloat(lng) + ( parseFloat(as[i].innerHTML.length) * parseFloat(spratio  ) );
						extspcnt = parseFloat(extspcnt) + parseFloat(spratio);
					}
				} else {
					lng = parseFloat(lng) +  ( parseFloat(as[i].innerHTML.length) * parseFloat(ratio) );
				}
				
			}
			lng += parseFloat(spcnt) + parseFloat(extspcnt);
			lng = 600 - lng;	
			
			return lng;
		}
		
		
		function rotate_image(obj ) {
		
			
		}
		
		
		
    
		
		function move_left() {

			if ( !scroll_lr ) {
				scroll_lr = true;
				move_left_fn();
			}
			
			return false;
		}
		
		function move_left_fn() {
			if ( scroll_lr ) {
				var c_move = Element.getStyle('menui','margin-left');
				c_move = c_move.replace('px','');
				move =  (parseFloat(c_move) - 8);
				
				var maxval = calculate_w();
				//alert(maxval+ " " +move);
				if ( move < maxval )
					move = maxval;
				if (  move <= 10 && move >= maxval )
					Element.setStyle('menui', {margin:'auto auto auto '+move+'px'} );
				window.setTimeout('move_left_fn();', 100);				
			}
			
		}
		
		function move_right() {

			if ( !scroll_rl ) {
				scroll_rl = true;
				move_right_fn();
			}
			
			return false;
		}
		
		function move_right_fn() {
			if ( scroll_rl ) {
				var c_move = Element.getStyle('menui','margin-left');
				c_move = c_move.replace('px','');
				move =  (parseFloat(c_move) + 8);
				var maxval = calculate_w();
				
				if (  move <= 10   && move >= maxval )
					Element.setStyle('menui', {margin:'auto auto auto '+move+'px'} );
				window.setTimeout('move_right_fn();', 100);				
			}
		}

		
		function showPosition(e) {
			if ( parseInt(mouse_position) > 0 ) {
				var move = (mouse_position - Event.pointerX(e));
				move = parseFloat(move);
				c_move = Element.getStyle('menui','margin-left');
				c_move = c_move.replace('px','');
				move = parseFloat(move) + parseFloat(c_move);
				var maxval = calculate_w();
				if ( move < maxval )
					move = maxval;
				if (  move <= 10 && move >= maxval )
					Element.setStyle('menui', {margin:'auto auto auto '+move+'px'} );
			}
			mouse_position = Event.pointerX(e);
		}
		
		window.onload = function() {
				Event.observe(document.getElementById('menutest3'), "mousemove", showPosition, false);
				Event.observe(document.getElementById('mv_left'), "mouseover", move_left /*function () { scroll_lr = false; }*/, false);				
				Event.observe(document.getElementById('mv_left'), "mouseout", /*move_left*/ function () { scroll_lr = false; }, false);
				Event.observe(document.getElementById('mv_right'), "mouseover", move_right /*function () { scroll_lr = false; }*/, false);				
				Event.observe(document.getElementById('mv_right'), "mouseout", /*move_left*/ function () { scroll_rl = false; }, false);
				
				/*
				$('portfolio').innerHTML = '<div id="dhtmltooltip"></div><img id="dhtmlpointer" src="/images/arrow2.gif">' + $('portfolio').innerHTML;
				
				ie=document.all;
				ns6=document.getElementById && !document.all;
				enabletip=false;
				if (ie||ns6)
					tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
				
				pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "";
				
				//document.onmousemove=positiontip;
				*/
		} 		