/*
* JavaScript files were generated by the PHP JavaScript Generator
* ver. 1
* Copyright 2008 Marek Stankala
* All Rights Reserved
* Contact: stankala@wp.pl
*/
/*
* File common.js
* Copyright 2008 Marek Stankala 
* All Rights Reserved
* Contact: stankala@wp.pl
*/

function displayWindow(url, width, height)
{ 
	var Win=window.open(url,"displayWindow",'width='+width+',height='+height+',left=50,top=50,resizable=no,scrollbars=no,menubar=no');
}

/*
* File engine.js
* Copyright 2008 Marek Stankala 
* All Rights Reserved
* Contact: stankala@wp.pl
*/

var Engine = {
	
	//Sets the dimensions of the site elements
	// to allow scroll
	theContent : null,
	scrollDim : null,
	content : null,
	footer : null,
	topnav : null,
	themenu : null,
	contentHolder : null,
	//the size of the rounded coreners: top and bottom
	borders: 20,
	scrollImg : 45,
	ie : navigator.appVersion.indexOf("MSIE"),	
	minContentHeight : 150, //px
	
	setDimensions :function() {
		
		/*if (document.body) {
			document.body.style.overflow = "auto";
		}
		else if (document.documentElement) {
			document.documentElement.style.overflow = "auto";
		}*/
		var windowH = this.getWindowHeight();
		//SHOW SCROLL BARS TO GET THE REAL WINDOW HEIGHT
		/*if (document.body) {
			document.body.style.overflow = "";
		}
		else if (document.documentElement) {
			document.documentElement.style.overflow = "";
		}*/
		
		if (windowH && windowH != 0) {
			// beacuse of Ajax Requests the elements have to be initialized againg - can't be stored in objects
			 
			this.content = document.getElementById("innerContent");
			
			this.leftNav = document.getElementById("leftnavigation");
		
			this.contentHolder = document.getElementById("content");
			
			this.theContent = document.getElementById("theContent");
		
			this.footer = document.getElementById("footer");
		
			this.topnav = document.getElementById("topNavigation");
	
			this.themenu = document.getElementById("themenu");
			
			this.scrollDim = document.getElementById("scrolldim");
				
			if (this.content && this.topnav && this.footer) {
				var footerH = this.getElementHeight(this.footer);
				var topNavH = this.getElementHeight(this.topnav);
				var themenuH = this.getElementHeight(this.themenu);
				var contentH = this.getElementHeight(this.contentHolder);
				var leftNavH = this.getElementHeight(this.leftNav);
				
				
				var clientH = this.getClientDim().y;
				
				var valueH = windowH-topNavH-themenuH-this.borders;
				var valueInnerH = clientH-topNavH-themenuH-this.borders;
				
				if (valueInnerH > 1) {
					if (leftNavH <= this.minContentHeight) {
						leftNavH = this.minContentHeight;
					}
					
					if (leftNavH <= (valueInnerH - footerH)) {
						this.theContent.style.height = (valueInnerH - footerH) + "px";
						this.scrollDim.style.height = (valueInnerH - footerH - this.scrollImg) + "px";
					}
					else {
						this.theContent.style.height = (leftNavH) + "px";
						this.scrollDim.style.height = (leftNavH - this.scrollImg) + "px";
					}
				}
				clientH = null;
				valueH = null;
				valueInnerH = null;
			}
		}
		windowH = null;
	},
	
	//Returns the element height 
	getElementHeight : function(elem) {
		if (elem.style.pixelHeight) { 
			return parseInt(elem.style.pixelHeight);
		} else {
			return parseInt(elem.offsetHeight);
		}
	},
	
	//Method returns window height value 
	getWindowHeight :function() {
		if (window.innerHeight) {
			return parseInt(window.innerHeight);
		}
		else if (document.body && document.body.clientHeight) {
			return parseInt(document.body.clientHeight);
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			return parseInt(document.documentElement.clientHeight);			
		}
		else {
			return 800;
		}
	},
	
	//Method returns window width value
	getWindowWidth :function() {
		if (window.innerWidth) {
			return parseInt(window.innerWidth);
		}
		else if (document.body && document.body.clientWidth) {
			return parseInt(document.body.clientWidth);
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			return parseInt(document.documentElement.clientWidth);			
		}
		else {
			return 1000;
		}
	
	},
	
	getClientDim : function() {
		var theWidth = 0;
		var theHeight = 0;
		// Window dimensions:
		if (window.innerWidth) {
			theWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			theWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
			theWidth=document.body.clientWidth;
		}
		if (window.innerHeight) {
			theHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			theHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
			theHeight=document.body.clientHeight;
		}
		return { x:parseInt(theWidth), y:parseInt(theHeight) };
	}
	 
}
/*
* File menu.js
* Copyright 2008 Marek Stankala 
* All Rights Reserved
* Contact: stankala@wp.pl
*/

