
	/*
	
	--------------------------------
	FS-CMS
	--------------------------------
	Copyright Frozen Sand
	
	File:		functions_website.php
	Author:		Kalish & Raider
	Started:	2008
	--------------------------------
	
	*/
	
	var host_domain = "urbanterror.info";
	var host_subdomain = "www.urbanterror.info";
	
	var location_host = window.location.hostname;
	
	if (location_host.indexOf(host_domain)==-1) 
	{
		alert( "Bad domain : " + location_host );
	}
	
	
	// GET PARENT
	
	function get_parent(obj)
	{
		try {
			obj = obj.parentNode;
		} catch(err) {
			try {
				obj = obj.parentElement;
			} catch(err) {
				obj = false;
			}	
		}
		return obj;
	}
	
	// PARENT HOVER
	
	function parent_hover(obj,hover,tag,select)
	{
		obj = get_parent(obj);
		select = select ? ( hover ? ' select' : 'select' ) : '' ;
		if(tag) tag = tag.toUpperCase();
		if(obj) if(!tag || obj.tagName==tag) obj.className = hover ? 'hover'+select : select ;
	}
	
	// PRINT
	
	function print_text(objid)
	{
		if(!objid) {
			window.print();
		} else {
			var obj = document.getElementById(objid);
			var main = document.getElementById("main");
			var print = document.getElementById("print");
			if(obj && main && print) {
				print.innerHTML = obj.innerHTML;
				print.className = obj.className;
				main.className = "doNotPrint";
				window.print();
				print.innerHTML = "";
				main.className = "";
			} else {
				window.print();
			}
		}
	}
	
	// SUBMENU
	
	var submenu_content = new Array();
		
	function show_submenu(num,mode)
	{
		var x = 0;
		var y = 0;
		var i = 0;
		var submenu = document.getElementById("submenu");
		if(submenu.style.visibility=="visible") {
			close_submenu();
		} else {
			var submenubg = document.getElementById("submenubg");
			var obj = document.getElementById("submenu"+num);
			var title = obj.innerHTML;
			if(mode=="under") {
				if(obj.offsetHeight) { y = obj.offsetHeight; }
				else if(obj.style.pixelHeight) { y = obj.style.pixelHeight; }
				y = y + 4;
			}
			while (obj!=null) {
				x+=obj.offsetLeft; // -obj.scrollLeft;
				y+=obj.offsetTop; // -obj.scrollTop;
				obj=obj.offsetParent;
				i++;
			}
			submenu.innerHTML = submenu_content[num];
			submenu.style.left = x + "px";
			submenu.style.top = y + "px";
			submenu.style.visibility = "visible";
			submenubg.style.visibility = "visible";
			if(mode=="under") { submenubg.onmouseout = function(){ document.getElementById("submenubg").onmouseover = function(){ close_submenu(); } } }
			else { submenubg.onmouseover = function(){ close_submenu(); } }
			window.setTimeout("close_submenu()",20000);
		}
	}
	
	function close_submenu()
	{
		var submenu = document.getElementById("submenu");
			var submenubg = document.getElementById("submenubg");
		submenu.style.visibility = "hidden";
		submenubg.style.visibility = "hidden";
		submenubg.onmouseout = null;
		submenubg.onmouseover = null;
	}
	
	
	// IMAGE POPUP
	
	var intextPadding = 12;
	var maxIntextWidth = 600;
	var maxIntextHeight = 700;
	
	var popup_style = "background-color: rgb(255,255,255); border: 1px rgb(125,125,125) solid;";
	var img_style = "background-color: rgb(200,200,200);";
	
	var popup_loader = "/images/themes/fs/popup/loader.gif";
	var popup_background = "/images/themes/fs/popup/background.png";
	var popup_none = "/images/themes/fs/popup/none.gif";
	
	var margin = 15;
	var loaderWidth = 38;
	var loaderHeight = 38;
	
	if( location_host!=host_subdomain ) 
	{
		popup_loader = 'http://' + host_subdomain + popup_loader;
		popup_background = 'http://' + host_subdomain + popup_background;
		popup_none = 'http://' + host_subdomain + popup_none;
	}
	
	var popup_bg_code =  '<div id="popup_bg" style="white-space: pre; display: none; z-index: 1000; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background-image: url(\''+popup_background+'\');" onclick="hide_popup()"><\/div><div id="popup_frame" style="z-index: 1001; display: none; position: fixed; overflow: hidden; -moz-user-select: none; -khtml-user-select: none; text-align: center; '+popup_style+'" onclick="hide_popup()"><a href="javascript:hide_popup()"><img id="loader_img" src="'+popup_loader+'" border="0" style="margin: '+margin+'px;" width="'+loaderWidth+'" height="'+loaderHeight+'" /><img id="popup_img" src="'+popup_none+'" border="0" style="margin: '+margin+'px;'+img_style+'" title="Click to close this image" /><\/a><div id="popup_nav" style="display: none;"></div><\/div>';
	
	var debug = false;
	
	var winWidth = 0;
	var winHeight = 0;
	var winMaxHeight = 0;
	var winLeft = 0;
	var winTop = 0;
	var navHeight = 0;
		
	var imgWidth = 0;
	var imgHeight = 0;
		
	var ratio = 1;
	var step = 10;
		
	var popup_bg = 0;
	var popup_frame = 0;
	var popup_img = 0;
	var loader_img = 0;
	var main_body = 0;
	var popup_nav = 0;
	
	var img_src = new Array();
	var img_count = 0;
	var img_num = 0;
	
	var new_image = new Image();
	
	var useragent = navigator.userAgent;
	
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChStart = strChUserAgent.substring(0,intSplitStart);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	var strChEnd = strChUserAgent.substring(strChEnd);
	
	if(strChMid.indexOf("MSIE 7") != -1)
		useragent = "IE7";
	else if(strChMid.indexOf("MSIE 6") != -1)
		useragent = "IE6";
	else if(strChMid.indexOf("MSIE 5") != -1)
		useragent = "IE5";
	else if(strChEnd.indexOf("Firefox/2") != -1)
		useragent = "firefox 2";
	else if(strChEnd.indexOf("Firefox") != -1)
		useragent = "firefox";
	else if(strChEnd.indexOf("Netscape/7") != -1)
		useragent = "netscape 7";
	else if(strChEnd.indexOf("Netscape") != -1)
		useragent = "netscape";
	else if(strChStart.indexOf("Opera/9") != -1)
		useragent = "Opera";
	else if(strChStart.indexOf("Opera") != -1)
		useragent = "Opera";
	else
		useragent = useragent;
	
	var popup_images = Array();
	
	function GetElement(string)
	{
		if(document.getElementById) element = document.getElementById(string);
		else if(document.all) element = document.all[string];
		if(!element) { elements = document.getElementsByTagName(string); element = elements[0]; }
		return element;
	}	
	
	function show_popup(img_list)
	{
		img_src = img_list.split(' ');
		img_count = img_src.length;
		img_num = 0;
		nav_popup(0);
		document.onkeydown=handle_keys;
	}	
	
	function nav_popup(nav_step)
	{	
		if( (img_num+nav_step)>=0 && (img_num+nav_step)<img_count ) 
		{
			img_num = img_num+nav_step;
			if( useragent=="IE5" || useragent=="IE6")
			{
				window.open(img_src[img_num],'image','scrollbars=yes,resizable=yes,dependent=yes,fullscreen=yes');
			}
			else
			{
				try	
				{	
					navHeight = 0;
			
					winWidth = main_body.clientWidth;
					winHeight = main_body.clientHeight;
					winMaxHeight = main_body.scrollHeight;
					winLeft = main_body.scrollLeft;
					winTop = 0; // main_body.scrollTop;
					
					step = 5;
					
					if(img_count>1) {
						var nav="<small>";
						if(img_num-1>=0) { 
							
							nav+='<a href="javascript:nav_popup(-1);">previous</a>';
						} else {
							nav+='previous';
						}
						nav+="&nbsp;";
						for(i=1;i<=img_count;i++) {
							if(i!=img_num+1)
								nav+='<a href="javascript:nav_popup('+(i-img_num-1)+');">'+i+'</a>&nbsp;';
							else
								nav+='['+i+']&nbsp;';
						}
						if(img_num+1<img_count) { 
							nav+='<a href="javascript:nav_popup(+1);">next</a>';
						} else {
							nav+='next';
						}
						nav+="<br /><small><i>Use left and right arrow keys to easely navigate.</i></small></small>";
						popup_nav.innerHTML = nav;
						popup_nav.style.display = "block";
						navHeight = 40;
					}
					
					popup_frame.style.width = loaderWidth+2*margin+"px";
					popup_frame.style.height = loaderHeight+2*margin+navHeight+"px";
					
					popup_frame.style.left = Math.floor((winWidth-loaderWidth-2*margin)/2)+"px";
					frameTop = winTop + Math.floor((winHeight-loaderHeight)/2);
					if(frameTop<margin) frameTop = margin;
					popup_frame.style.top = frameTop+"px";
					
					popup_bg.style.display = "block";
					popup_frame.style.display = "block";
					popup_img.style.display = "none";
					loader_img.style.display = "block";
					
					check_popup();
					
					if(useragent=="Opera")
					{
						new_img = new Image();
						new_img.src = img_src[img_num]; 
						
						popup_img.style.maxWidth = "1";
						popup_img.style.maxHeight = "1";
						popup_img.style.display = "block";
						popup_img.onload = img_loaded;
						popup_img.src = img_src[img_num];
					}
					else
					{
						new_img = new Image();
						new_img.onload = img_loaded;
						new_img.src = img_src[img_num]; 
					}
				}
				catch(err)
				{
					window.open(img_src[img_num],'image','scrollbars=yes,resizable=yes,dependent=yes,fullscreen=yes');
				}
			}
		}
	}
	
	function img_loaded()
	{
		
		if(useragent=="Opera")
		{
			popup_img.onload = "";
			popup_img.style.maxWidth = "";
			popup_img.style.maxHeight = "";
			imgWidth = new_img.width;
			imgHeight = new_img.height;
		}
		else
		{
			popup_img.style.display = "none";
			imgWidth = new_img.width;
			imgHeight = new_img.height;
			popup_img.src = new_img.src;
			delete new_img;
		}
		
		winWidth = main_body.clientWidth;
		winHeight = main_body.clientHeight;
		winMaxHeight = main_body.scrollHeight;
		winLeft = main_body.scrollLeft;
		winTop = 0; // main_body.scrollTop;
		
		var wratio = 1;
		var hratio = 1;
		
		ratio = 1;
		
		if(imgWidth<10) imgWidth = popup_img.width;
		if(imgHeight<10) imgHeight = popup_img.height;
		
		/*
		if(imgWidth<300 && imgHeight<300) 
		{ 
			imgWidth = 2*imgWidth; 
			imgHeight = 2*imgHeight;
		}
		*/
		
		if(imgWidth>(winWidth-2*margin)) { wratio=(imgWidth+4*margin)/(winWidth); } 
		if(imgHeight>(winHeight-3*margin)) { hratio=(imgHeight+6*margin)/(winHeight); }  
		
		if(wratio>hratio) ratio=wratio; else ratio=hratio; 
		
		imgWidth = Math.floor(imgWidth/ratio);
		imgHeight = Math.floor(imgHeight/ratio);
		
		popup_img.width = imgWidth;
		popup_img.height = imgHeight;
		
		popup_frame.style.width = imgWidth+2*margin+"px";
		popup_frame.style.left = Math.floor((winWidth-imgWidth-2*margin)/2)+"px";
		
		loader_img.style.display = "none";
		
		popup_img.style.display = "block";
		
		if(debug) GetElement("popup_bg").innerHTML = "url => "+img_src[img_num]+"\rwin => w "+winWidth+" - h "+winHeight+" \rimg => w "+imgWidth+" - h "+imgHeight+"\rratio = >"+ratio+" / margin = >"+margin+"\rdisplay => "+popup_img.style.display;
		
		resize_popup();
	}
	
	function check_popup()
	{
		winWidth = main_body.clientWidth;
		winMaxHeight = main_body.scrollHeight;
		
		popup_bg.style.height = winMaxHeight;
		popup_bg.style.width = winWidth;
		
		if(popup_bg.style.display=="block") setTimeout("check_popup()",500);
		if(step==0) popup_frame.style.left = Math.floor((winWidth-imgWidth-2*margin)/2)+"px";
	}
	
	function get_parent_box(my_node)
	{
		var count = 0;
		try {
			while( my_node.tagName!="body") {
				count++;
				my_node = my_node.parentNode;
				if( my_node.tagName=="div" || my_node.tagName=="DIV" || count>10) { return my_node; }
			}
		}
		catch(err) {
			// alert(count + " => " + err); 
			return my_node;
		}
	}
	
	function img_checker(main_img)
	{
		try {
			parentBox = get_parent_box(main_img);
			if(parentBox.offsetWidth!=main_img.width)
				maxWidth = parentBox.offsetWidth - 2*intextPadding;
			else
				maxWidth = parentBox.offsetWidth;
		}
		catch(err) { maxWidth = maxIntextWidth; }
		
		maxHeight = maxIntextHeight;
		
		imgWidth = main_img.width;
		imgHeight = main_img.height;
		
		if(imgHeight>1.5*imgWidth) {
			maxHeight = maxWidth - intextPadding;
		}
		
		if(imgHeight>1.5*maxWidth) {
			maxHeight = 1.5*maxWidth;
		}
		
		var wratio = 1;
		var hratio = 1;
		
		ratio = 1;
		
		if(imgWidth>maxWidth) { wratio=imgWidth/maxWidth; }
		if(imgHeight>maxHeight) { hratio=imgHeight/maxHeight; } 
		
		if(wratio>hratio) ratio=wratio; else ratio=hratio;
		
		if(ratio>1) 
		{ 
			imgWidth = Math.floor(imgWidth/ratio);
			imgHeight = Math.floor(imgHeight/ratio);
		
			main_img.width = imgWidth;
			main_img.height = imgHeight;
			
			var main_img_has_link = false; 
			try { 
				var main_img_parent = main_img.parentNode;
				if( main_img_parent.tagName=="a" || main_img_parent.tagName=="A" ) { main_img_has_link = true; }
			}
			catch(err) { main_img_has_link = true; }
			if(!main_img_has_link) {
				main_src = main_img.src;
				main_img.style.cursor = "pointer";
				main_img.onclick = new Function('show_popup("'+main_src+'");');
			}
		}
	}
	
	function resize_popup()
	{
		step--;
		
		if(imgHeight>800 && imgWidth>900) step = 0;
		
		if(step>0)
		{
			// if(imgHeight<600 && imgWidth<600) popup_img.height = Math.floor(imgHeight/step);
			popup_frame.style.height = Math.floor(imgHeight/step)+2*margin+navHeight+"px";
			frameTop = winTop + Math.floor((winHeight-imgHeight/step)/2);
			if(frameTop<margin) frameTop = margin;
			popup_frame.style.top = frameTop+"px";
			setTimeout("resize_popup()",50);
		}
		else
		{
			popup_img.height = imgHeight;
			popup_frame.style.height = imgHeight+2*margin+navHeight+"px";
			frameTop = winTop + Math.floor((winHeight-imgHeight)/2);
			if(frameTop<margin) frameTop = margin;
			popup_frame.style.top = frameTop+"px";
		}
	}
	
	function hide_popup()
	{
		popup_bg.style.display = "none";
		popup_frame.style.display = "none";
	}
	
	function handle_keys(evt) 
	{
		if(	popup_frame.style.display=="block" )
		{
			evt = (evt) ? evt : ((window.event) ? event : null);
			if (evt) 
			{
				switch (evt.keyCode) 
				{
					case 37:
						nav_popup(-1);
						return false; 
						break;	
					case 39: 
						nav_popup(+1);
						return false; 
						break;	
					case 8 : // Retour arriere
					case 13 : // Retour chariot
					case 27 : // Echappement
					case 127 : // Effacement
						hide_popup();
						return false; 
						break;	
					case 38:
						// up
						break;	
					case 40:
						// down;
						break;	
				}
			}
		}
	}
	
	document.write(popup_bg_code);
	
	popup_bg = GetElement("popup_bg");
	popup_frame = GetElement("popup_frame");
	popup_img = GetElement("popup_img");
	main_body = GetElement("body");
	loader_img = GetElement("loader_img");
	popup_nav = GetElement("popup_nav");


