function menu_hover(div)
{	
	var imgs = div.getElementsByTagName('img');
	for(i = 0; i<imgs.length; i++)
		imgs[i].src = imgs[i].src.substr(0,imgs[i].src.length-4)+"2.png";
}

function menu_out(div)
{
	var all_imgs = div.getElementsByTagName('img');
	for (var i = 0;i <all_imgs.length; i++)
	{
		//if (all_imgs[i].src.substr(all_imgs[i].src.length-5)=="2.png")
			all_imgs[i].src=all_imgs[i].src.substr(0,all_imgs[i].src.length-5)+".png";
	}
}

var fade_timer = 0;
function fade_in_fade_out(el, way)
{
	var the_op = Math.min(getOpacity(el) + (0.3 * way), 1);
	setOpacity(el, the_op);
	if (way == 1)
	{
		if (the_op < 1)
			fade_timer = setTimeout("fade_in_fade_out('" + el + "', 1)", 100);
		else
			fade_timer = setTimeout("fade_in_fade_out('" + el + "', -1)", 4000);
	}
	else
	{
		if (the_op > 0)
			fade_timer = setTimeout("fade_in_fade_out('" + el + "', -1)", 100);
		else
		{
			change_text(el);
			fade_timer = setTimeout("fade_in_fade_out('" + el + "', 1)", 150);
		}
	}
}
function stop_fifo(el)
{
	clearTimeout(fade_timer);
	setOpacity(el, 1);
	fade_timer = 0;
}

var the_text_ind = 1;
function change_text(el)
{
	element = document.getElementById(el);
	element.innerHTML = texts[(the_text_ind++) % texts.length];
}

function setOpacity(el, value)
{
	element = document.getElementById(el);
	var set_value = (value === '') ? '0' : (value < 0.00001) ? 0 : value;
	element.style.opacity = set_value;
	element.style.filter  = "alpha(opacity=" + parseInt(set_value * 100) + ")";
	element.opac = set_value;
}

function getOpacity(el)
{
	var val = document.getElementById(el).opac;
	if (typeof val != 'undefined')
		return parseFloat(val);
	else
    	return 1.0;
}

function start_scroll()
{
	var da_div = document.getElementById("year_info");
	da_div.scrollTop += 1;
	if (da_div.scrollTop >= da_div.scrollHeight - da_div.offsetHeight - 5)
	{
		return ;
//		setTimeout("closeApp()", 15000);
	}
	else
		setTimeout("start_scroll()", 25);
}

function closeApp()
{
//	document.location.href = "http://www.google.com/close_app";
}

function scroll_up(id, amount)
{
	var div = document.getElementById(id);
	div.scrollTop -= 72;
}
function scroll_down(id, amount)
{
	var div = document.getElementById(id);
	div.scrollTop += 72;
}

function show_img(ind, src, id, movie)
{
	// alert(img_name);
	if (movie == 'false')
	{
		document.getElementById(id).innerHTML = '<img src="' + src + '" height="312" onclick="show_popup(\'divid\', \''+ ind +'\')" />';
		
		var imgs = document.getElementById('images').getElementsByTagName('img');
		var first_img = images[0];
//		var show = 1;
//		alert(document.getElementById('text').innerHTML);
//		alert(alt);
// && (document.getElementById('text').innerHTML != first_img.alt)
/*
		if (!modified_text)
		{
			show = 0;
		}
*/

		if (show)
		{
			document.getElementById('text').innerHTML = imgs[ind].alt;
//			modified_text = 1;
		}
		
		document.getElementById('description').innerHTML = imgs[ind].alt;
	}
	else
	{
		document.getElementById(id).innerHTML = '<div id="flashbanner"><embed type="application/x-shockwave-flash" src="mediaplayer.swf" style="" id="mpl" name="mpl" quality="high" allowfullscreen="false" wmode="transparent" flashvars="file=' + movie + '&amp;backcolor=0xffffff&amp;autostart=true" width="420" height="312"></div>';
	}
	var the_p = document.getElementById("parag_" + ind);
//	var the_id_elem = document.getElementById("img_" + img_name);
	// alert(the_id_elem.innerHTML);
	var the_c = document.getElementById("text");
	// alert(the_c.innerHTML);
//	if (the_id_elem)
//	{
//		vScrollInContainer(the_c, the_id_elem);
//	}
//	else if (the_p)
//		the_c.scrollTop = the_p.offsetTop;
//	else
	{
		/*
		var ps = the_c.getElementsByTagName("p");
		if (ps.length > ind)
			the_c.scrollTop = ps[ind].offsetTop;
			*/
	}
}