// Array.indexOf(value) - Return index of the first element that matches value
Array.indexOf || (Array.prototype.indexOf = function(v,n){
  n = (n==null)?0:n; var m = this.length;
  for(var i = n; i < m; i++)
    if(this[i] == v)
       return i;
  return -1;
});


var Menu = {
		//page_base_page
		basePage : "index.php?id=",
		//Block next ajax call
		blockAjax : false,
		//Keeps the Scroll to value after the page is loaded
		scrollTo : null,
		//Keeps the actually page id - inlcuding ajax requests page ids
		activePageId : null,
		// Array that keeps the nodes and the id activity
		nodesIdActivities : null,
		// Keeps the menu buttons objects
		menuButtons : null,
		
		//Initialize the menu - mouseover and mouseout events
		init : function(id) {
			var navRoot = document.getElementById(id);
			if (navRoot != null) {
				this.menuButtons = new Array();
				for (var i=0; i<navRoot.childNodes.length; i++) {
					var node = navRoot.childNodes[i];
					if (node.nodeName.toLowerCase()=="li") {
						
						//Add the menu button object to the array
						this.menuButtons.push(node);
												
						var self = this;
						node.onmouseover=function() {							
							this.className+=" over";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}
						
						node.onclick = function() {
							this.className=this.className.replace(" over", "");
						}
					}
				}
			}
		},
		//Initialize the Ajax
		initAjax : function(id) {
			var node = document.getElementById(id);
			if (node) {
				var link = node.getElementsByTagName("a");
				if (link != null && link.length != 0) {
					for (var i=0; i<link.length; i++) {
						//alert(link[i].href);
						if (link[i].href != "javascript:void(0);"
							&& link[i].href.indexOf("mailto:") == -1) {
							// If id for the destination page is specified -> attach Ajax							
							var pageId = this.getParameter(link[i].href,"id");							
							if (pageId != null && escape(pageId) != "") {
															
								var ajaxParam = "ajax=true";
																						
								//If top link clicked - fix the url
								if (link[i].href.indexOf("#top") != -1) {
									link[i].href = link[i].href.replace("#top","");
								}
								//If another # param exists, cut it and paste it at the end of the url
								var hashParam ="";
								//if () alert(link[i].hash);
																
								if (link[i].href.indexOf("#") != -1) {
									hashParam = link[i].href.substr(link[i].href.indexOf("#"),link[i].href.length-link[i].href.indexOf("#"));
									link[i].href = link[i].href.replace(hashParam,"");
								}
														
								if (link[i].href.indexOf("?") == -1) {	
									ajaxParam = "?" + ajaxParam;
								} else {
									ajaxParam = "&" + ajaxParam;
								}
															
								// Adds an Ajax onClick event to the menu button element 
								// corresponding to the link onClick event.
								if (link[i].parentNode 
									&& link[i].parentNode.tagName 
									&& link[i].parentNode.tagName.toLowerCase() == "div"
									&& link[i].parentNode.className.indexOf("menu_content") != -1) {
									link[i].parentNode.onclick = function(e) {
										var ev = (e? e : window.event);
										var el = (ev.target ? ev.target : ev.srcElement);									
										if (el.getElementsByTagName("a").length > 0) {
											eval(unescape(this.getElementsByTagName("a")[0].href));
										}
									};								
								}
								// Replace the default link action with the Ajax request
								link[i].href = "javascript:Menu.getRequest(Menu.callback_onClick,'" + escape(link[i].href) + ajaxParam + hashParam + "');";
							}
													
						}
					}
				}
			}
		},
		//Gets the Ajax request by the sepcified params
		getRequest : function(callback_function, url) {
			if (!this.blockAjax) {
				this.blockAjax = true;
				try { // Mozilla, Safari, Opera ...
	 				http_request = new XMLHttpRequest();
	 				http_request.overrideMimeType('text/xml');
	 				
				} catch(e){ // IE
	    			http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    		}
	    		
				http_request.onreadystatechange = callback_function;
				
				http_request.open('POST', url, true);
				//Add headers
	            Menu.addHeaders(http_request,url.length);
                /* Force "Connection: close" for Mozilla browsers to work around
                 * a bug where XMLHttpReqeuest sends an incorrect Content-length
                 * header. See Mozilla Bugzilla #246651.
                 */
                if (http_request.overrideMimeType)
    	            http_request.setRequestHeader('Connection', 'close');
				
				//Keeps the requestes page id by the url - used in callback method
				this.activePageId = this.getParameter(url,"id");
				//Keeps the page scrool value by url parameter 
				this.scrollTo = this.getParameter(url,"scrollTo");
				//sends the Ajax request 
				http_request.send(null);
				
				//Init Google Analytics
				Menu.initGoogleAnalytics("/" + this.basePage + this.activePageId);
								
				this.preloader("");
			}    	
		},
		
		//Returns the parameter by the url		
		getParameter : function( queryString, parameterName ) {
			// Add "=" to the parameter name (i.e. parameterName=value)
			var parameterName = parameterName + "=";
			if ( queryString.length > 0 ) {
				// Find the beginning of the string
				begin = queryString.indexOf ( parameterName );
				// If the parameter name is not found, skip it, otherwise return the value
				if ( begin != -1 ) {
					// Add the length (integer) to the beginning
					begin += parameterName.length;
					// Multiple parameters are separated by the "&" sign
					end = queryString.indexOf ( "&" , begin );
					if ( end == -1 ) {
						end = queryString.length
					}
					// Return the string
					return unescape ( queryString.substring ( begin, end ) );
				}
				// Return "null" if no parameter has been found
				return "null";
			}
		},
		
		getRequestObject : function() {
			try { // Mozilla, Safari, Opera ...
 				http_request_obj = new XMLHttpRequest();
 				http_request_obj.overrideMimeType('text/xml');
 				
			} catch(e){ // IE
    			http_request_obj = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		return http_request_obj;
		},
		
		//The Ajax callback method - called on Server Response
		callback_onClick : function(response) {
			try {
	            if (http_request.readyState == 4) {
	                if (http_request.status != 404) {
	                    //alert(http_request.responseText);
	                    var content = document.getElementById("content");
	                    if (content != null) {
	                    	content.innerHTML = http_request.responseText;	                    	
	                    	//Set the dimensions after load
	                    	Engine.setDimensions();
	                    	
	                    	//Init left nav and footer once again
	                    	Menu.initLeftNav();
	                    	//Menu.initFooter();
	                    	//Sets the active menu button
	                    	Menu.setActiveButton(Menu.activePageId);
	                    	//clear the value
	                    	Menu.activePageId = null;

							Menu.scrollPage(Menu.scrollTo);
	        				Menu.scrollTo = null;	
	        
	        				req = Menu.getRequestObject();
	                    	//sets the callback method
	                    	req.onreadystatechange = Menu.setTitleAjax;
	                    	//Openes and sends the request
	                    	var titlePage = "title.php";
	                    	req.open("POST", titlePage, true);
	              			//Add headers
	              			Menu.addHeaders(req, titlePage.length);
							req.send(null);
							
							Menu.preloader("none");                    	
	                    }
	                } else {
	                    //alert("Menu Class callback_onClick() error.");
	                }
	            }
	        }
	        catch( e ) {
	        	//Unlock next Ajax requests
	        	if (Menu) {Menu.blockAjax = false;}
	        	Menu.preloader("none");
	        }
		},
		
		//Adds information to the request http headers 
		addHeaders : function(httpRequest, contentLength) {
			var requestHeaders =
                   ['X-Requested-With', 'XMLHttpRequest',
                    'Accept', 'text/javascript, text/html, application/xml, text/xml, */*',
                    'Content-type', 'application/x-www-form-urlencoded;charset=utf-8',                         
                    'Content-length', contentLength];

           for (var i = 0; i < requestHeaders.length; i += 2)
            httpRequest.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
		},
		
		//permanent activation of a menu button by the corresponding id url parameter
		setActiveButton : function(idParam) {
			if (idParam && this.nodesIdActivities && this.menuButtons) {
				
				this.deactivateButtons();
				
				//The array contains strings e.g. 3,4,5				
				for (var i=0; i< this.nodesIdActivities.length; i++) {
					var idxArray = this.nodesIdActivities[i].split(",");//indexOf(idParam+"");					
					//If array item string contains the idParam
					//Activate the button
					for (var j=0; j<idxArray.length; j++){
						//Id ids are ther same
						if (idxArray[j] == idParam+"") {
							this.activateButton(this.menuButtons[i]);
							break;	
						}
					}
				}
			}
		},
		//Activates a menu buttons
		activateButton : function(button) {										
			button.className+=" active";
		},
		//Deactivates all menu buttons
		deactivateButtons : function() {
			if (this.menuButtons && this.menuButtons.length > 0) {
				for (var i=0; i<this.menuButtons.length; i++) {
					this.menuButtons[i].className = this.menuButtons[i].className.replace(" active", "");
				}
			}
		},
		
		//Scrolls the page content to the specified value
		scrollPage : function(scrollVal) {
			var content = document.getElementById("theContent");
			if (content) {
				if (scrollVal && escape(scrollVal) != "") {
					content.scrollTop = parseInt(scrollVal);
				} else {
					content.scrollTop = 0;
				}
			}
		},
		
		baner : null,
		setTitleAjax : function(response) {
			try {
				if (req.readyState == 4) {                
	                if (req.status != 404) {
	                	eval(req.responseText.replace(/\r\n/g,""));
						document.title = title;
						if (this.baner != baner) {
							this.baner = baner;
							//Replace the Baner Image if required
							var img = document.getElementById("banerImg"); // 
                            var flashcontent= document.getElementById("flashcontent"); //							
							
					        if (baner.indexOf(".swf") != -1) {
                                img.style.display = "none";
                                flashcontent.style.display = "";
                            }
                            else if (img != null) {
                                img.src = baner;
                                flashcontent.style.display = "none";
                                img.style.display = "";
                            }
						}						
					}
				}
				//Unlock next Ajax requests
				Menu.blockAjax = false;
						
			} catch(e)
			{ 
				//Unlock next Ajax requests
				if (Menu) {Menu.blockAjax = false;} 
			}
		},
		
		initLeftNav : function() {			
			Menu.initAjax("leftnavigation");
		},
		
		initFooter : function() {
			Menu.initAjax("footer");
		},
		initGoogleAnalytics : function(page) {
			try {
				urchinTracker(page);
				pageTracker._trackPageview(page);
			} catch(e) {}
		},
		
		preloader : function(display) {
			var preloader = document.getElementById("preloader");
			if (preloader != null) {
				preloader.style.display = display;	
			}
		}
}

/*
* File scroll.js
* Copyright 2008 Marek Stankala 
* All Rights Reserved
* Contact: stankala@wp.pl
*/

var Scroll = {
	ie : navigator.appVersion.indexOf("MSIE"),
	innerContent : null,
	interv : null,
	max : 40, // max scroll speed
	step : 1, 
	timeout : 20,
	inc : 1,
	oneClickScroll : 20,
	
	init : function() {
		this.innerContent = document.getElementById("theContent");
	},
	up : function(oneClickVal) {
		this.init();		
		if (oneClickVal) {
			if (this.innerContent.scrollTop - oneClickVal >= 0) {
				this.innerContent.scrollTop -= oneClickVal;
			}
			else {
				this.innerContent.scrollTop = 0;
			}
		}
		else {
			if (this.innerContent.scrollTop - this.inc >=0) {
				this.innerContent.scrollTop -= this.inc;
				this.speedup();
			}
			else {
				this.innerContent.scrollTop = 0;
			}
		}
	},
	down : function(oneClickVal) {
		this.init();
		if (oneClickVal) {
			this.innerContent.scrollTop += oneClickVal; 
		}
		else {
			this.innerContent.scrollTop += this.inc;
			this.speedup();
		}
		//window.status = this.inc; 
	},
	
	speedup : function() {
		if ((this.inc += this.step )<= this.max) {
			this.inc += this.step;
		}
		 else {
		 	this.inc  = this.max;
		 }
	},
	
	scroll : function(dir) {
		clearInterval(this.interv); 
		if (dir == "up") {
			Scroll.up(this.oneClickScroll);
			this.interv = setInterval(function(){Scroll.up();},this.timeout);	
		}
		else if (dir = "down") {
			Scroll.down(this.oneClickScroll);
			this.interv = setInterval(function(){Scroll.down();},this.timeout);
		}		
	},
	
	stop : function() {
		if (this.interv != null) {
			clearInterval(this.interv);
			this.interv = null;
			this.inc = 5;
		}		
	}
	
}

