String.prototype.test = function( str, where ) {
	str = 	str.replace(/\?/g, '\\?').replace(/\./g, '\\.').replace(/\^/g,'\\^').replace(/\$/g,'\\$').replace(/\+/g,'\\+')
			.replace(/\*/g,'\\*').replace(/\(/g,'\\(').replace(/\)/g,'\\)').replace(/\|/g,'\\|').replace(/\{/g,'\\{').replace(/\[/g,'\\[');
	var G = new RegExp('^.*'+str+'.*$','g');
	if ( where && where == 'first' ) {
		G = new RegExp('^'+str+'.*$','g');
	} else if ( where && where == 'last' ) {
		G = new RegExp('^.*'+str+'$','g');
	}
	return G.test(this);
};

function showHide(object) {
		var obj = $("#"+object);
		var arrow = $("#"+object+"_arrow");
		if ( obj.is(':visible') ) {
			obj.fadeOut();
			if(typeof arrow == 'object') arrow.attr('src',"/i/cf/citibank/blue_arrow_down.jpg");
		} else {
			obj.fadeIn();
			if(typeof arrow == 'object') arrow.attr('src',"/i/cf/citibank/blue_arrow_up.jpg");
		}
}

var f = function() {
	/* private */
	var months = ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'];
	var monthsDop = ['stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'];
	
	/* public */
	return {
		hideObjects: 	false,
		sortByColumn: 	false,

		insert: {
			css: function(href, antyCache) {
				if ( !href ) { return false;}

				if ( antyCache ) { href = href +'?antyCache='+new Date().getTime();	}
				$.ajax({
					type: "GET",
					url: href,
					dataType: 'html',
					async: false,
					success: function(data) { 
						var cssNode = document.createElement('link');
						cssNode.type = 'text/css';
						cssNode.href = href;
						cssNode.rel = 'stylesheet';
						cssNode.media = 'screen';
						cssNode.title = 'dynamicStyleSheet';
						document.getElementsByTagName("head")[0].appendChild(cssNode);				
					}
				});
			},
			js: function(href, antyCache) {
				if ( !href ) {return false;}
				if ( antyCache ) {
					href = href +'?antyCache='+new Date().getTime();
				}
				var newScript = document.createElement('script');
				newScript.type = 'text/javascript';
				newScript.src = href;
				document.getElementsByTagName("head")[0].appendChild(newScript);
			}
		},
	
		getParam: 		function(param, options) {
			var qstr = window.location.search;
			if ( options && options.searchFrom && options.searchFrom != '' ) {
				qstr = options.searchFrom;
			}
			if ( !options || !options.caseSensitive ) {
				// dotyczy zarowno wartosci zwracanej jak i nazwy zmiennej
				param = param.toLowerCase();
				qstr = qstr.toLowerCase();
			}
			if ( qstr.test('=') && qstr.test(param) ) {
				var tmp = new RegExp(".*[\\?\\&]+"+param+"=([\\w\\d]+).*").exec(qstr);
				if (tmp) {
					return tmp[1];
				}
			} else { 
				return false;
			}
		},
		
	
		wups: function(href, options) {
			var width = 620;
			var height = 630;
			var name = 'wupsWindow';
			if ( options && options.width && this.number.isInteger(options.width) ) {
				width = options.width;
			} 
			if ( options && options.height && this.number.isInteger(options.height) ) {
				height = options.height;
			}
			if ( options && options.name ) {
				name = options.name;
			}
			if ( name.length>10 ) {
				name = name.slice(0,10);
			}
			var parameters = 'menubar=no, toolbar=no, location=yes, width='+width+', height='+height+', left=30, top=30, scrollbars=yes, status=yes, resizable=yes';

			if ( options && options.html ) {

				var newWin = window.open('', name, parameters);
				with ( newWin.document ) {
					open('text/html', 'replace');
					write(html);
					close();
				};
			} else {

				var prid = f.getParam('prid');
				var pridHref = f.getParam('prid', href)
				if ( prid && !pridHref ) {
					if ( href.test('?') ) {
						href += '&prid='+prid;
					} else {
						href += '?prid='+prid
					}
				}
				var newWin = window.open(href, name, parameters);
				newWin.focus();
			}
			return true;
		}
	}
}();



var taber = function(){

	var showFirst 		= true;
	var manyContainers 	= false;
	var	inicjacja		= true;
	
	return { 
		init: 		function() {
			if ( ('.taber_container').length == 0 ) {
				return false;
			}
			var _self = this;
			$('.taber_container').each(function() {
				$(this).find('.taber_box').hide();
				var containerId = this.id || null;
				var containerObj = $(this);
				var taberMenus = containerObj.find('.taber_menu');
				var menu = null;
				
				if ( taberMenus.length == 0 ) {
					return false;
				} else if ( taberMenus.length == 1 ) {
					menu = taberMenus;
				} else if ( taberMenus.length > 1 ) {

					manyContainers = true;
					if ( containerId ) {
						menu = containerObj.find('.taber_menu[rel="'+containerId+'"]');
					} else { 
						menu = containerObj.find('.taber_menu:first');
					}
				} else {
					return false;
				}
				if ( !menu ) {
					return false;
				}
				$(menu).each( function() {
					var ustawionoAktywna = false;
					if ( showFirst ) {
						$(this).find('li a:first').each(function() {
							_self.show( this );
						});
						ustawionoAktywna = true;
					}
					$(this).find('li a').each(function() {
						var tabId = $(this).attr('href').slice(1);
						if ( _self.isMenuActive( $(this) ) ) {
							_self.show( $(this) );
							ustawionoAktywna = true;
						}
						$(this).click(function() {
							_self.show( $(this) );
							return false;
						});
						$(this).focus(function() { $(this).blur(); });
						$(this).hover(function() { 
							_self.onHover( $(this), 'over' ); 
							}, function(){
							_self.onHover( $(this), 'out' ); 
						});
					});
				});
			});
			if ( f.getParam('taber') && f.getParam('tab') ) {
				var _taber = f.getParam('taber', { caseSensitive: true });
				var _tab = f.getParam('tab', { caseSensitive: true });
				var link = $('#'+_taber+' .taber_menu li a[href="#'+_tab+'"]');
				if ( link && link.length > 0 ) {
					_self.show(link, { containerId : _taber , tabId: _tab } );
				}
			}
			inicjacja = false;
		},
		show: 		function(obj, options) {
			if ( arguments.length == 0 || !obj ) {return false;	}
			var _self = this;
			var link = null;
			if ( typeof obj == 'string' ) {
				if ( obj.test('#') ) {
					link = $('#'+obj.slice( obj.indexOf('#') + 1 ));
				} else if ( obj.test('.') ) {
					link = $('.'+obj.slice( obj.indexOf('.') + 1 ));
				} else { 
					link = $('#'+obj);
				}
			} else if ( typeof obj == 'object' ) {
				link = $(obj);
			} else {
				return false;
			}
			
			var containerId = null;
			var containerObj = null;
			var tabId = null;
			
			if ( options && options.containerId ) {
				containerId = options.containerId; 
				containerObj = $('#'+containerId);
			} else {
				var objTmp = link;
				while ( objTmp && !$(objTmp).hasClass('taber_container') ) {
					objTmp = $(objTmp).parent();
				}
				containerId = objTmp.attr('id') || null;
				containerObj = objTmp;
			}
			if ( options && options.tabId ) {
				tabId = options.tabId;
			} else {
				tabId = $(link).attr('href').slice( $(link).attr('href').indexOf('#')+1 );
			}
			containerObj.find('.taber_menu').each(function() {
				if ( !$(this).attr('rel') || !containerId || 
					( $(this).attr('rel')  && $(this).attr('rel') == containerId  ) ) {
						$(this).find('li a').each(function() {
							_self.setMenuActive( $(this), false );
						}); 
				}
			});
			
			if ( options && options.preCallback && typeof options.preCallback == 'function' ) {
				options.preCallback.call(link);
			}
			
			containerObj.find('.taber_box').not( containerObj.find('.taber_container .taber_box')).hide();
			
			_self.showTab ( $('#tab_'+tabId), (options ? options.postCallback ||  null: null ), link );
			
			_self.setMenuActive( $(link), true );
			
			containerIdold = containerId;
			containerId = false;
			tabId = false;
			

			if ( manyContainers && !inicjacja ) {
				while ( link && $(link).length > 0) {
					//	dla kazdej zakladki, sprawdzamy czy jest widoczna, jesli nie (a powinna), to ustawiamy tabId i pozniej pokazemy ja... 
					if ( link.hasClass('taber_box') && !link.is(':visible') ) {
						tabId = $(link).attr('id').slice(4);
					}
					//	sprawdzamy containerId dla zakladki, ktora chcemy pokazac
					if ( $(link).hasClass('taber_container') && $(link).attr('id') != containerIdold ) {
						containerId = $(link).attr('id');
					}
					//	jesli znalezlismy ukryta zakladke do pokazania i container, w ktorym sie znajduje, to szukamy linku do niej i pokazujemy ja.
					if ( tabId && containerId ) {
						var pLink = $('#'+containerId+' .taber_menu li a[href="#'+tabId+'"]');
						this.show( pLink, { containerId : containerId, tabId : tabId } )
						tabId = false;
						containerId = false;
					}
					link = $(link).parent();
				}
			}
			return false;
		},
		setMenuActive : function(obj, stan) {
			if ( stan ) {
				obj.addClass('active');
			} else {
				obj.removeClass('active');
			}
		},
		isMenuActive : function(obj) {
			return obj.hasClass('activeStart');
		},
		showTab : function (tab, postFn, link) {
			tab.fadeIn(function() {
				if ( postFn && typeof postFn == 'function' )  {
					postFn.call(link);
				}
			});
		},
		onHover : function( obj , status ) {
			if ( status == 'over' ) {
			} else if ( status == 'out' ) {
			}
		}
	}	
}();

var plusik = function(){
//TEST
	var showFirst				= true;			//	pokazuj automatycznie pierwszy plusik rozwinięty
	var showLinkAll				= true;			//	pokazuj linki rozwiń / zwiń wszystkie 
	var expand_from_hash		= false;		//  rozwin odpowieni plusik wg hasha
	
	function hideContent (obj) {
		if ( $(obj).parent().find('.plusik_plus_content').length > 0 ) {
			$(obj).parent().find('.plusik_plus_content').fadeOut();
		} else {
			//TEST/	
			//$(obj).parent().find('*').not('h6, h6 span, .dontTouchPlusik, .dontTouchPlusik *, script, style').fadeOut();
			$(obj).parent().children().not('h6, .dontTouchPlusik, script, style').fadeOut();
		}
		$(obj).removeClass('minus');
	}; 
	function showContent(obj) {
		if ( $(obj).parent().find('.plusik_plus_content').length > 0 ) {
			$(obj).parent().find('.plusik_plus_content').fadeIn();
		} else { 
			//TEST/
			//$(obj).parent().find('*').not('h6, h6 span, .dontTouchPlusik, .dontTouchPlusik *, script, style').fadeIn();
			$(obj).parent().children().not('h6, .dontTouchPlusik, script, style').fadeIn();
		}
		$(obj).addClass('minus');
	};
	
	return { 
		init : function() {
		
			$('.plusik_plus_box').each(function() {
		
				var hash = document.location.hash.slice(1);
				if($(this).hasClass('expand_from_hash')) {
					if(hash>"") showFirst=false;
					expand_from_hash = true;
				}
				
				$(this).find('.plusik_plus > h6').each(function(){
					$(this).addClass('plus').css('cursor','pointer');
						
					var plusik_id = $(this).parent().attr('id');
					if(plusik_id>"") {							// jezeli plusik ma ID
						if(expand_from_hash) { 			// jezeli patrzymy na hash
							if(plusik_id==hash) { 		// jezeli znalezlismy plusik
														//nic nie robimy (nie zamykamy)
							} else {
								hideContent(this);
							}
						}else{ 									// jezeli nie patrzymy na hash
							hideContent(this);
						}
					} else { //jezeli plusik nie ma ID
						hideContent(this);
					}
					/* end expand hash */
					
					$(this).click(function() {
						if ( $(this).hasClass('minus') ) {
							hideContent(this);
						} else { 					
							showContent(this);
						}
						$(this).blur();
						return false;
					});
				});
				if ( showFirst ) {
					showContent ( $(this).find('.plusik_plus > h6').get(0) );
				}
				//TEST/ DOKLADNIE 
				if ( showLinkAll && !$(this).hasClass('no_expand_all') ) {
					$(this).parent().prepend( $('<div class="plusik_links"><a href="#plusik_expand" class="plusik_expand"><img src="/i/cf/citibank/icon_plus.gif" alt="+"> rozwiń wszystkie</a><a href="#plusik_collapse" class="plusik_collapse"><img src="/i/cf/citibank/icon_minus.gif" alt="-"> zwiń wszystkie</a></div><div class="clearer">&nbsp;</div>') );
				}
			});
			$('#plusik_expand, .plusik_expand').click(function() {
				// rozwin wszystkie
				//	dla wersji z taber.js
				if ( $('.taber_container').length > 0 ) {
					$('.taber_box:visible').find('.plusik_plus > h6').each(function() {
						if ( !$(this).hasClass('minus') ) {
							showContent(this);
						}
					});
				} else {
					$('.plusik_plus > h6').each(function() {
						if ( !$(this).hasClass('minus') ) {
							showContent(this);
						}
					});
				}
				$(this).blur();
				return false;
			});		
			$('#plusik_collapse, .plusik_collapse').click(function() {
				// zwin wszystkie
				//	dla wersji z taber.js
				if ( $('.taber_container').length > 0 ) {
					$('.taber_box:visible').find('.plusik_plus > h6').each(function() {
						if ( $(this).hasClass('minus') ) {
							hideContent(this);
						}
					});
				} else {
					$('.plusik_plus > h6').each(function() {
						if ( $(this).hasClass('minus') ) {
							hideContent(this);
						}
					});
				}
				$(this).blur();
				return false;
			});
		}
	}

}();


/*
var big_tabers = function(){
	var print = new String('');
	return { 
		create : function(active) {
			if(tabs) {
				for (i in tabs) { 
					print = '<div';
					var href = '';
					if(typeof tabs[i]  == 'object') href = tabs[i][0];
					else if(typeof tabs[i]  == 'string') href= tabs[i];
					if(active == href) print+= ' class="active"';
					
					print +='><a href="' + href + '">'+i+'</a></div>';
					document.write(print); 
				}; // end for()
			}//end if(tabs)
		} // end create()
	}
}();
*/

/*
var small_tabers = function(){
	return { 
		create : function(main_menu,active) {
		// pokazanie menu
			for (i in tabs) {
				if ( !tabs.hasOwnProperty(i) ) continue;
				if(typeof tabs[i]  == 'object') {
					if( (main_menu) && (main_menu>'') && (tabs[i][0]==main_menu) )
					{
						var submenu = tabs[i][1];
						for (j in submenu){
							var klasa = '';
							var print = '<div';
							if((active) && (active == submenu[j]) ) klasa = 'active';
							if (j.length>15) klasa += ' big';
							if(klasa=='active big') klasa = 'activebig';
							print+= ' class="'+klasa+'"';
							print +='><a href="'+submenu[j]+'">'+j+'</a></div>';
							document.write(print); 
						}
					}
				}
			}; // end for
		}// end create()
	}
}();
*/

var citi = function(){
	return {
		create_menus: {
		
			/** Duze menu */
			big : function(active) {
				if(typeof citi_menu_tabs!='undefined') {
					for (i in citi_menu_tabs) {
						var print = new String('<div');
						var href = '';
						if(typeof citi_menu_tabs[i]  == 'object') href = citi_menu_tabs[i][0];
						else if(typeof citi_menu_tabs[i]  == 'string') href = citi_menu_tabs[i];
						if(active == href) print+= ' class="active"';
						print +='><a href="' + href + '">'+i+'</a></div>';
						$("#big_tabers").append(print);
					};
				}
			},
			/** Male menu */
			small : function(main_menu,active) {
		if (typeof citi_menu_tabs!='undefined'){
				for (i in citi_menu_tabs) { 
					if ( !citi_menu_tabs.hasOwnProperty(i) ) continue;
					if(typeof citi_menu_tabs[i]  == 'object') {
						if( (main_menu) && (main_menu>'') && (citi_menu_tabs[i][0]==main_menu) )
						{
							var submenu = citi_menu_tabs[i][1];
							for (j in submenu){
								/*
								var klasa = '';
								var print = '<div';
								if((active) && (active == submenu[j]) ) klasa = 'active';
								if (j.length>15) klasa += ' big';
								if(klasa=='active big') klasa = 'activebig';
									print+= ' class="'+klasa+'"';
								print +='><a href="'+submenu[j]+'">'+j+'</a></div>';
								$("#small_tabers").append(print);
								*/
								
								var print = '<div class="tab';
								if((active) && (active == submenu[j]) ) print += ' active';
								print +='"><span class="l"></span><a href="'+submenu[j]+'">'+j+'</a><span class="r"></span></div>';
								$("#small_tabers").append(print);
								
							}
						}
					}
				}
				};
			}
			//end small
		}
	}
}();

$(function(){
	if(typeof exec!='undefined'){
		if(exec.menu&&exec.menu.big){
			citi.create_menus.big(exec.menu.big)
		}
		if(exec.menu&&exec.menu.big&&typeof exec.menu.small=='string'){

			citi.create_menus.small(exec.menu.big,exec.menu.small)
		}
	}
});