//----------------------CHECK NAVIGATOR VERSION------------------------
function version()
{
	var allversions = navigator.appVersion.split("MSIE");
	var version=parseFloat(allversions[1]);	
	if(navigator.appName=='Microsoft Internet Explorer')
	{
		if(version >= 5.5 && version<7)
			return "IE6";
		if(version >=7)
			return "IE7";
	}else
	{
		return "OTHER";
	}
}


//========================SET FILTERS FOR IE======================
function pngFilter()
{	
	//punem una din cele ca header
	var rnd_nr=Math.random();
	var img_nr=Math.round(rnd_nr*3);
	if(img_nr==0)
		img_nr=1;
	var img_name="images/raft"+img_nr+".png";
	
	var main_img=document.getElementById('main_img');
	main_img.style.backgroundImage="url("+img_name+")";

	
	var divBkg=document.getElementById('shadow');
	if(version()=="IE6")
	{	
		var shadow_left= document.getElementById('shadow_left');
		var shadow_right= document.getElementById('shadow_right');
		var top_left=document.getElementById('top_left');
		var top_right=document.getElementById('top_right');
		
		
		divBkg.style.backgroundImage = "url(images/1.gif)";
		shadow_left.style.backgroundImage="url(images/1.gif)";
		shadow_right.style.backgroundImage="url(images/1.gif)";
		top_left.style.backgroundImage="url(images/1.gif)";
		top_right.style.backgroundImage="url(images/1.gif)";
		main_img.style.backgroundImage="url(images/1.gif)";
								
		divBkg.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/bkgShadow.png', sizingMethod='scale')";
		shadow_left.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/shadow_left.png', sizingMethod='scale')";
		shadow_right.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/shadow_right.png', sizingMethod='scale')";
		top_left.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/left.png', sizingMethod='scale')";
		top_right.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/right.png', sizingMethod='scale')";
		main_img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img_name+"', sizingMethod='scale')";
	}
	
}

//-----------------LOADER DIV-----------------------------

function loader()
{
	var overDiv=document.getElementById('over');
	var menu=document.getElementById('menu');
	
	if(navigator.appName=='Microsoft Internet Explorer')
	{
		menu.style.top=(document.body.clientHeight-30)+"px";
		overDiv.style.height=document.body.clientHeight+"px";
		overDiv.style.width=document.body.clientWidth+"px";
		overDiv.style.display="block";
		overDiv.style.display="none";
	}else
	{
		menu.style.top=(window.innerHeight-80)+"px";
		overDiv.style.width=window.innerWidth + "px";
		overDiv.style.height=window.innerHeight + "px";
		overDiv.style.display="block";
	}
	
}


//---------------------------FIRST LOAD---------------------------------

function first_load()
{
	var menu=$("#menu_holder");
	var menuH=menu.height();
	var obj=$("#main_img");
	var next=$("#content_holder");
	obj.css("display", "block");
	next.css("display", "block");
	menu.css("top",$(window).height()-menuH);
	/*if(version()=="IE6" || version()=="IE7")
	{
		obj.css("display", "block");
		next.fadeIn("slow");
		//menu.style.top=($(document).height()-menuH)+"px";
	}
	else
	{	
		obj.fadeIn("slow",function callback()
		{
			next.fadeIn("slow");
		});
		menu.style.top=(window.innerHeight-menuH)+"px";
	}*/
}

//-------------------POSITION MENU-------------------
function menuPoz()
{
	var menu=$("#menu_holder");
	var menuH=menu.height();
	if(version()=="IE6" || version()=="IE7")
	{
		var top=document.body.scrollTop;
		menu.css("top",((top+document.body.clientHeight)-menuH)+"px");
	}
	else
	{	
		var top=window.pageYOffset;
		menu.css("top",((top+document.body.clientHeight)-menuH)+"px");
	}
}
//-------------------END POSITION MENU -------------------

//-------------------MENU SLIDE-------------------
function delay(ms){
	var start=new Date;
	while(new Date-start<ms);	
}
function menuToggle()
{
	
	var menu=document.getElementById('menu_holder');
	var menuH=menu.offsetHeight;
	var div_submenu=document.getElementById('div_submenu');
	var div_login=document.getElementById('div_login');

	if(menuH<=30)
	{
		
		div_submenu.style.display="block";
		div_login.style.display="block";
		menuPoz();
	}else
	{
		$("#div_submenu").slideDown("slow");
		div_submenu.style.display="none";
		div_login.style.display="none";
		menuPoz();
	}
}
//-------------------END MENU SLIDE-------------------

$(document).ready(function(){
	var a=0;
	pngFilter();
	first_load();
	
	
	
	//------Window RESIZE EVENT-----------------------
	$(window).resize(function(){
		menuPoz();
	});
	
	$(window).scroll(function(){
		//alert (a);
		menuPoz();
		if(a==0)
		{
			a=1;
			var partners = document.getElementById('partners');
			var partnersH = document.body.scrollHeight;
			partners.style.height=partnersH+"px";
		}
		
		
	});

	$("#menu_img").click(function(){
		menuToggle();								 
	});
	$("#proiecte").click(function(){
		menuToggle();								 
	});
});

//---------------------FILE UPLOAD FUNCTION-----------------
function startUpload()
{
	var p = document.createElement("p");
	var child;
	p.innerHTML="Loading... &nbsp<img src='loading.gif' height=15 alt='' />";
	p.setAttribute("id","mesaj_upload");
	var parent=document.getElementById('img_upload');
	if(!document.getElementById('mesaj_upload'))
	{
		child = document.getElementById('image_upload_form');
	}else
	{
		child = document.getElementById('mesaj_upload');
	}
	parent.insertBefore(p,child);
}

function stopUpload(status, cale,cale_thumb)
{
	var x =document.getElementById('mesaj_upload');
	if(status==1)
	{
		
		//ceva nu-i bun la substr
						//var loc= window.location.href;
						//var imgpath = loc.substr(0,loc.lastIndexOf("/")) + "/prj_images/img/" + imgname;
		
		var textarea = document.createElement("textarea");
		textarea.setAttribute("cols","60");
		textarea.setAttribute("rows","2");
		textarea.style.border="solid 1px #666666";
		textarea.style.color="#666666";
		textarea.style.backgroundColor="#cccccc";
		
		textarea.value="<a href='"+ cale +"' >" + "<img src='" + cale_thumb + "' height='150' alt='"+ cale +"' style='border:1px solid #ffffff' align='left'>" + "</a>";
		
		x.innerHTML="Image uploaded succesfuly. Copy and paste text below to embed in webpage. <br>";
		x.appendChild(textarea);
		
	}else{
		x.innerHTML=imgname+ ' Could Not Be Loaded.';
	}
	document.image_upload_form.reset();
	frames['upload_frame'].location.href = 'blank.html';
}

//-------TOGGLE TINY MCE-----------------------------------
function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id))
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
	document.getElementById(id).style.width='450px';
	document.getElementById(id).style.height='120px';
}