var Site = new Class({

	boxPages: 0,
	boxWidth: 0,
	boxCurrentPage: 1,
	boxCurrentOffset: 0,
	
	initialize: function(){

		hs.lang.cssDirection = lang.cssDirection;
		hs.lang.loadingText = lang.loadingText;
		hs.lang.loadingTitle = lang.loadingTitle;
		hs.lang.focusTitle = lang.focusTitle;
		hs.lang.fullExpandTitle = lang.fullExpandTitle;
		hs.lang.previousText = lang.previousText;
		hs.lang.nextText = lang.nextText; 
		hs.lang.moveText = lang.moveText;
		hs.lang.closeText = lang.closeText; 
		hs.lang.closeTitle = lang.closeTitle; 
		hs.lang.resizeTitle = lang.resizeTitle;
		hs.lang.playText = lang.playText;
		hs.lang.playTitle = lang.playTitle;
		hs.lang.pauseText = lang.pauseText;
		hs.lang.pauseTitle = lang.pauseTitle;
		hs.lang.previousTitle = lang.previousTitle;
		hs.lang.nextTitle = lang.nextTitle;
		hs.lang.moveTitle = lang.moveTitle;
		hs.lang.fullExpandText = lang.fullExpandText;
		hs.lang.number = lang.number;
		hs.lang.restoreTitle = lang.restoreTitle;			
		hs.graphicsDir = '/wp-content/themes/wyspagadzetow/images/highslide/';
		hs.align = 'center';
		hs.transitions = ['expand', 'crossfade'];
		hs.outlineType = 'rounded-white';
		hs.fadeInOut = true;
		hs.dimmingOpacity = 0.50;
		
		hs.addSlideshow({
			//slideshowGroup: 'group1',
			interval: 5000,
			repeat: false,
			useControls: true,
			fixedControls: 'fit',
			overlayOptions: {
				opacity: .75,
				position: 'bottom center',
				hideOnMouseOut: true
			}
		});

	}, // initialize
	
	domReady: function() {
		this.setBoxParams();
		this.activateBoxActions();
		
		Cufon.replace('.cufonNormal', { hover: true });
		Cufon.replace('button.cufonShadow', { textShadow: '1px 1px #444' });
		Cufon.replace('.cufonShadow', { textShadow: '1px 1px #1E3706', hover: {textShadow: '1px 1px #135C80'} });
		Cufon.now();

		this.setActiveLinks('ul#menu');

		if($('goback')) {
			$('goback').addEvent('click', function() {
				history.go(-1);
			});
		}

		$('gotop').addEvent('click', function() {
			var scrollFx = new Fx.Scroll(window, {
				transition: Fx.Transitions.Quad.easeInOut
			});
			scrollFx.toTop();
		});
		
		$$('ul#tabs a').each(function(a){
			a.addEvent('click', function(){
				$$('ul#tabs a').each(function(a){ a.removeClass('active'); });
				$$('div#tabs_content div').each(function(div){ div.hide(); });
				this.addClass('active');
				$('tabs').className = this.rel;
				Cufon.replace('ul#tabs .cufon');
				$(this.rel+'-content').show();
			});
		});
		$('tabs').getLast().getFirst().fireEvent('click');

	}, // domReady

	setActiveLinks: function(pattern) {
		var path = document.location.pathname.substr(1);
		if(path.charAt(path.length-1) == '/') path = path.substr(0, path.length-1);
			else if(path == '') path = '/'; // main page
		path = path.replace(/\/\d+\/?$/, '').replace(/\/[0-9a-z-]+\.html\/?$/, '');
		
		var links = $$(pattern+' a[href='+path+']');
		while(links.length == 0 && path != '') {
			path = path.split('/');
			path.pop();
			path = path.join('/');
			links = $$(pattern+' a[href='+path+']');
		}
		if(links.length == 1) {
			var a = links[0];
			a.addClass('active');
		}
		
	}, //setActiveLinks

	setBoxParams: function() {
		if ($('bar-scroll-links')) {
			this.boxWidth = parseInt($('bar-scroll-links').getStyle('width'));
			var height = $('bar-scroll-links').getStyle('height');
			this.boxPages = parseInt(height)/24;
		}
		
	}, // setBoxParams
	
	activateBoxActions: function() {
		
		$('bar-control-prev').addEvent('click', function() {
			if (Site.boxCurrentPage > 1) {
				Site.boxCurrentPage--;
				Site.boxCurrentOffset = (Site.boxCurrentPage-1)*Site.boxWidth*-1;
				$('bar-scroll').tween('margin-left',Site.boxCurrentOffset);
			}
			return false;
        });
		
		$('bar-control-next').addEvent('click', function() {
			if (Site.boxCurrentPage < Site.boxPages) {
				Site.boxCurrentPage++;
				Site.boxCurrentOffset = (Site.boxCurrentPage-1)*Site.boxWidth*-1;
				$('bar-scroll').tween('margin-left',Site.boxCurrentOffset);
			}
			return false;
        });
		
	} // activateBoxActions
	
});

var Site = new Site();
window.addEvent('domready', function(){ Site.domReady(); });
