///////////////////////////////////////////////////////////////////////////////
var SITE = {
	baseUrl: ''
	,basePath: ''

	,getFragment: function(url){
		var matches = url.match( /#([^#]*)$/ );
		return (matches) ?matches[1] :null;
		}

	,preInit: function(){
		this.initCufon();
		this.mailtoAntiSpam();
		}

	,init: function(){
		this.mailtoAntiSpam();
		this.setInputClasses();
		if(window.initOverLabels) setTimeout(initOverLabels, 50);
		this.initCufon();
		$('IFRAME.allowTransparency').attr('allowTransparency', 'true');
		if($().customInput) $('.jsCustomInputs INPUT').customInput();
		this.attachFancybox();
		this.attachJSTabs();
		if($().TextAreaResizer) $('TEXTAREA.resizable:not(.processed)').TextAreaResizer();
		}

	,mailtoAntiSpam: function(){
		$("span[class='email']").each(function(){
			var mailtoVal = $(this).html().replace(' kukac ', '@').replace(' at ', '@').replace(' pont ', '.').replace(' dot ', '.');
			var titleVal = $(this).attr('title').replace(' kukac ', '@').replace(' at ', '@').replace(' pont ', '.').replace(' dot ', '.');
			if(!titleVal) titleVal = mailtoVal;
			var s = mailtoVal.match(/subject=([^&]*)/);
			if(s) mailtoVal = mailtoVal.replace(/(subject=)([^&]*)/, '$1'+escape(s[1]));
			$(this).replaceWith('<a href="mailto:'+mailtoVal+'" class="email">'+titleVal+'</a>')
			});
		}

	,setInputClasses: function(){
		$('a.submit').click(function(){
			var form = $(this).parents('form').get(0);
			if(!form.onsubmit) form.submit();
			else if(form.onsubmit.apply(form)) form.submit();
			return false;
			});
		$('input[type=text]:not(.typetext)').addClass('typetext');
		$('input[type=password]:not(.typetext)').addClass('typetext').addClass('typepassword');
		$('input[type=checkbox]:not(.typecheckbox)').addClass('typecheckbox');
		$('input[type=radio]:not(.typeradio)').addClass('typeradio');
		$('input[type=submit]:not(.typesubmit)').addClass('typesubmit');
		$('input[type=reset]:not(.typesubmit)').addClass('typesubmit').addClass('typereset');
		$('input[type=button]:not(.typebutton)').addClass('typebutton');
		}

	,initCufon: function(){
		if(!window.Cufon) return;
		Cufon.now();
		}

	,attachFancybox: function(){
		if(!$().fancybox) return;
		$('a.fancybox').fancybox({
			'centerOnScroll': true,
			'hideOnContentClick': true,
			'overlayColor': '#000',
			'overlayOpacity': 0.6,
			'speedIn': 300,
			'speedOut': 200,
			'titlePosition': 'over',
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'onComplete': function(currentArray, currentIndex, currentOpts){
				pager = $('<div id="fancybox-pageinfo">'+(currentIndex+1) + ' / ' + currentArray.length+'</div>').appendTo($("#fancybox-inner"));
				}
			});
		}

	,attachJSTabs: function(){
		if(!$('.jstabs').length) return;
		$('.jstabs .jstabs-handler li').removeClass('act');// Remove active class from links
		$('.jstabs .jstabs-sheet').hide();// Hide all tabsheets
		var initFragment = SITE.getFragment(document.location.href);
		if(initFragment){
			$('#jstabs-tab-'+initFragment).addClass('act');// Set the class for active state
			$('#jstabs-sheet-'+initFragment).show();// Show the first div
			}

		$('.jstabs').each(function(){
			var jstab = $(this);
			if(!initFragment){
				$('.jstabs-handler:first li', jstab).first().addClass('act');// Set the class for active state
				$('.jstabs-sheet:first', jstab).first().show();// Show the first div
				}
			$('.jstabs-handler:first li a', jstab).click(function(){// When link is clicked
				$('.jstabs-handler:first li', jstab).removeClass('act');// Remove active class from links
				$(this).parent().addClass('act');//Set parent of clicked link class to active

				var fragment = SITE.getFragment($(this).attr('href'));
				if(fragment){
					$('.jstabs-handler:first ~ .jstabs-sheet:not(#jstabs-sheet-'+fragment+')', jstab).hide();// Hide all tab divs
					$('#jstabs-sheet-'+fragment).fadeIn();// Show div with id equal to variable currentTab
					}
				return false;
				});
			});
		}

	,submitWithAction: function(element, action){
		var form = $(element).parents('form');
		$('input[name=action]', form).val(action);
		form.submit();
		}

	,createBookmarkLink: function(url, title){
		if(window.sidebar) window.sidebar.addPanel(title, url, ''); // Mozilla Firefox Bookmark
		else if( window.external ) window.external.AddFavorite(url, title); // IE Favorite
		}

	,isEmptyObject: function(obj){
		for (var prop in obj) if (obj.hasOwnProperty(prop)) return false;
		return true;
		}

	,overlayShow: function(html){
		var loading = (!html);
		if(loading) html = '<div class="loading"></div>';
		var obj = $('#overlayBox').html(html);
		if(loading) obj.height(70).width(450);
		else obj.height('auto').width('auto');

		var offset = {top: parseInt( $(window).scrollTop() + $(window).height()/2 - obj.height()/2 ), left: parseInt( $(window).scrollLeft() + $(window).width()/2 - obj.width()/2 )};
		if(loading) offset.top = $(window).scrollTop() + 100;
		obj.show().offset(offset);
		}

	,overlayClose: function(){
		$('#overlayBox').fadeOut();
		}

	};

if(window.jQuery) $(document).ready(function(){
	SITE.init();
	});