function open_submenu(id)
{
	var uls = document.getElementById('main_menu').getElementsByTagName('ul');
	for (var i = 0; i < uls.length; i++)
	{
		if (i == id)
		{
			uls[i].style.display = 'block';
			document.getElementById('p'+i).style.backgroundImage = 'url(i/menu_2.gif)';
		}
		else
		{
			uls[i].style.display = 'none';
			document.getElementById('p'+i).style.backgroundImage = 'url("i/menu_1.gif")';
		}
	}
}

function check_menu()
{
	var uls = document.getElementById('main_menu').getElementsByTagName('ul');
	if (uls.length > 0)
	{
		for (var i = 0; i < uls.length; i++)
		{
			var as = uls[i].getElementsByTagName('a');
			for(var j = 0; j < as.length; j++)
			{
				if (as[j].getAttribute('class') == 'selected')
				{
					uls[i].style.display = 'block';
					document.getElementById('p'+i).style.backgroundImage = 'url(i/menu_2.gif)';
				}
			}
		}
	}
}

function vScrollInContainer(container, elem)
{
	var scroll_top = 0;
	var e = elem;
	while (e && (e != container))
	{
		scroll_top += e.offsetTop;
		e = e.offsetParent;
	}
	container.scrollTop = scroll_top;
}

// Determine browser

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function set_width(w)
{
	document.getElementById("timeline").setAttribute("width", w + "px");
	document.getElementById("timeline").style.width = w + "px";
}

function dragGo(event) {

  var x, y;
  var timeline = document.getElementById('timeline');
  var holder = document.getElementById('holder');
  
  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
  // alert(x + " x "+ y);

  // Move drag element by the same amount the cursor has moved.

  if ((dragObj.elStartLeft + x - dragObj.cursorStartX) > 0)
  	dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  else 
  	dragObj.elNode.style.left = "0px";
  if ((dragObj.elStartLeft + x - dragObj.cursorStartX) > 720)
  	dragObj.elNode.style.left = "720px";
  holder.scrollLeft = (dragObj.elNode.offsetLeft * timeline.offsetWidth)/1000;
  //alert((dragObj.elNode.offsetLeft * timeline.offsetWidth)/800);
  
  //dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Clear the drag element global.

  dragObj.elNode = null;

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

var set_year_info_last = null;

function set_year_info(string_year, id)
{
	if (set_year_info_last)
		set_year_info_last.style.display = 'none';
	var c_div = document.getElementById("info_" + string_year);
	if (c_div)
	{
		c_div.style.display = 'block';
		set_year_info_last = c_div;
	}
	
	var links = document.getElementById('timeline').getElementsByTagName('a');
	for (var i = 0; i < links.length; i++)
		if(links[i].id == id)
			links[i].className = "selected";
		else
			links[i].className = "";
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.StopPlay();
}

function PlayFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Play();
	//embed.nativeProperty.anotherNativeMethod();
}

function RewindFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Rewind();
}

function NextFrameFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	// 4 is the index of the property for _currentFrame
	var currentFrame=flashMovie.TGetProperty("/", 4);
	var nextFrame=parseInt(currentFrame);
	if (nextFrame>=10)
		nextFrame=0;
	flashMovie.GotoFrame(nextFrame);		
}


function ZoominFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Zoom(90);
}

function ZoomoutFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Zoom(110);
}


function SendDataToFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.SetVariable("/:message", document.controller.Data.value);
}

function ReceiveDataFromFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	var message=flashMovie.GetVariable("/:message");
	document.controller.Data.value=message;
}

function set_sound()
{
	var item = document.getElementById('sound');
	
	var obj = top.document.getElementById('variables');
	if(obj.getAttribute('sound_on') == "false")
		item.src = "i/btn_sound_off.gif";
	else
		item.src = "i/btn_sound.gif";
}

function playSound(soundobj) {
	var thissound=document.getElementById(soundobj);
	thissound.Play();
}

/*
function setSound(nr)
{
	alert(nr);
	switch(nr)
	{
		case '1': var isPlaying = parent.document.getElementById('1');
		case '2': var isPlaying = parent.document.getElementById('2');
		case '3': var isPlaying = parent.document.getElementById('3');
		case '4': var isPlaying = parent.document.getElementById('4');
	}
	
	
	alert(isPlaying);
	
	if (isPlaying.title == "true")
	{
		document.getElementById('sound').className = "sound";
		alert(isPlaying.id);
		if (isPlaying.id != nr)
		{
			isPlaying.Stop();
			isPlaying.title = "false";
			parent.document.getElementById(nr).Play();
		}
	}
	else
	{
		document.getElementById('sound').className = "no_sound";
	}
}
*/

