/* 

	Author: Greg Gawlik - Web Designers
	        http://www.webdesigners.pl/

*/

/* Chmurki informacyjne */

var toolTip = 
{
	makeToolTips: function(className) {
		
		var d = document;
		var objects = getElementsByClassName(className);
		
		if(isArray(objects)) {
			
			for(var i=0; i<objects.length; i++) {
				
				objects[i].className = "tooltip";
				var CloudNode = objects[i];
				
				var content_button = "?";
				var content_cloud = CloudNode.innerHTML;
				
				content_cloud = content_cloud.replace(/^\(/gi, '');
				content_cloud = content_cloud.replace(/\)$/gi, '');
				
				if(CloudNode.hasChildNodes())
				   while (CloudNode.firstChild)
		    		      CloudNode.removeChild(CloudNode.firstChild);
		    		
		    		CloudNode.innerHTML = "<SPAN CLASS=\"tt_button\"><SPAN></SPAN>" +  content_button + "</SPAN>";
		    		CloudNode.innerHTML += "<SPAN CLASS=\"tt_cloud\"><SPAN></SPAN>" + content_cloud + "</SPAN>";
		    		
		    		CloudNode.onmouseover = function() { this.className += ' hover'; }
		    		CloudNode.onmouseout = function()  { this.className = this.className.replace(" hover", ""); }
			}
		}
	},
	
	initNow: function(className) {
		
		this.makeToolTips(className);
	}
}

/* Mapa lokalizacji */

var mapa = 
{
	makeMapa: function() {
		
		var d = document;
		var object = getElementsByClassName("gdzie_dzialamy");
		
		if(isObject(object[0]))
		  {
		  	var ullists = object[0].getElementsByTagName("ul");
		  	var ullist = ullists[0];
			
			var anchors = ullist.getElementsByTagName("a");
			
			for(var i=0; i<anchors.length; i++) {
			
				anchors[i].onclick = this.changeMap;
			}
		  }
		
	},
	changeMap: function() {
		
		var parent_id = this.parentNode.parentNode.id;
		var ullist = this.parentNode.parentNode.parentNode;
		
		ullist.className = parent_id;
		
		return false;
	},
	initNow: function() {
		
		this.makeMapa();
	}
}

/* Inteligentne pola formularza */

var smartFields =
{
	makeSmartFields: function () {
	
		var d = document;
		var a = sfArray;
		
		for (x in a)
		{
			var id = x;
			var value = a[x];
			var f = d.getElementById(id);
			
			if(!isNull(f))
			  {
				f.onblur = this.a_onblur;
				f.onfocus = this.a_onfocus;
			  }
		}
	},
	
	a_onblur: function() {
	
		if(this.value == "") { this.value = sfArray[this.id]; }
	},
	
	a_onfocus: function() {
		
		if(this.value == sfArray[this.id]) { this.value = ""; }
	},
	
	initNow: function() {

		this.makeSmartFields();
	}
};

/* Nagłówek flash na stronie głównej */

function pokaz_flash_naglowek(od_nowa) {

	if(checkDOM() && swfobject.hasFlashPlayerVersion("8"))
	  {
		var d = document;
		
		var flash_plik = "flash/preloader.swf";
		var flash_width = "900";
		var flash_height = "374";
		
		var obj = d.getElementById("ilustracja_naglowek");
		obj.className = "flash_naglowek";
		
		if(obj.hasChildNodes())
		   while (obj.firstChild)
    		      obj.removeChild(obj.firstChild);
		
		var adddiv=d.createElement('div');
		adddiv.setAttribute("id", "animacja_flash_kontener");
		obj.appendChild(adddiv);
		
		var flashvars = {nowa_sesja: od_nowa};
		var params = {wmode: "opaque", scale: "noscale", salign: "TL", menu: "false"};
		var attributes = {};

		swfobject.embedSWF(flash_plik, "animacja_flash_kontener", flash_width, flash_height, "8.0.0", "expressInstall.swf", flashvars, params, attributes);
	  }
}

/* Dodatkowe funkcje */

function checkDOM() {
	
	var d = document;
	var db = d.body;
	
	if(!db || !db.getElementsByTagName || !d.getElementById) 
	  { return false; }
	else
	  { return true; }
}

function getElementsByClassName(cn) {
  var arr = new Array(); 
  var els = document.getElementsByTagName("*");
  var exp= new RegExp("^(.* )?"+cn+"( .*)?$", "g");
  for (var i = 0; i < els.length; i++ ){
    if (exp.test(els[i].className)){
      arr.push(els[i]);
    }
  }
  return arr;
}

/* Funkcje sprawdzające */

function isNull(a) {
    return typeof a == 'object' && !a;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isString(a){
    return typeof a == 'string';
}
function isNumber(a){
    return typeof a == 'number';
}
function getCookieVal (offset) {

	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

/* Funkcje do Cookie */

function GetCookie (name) {

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {

		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;

	}
	return null;
}
function SetCookie (name, value, expires, path, domain, secure) {

    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}
function DeleteCookie (name) {

	var exp = new Date();
	exp.setTime (exp.getTime() - 1);  // This cookie is history
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

/* Ustawienia wartości domyślnych dla pól */

var sfArray = new Array();
sfArray["tresc_listu"] = "Treść listu...";
sfArray["imie_nazwisko_nazwa_firmy"] = "Imię i nazwisko / nazwa firmy...";
sfArray["adres"] = "Adres...";
sfArray["telefon"] = "Telefon...";
sfArray["email"] = "E-mail...";

/* Inicjacja */

function initNow() {

	if(checkDOM())
	  {
		smartFields.initNow();
		toolTip.initNow('chmurka');
		mapa.initNow();
	  }
}