function parentChangeMusic(id)
{
	//alert(parent.document.getElementById(id));
	var sound_on = parent.document.getElementById('variables').getAttribute('sound_on');
	var last_id = parent.document.getElementById('variables').getAttribute('last_id');
	//alert(sound_on);
	//alert(last_id);
	
	if(sound_on == "true")
	{
		document.getElementById('sound').className = "sound";
		if (last_id != id)
		{
			top.document.getElementById(last_id).Stop();
			top.document.getElementById(id).Play();
			top.document.getElementById('variables').setAttribute('last_id', id);
		}
	}
	else
	{
		document.getElementById('sound').className = "no_sound";
	}
}

function startStopMusicEx(val)
{
	var div_music = top.document.getElementById("embed_list");
	var embs = div_music.getElementsByTagName("embed");
	
	for (var i = 0; i < embs.length; i++)
	{
		// alert(embs[i]);
		embs[i].Stop();
	}
	
	top.document.getElementById('variables').setAttribute('sound_on', 'false');
	
	if (val == "true")
	{
		var last_id = top.document.getElementById('variables').getAttribute('last_id');
		var last_one = top.document.getElementById(last_id);
		
		last_one.Play();
		document.getElementById('sound').className = "sound";
		top.document.getElementById('variables').setAttribute('sound_on', 'true');
	}
}

function startStopMusic(id)
{
	var sound_on = top.document.getElementById('variables').getAttribute('sound_on');
	//alert(parent.document.getElementById(id));	
	var last_id = top.document.getElementById('variables').getAttribute('last_id');
	top.document.getElementById('variables').setAttribute('last_id', id);
//	alert(sound_on);
	//alert(last_id);
	var div_music = top.document.getElementById("embed_list");
	// alert(div_music);
	var embs = div_music.getElementsByTagName("embed");
	// alert(embs.lenth);
	for (var i = 0; i < embs.length; i++)
	{
		// alert(embs[i]);
		embs[i].Stop();
	}
	
	if(sound_on == "true")
	{
		// alert("stoping:" + id);
		if (document.getElementById('sound'))
			document.getElementById('sound').src = "i/btn_sound_off.gif";
	
		top.document.getElementById(id).Stop();
		top.document.getElementById('variables').setAttribute('sound_on', 'false');
	}
	else
	{
		if (document.getElementById('sound'))
			document.getElementById('sound').src = "i/btn_sound.gif";
			
		top.document.getElementById(id).Play();
		top.document.getElementById('variables').setAttribute('sound_on', 'true');
	}
}

var bgcol_divid = "#182741";

function show_popup(d, img)
{
//	document.getElementsByTagName("body")[0].style.overflowY = "hidden";
//	document.getElementsByTagName("body")[0].style.overflowX = "hidden";
	var width = 0;
	var height = 0;
	if (typeof window.innerWidth != 'undefined')
	{
	    width = window.innerWidth;
		height = window.innerHeight;
	}	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
	    width = document.documentElement.clientWidth,
		height = document.documentElement.clientHeight
	}

//	var height = document.body.clientHeight;
//	if (height < 550)
//	{
////		alert(height);
//		var div_h = height - 60;
//		document.getElementById("popup_opac_divid").getElementsByTagName("div")[0].style.height = div_h+'px';
//		document.getElementById("the_q").style.height = (div_h - 80)+'px';
//	}

	var imgs = document.getElementById('images').getElementsByTagName('img');

	var image = document.getElementById("largest_img");
	image.src = images[img];
	
	/*alert(images[img]);
	if (img.complete)
		document.getElementById("largest_img").src = images[img];
	else
		document.getElementById("largest_img").src = "i/loading.gif";*/
		
	document.getElementById("popup_tran_" + d).style.display = "block";
	document.getElementById("popup_tran_" + d).style.height = height+"px";
	document.getElementById("description").innerHTML = imgs[img].alt;
	document.getElementById("popup_opac_" + d).style.display = "block";
	/*try
	{
		document.getElementById("popup_opac_" + d).style.display = "table";
	}
	catch (error)
	{
		document.getElementById("popup_opac_" + d).style.display = "block";
	}*/	
//	document.getElementById("popup_tran_" + d).style.backgroundColor = eval ("bgcol_" + d);
}
function hide_popup(d)
{
//	document.getElementsByTagName("body")[0].style.overflowY = "scroll";
//	document.getElementsByTagName("body")[0].style.overflowX = "hidden";
	document.getElementById("popup_opac_" + d).style.display = "none";
	document.getElementById("popup_tran_" + d).style.display = "none";
	document.getElementById("largest_img").src = "i/loading2.gif";
}
function switchImg(src)
{
	document.getElementById("largest_img").src = src;
}

function open_pdf (d)
{
	var offsetx = (screen.width-800)/2;
	var offsety = (screen.height-730)/2;
	window.open(d,"Titlu",
	        "menubar=no,width=800,height=730,toolbar=no,left="+offsetx+",top="+offsety+"");
        
}