var SiteClass = new Class({

	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 = 'public/images/highslide/';
		hs.align = 'center';
		hs.transitions = ['expand', 'crossfade'];
		hs.outlineType = 'rounded-white';
		hs.fadeInOut = true;
		//hs.dimmingOpacity = 0.75;
	
		hs.addSlideshow({
			//slideshowGroup: 'group1',
			interval: 5000,
			repeat: false,
			useControls: true,
			fixedControls: 'fit',
			overlayOptions: {
				opacity: .75,
				position: 'bottom center',
				hideOnMouseOut: true
			}
		});
				
	}, // initialize
	
	fadeDuration: 1000,
	delayDuration: 8000,
	tableSlides: [],
	
	domReady: function() {

		if(Browser.Engine.trident4) { $$('div#menu ul li a').each(function(a){ a.addEvents({'mouseenter': function(){ this.toggleClass('hover'); }, 'mouseleave': function(){ this.toggleClass('hover'); } }); }); }
		
		new Swiff('public/flash/top.swf', {
			container: $('slogan'),
			width: 300,
			height: 50
		});
		
		this.activateSIFR();
		this.activateChart();
		this.activateQuotes();
		this.activateNewsletter();
		this.activateServiceTable();
		this.activateForms();
		newsScroller.activate();
	}, // domReady

	activateServiceTable: function() {

		if($('services-table')) { 
			$$('table#services-table tr.caption').each(function(tr){ 
				tr.addEvents({'mouseenter': function(){ this.addClass('hover'); }, 'mouseleave': function(){ this.removeClass('hover'); } }); 
				//if(tr.getParent('table').hasClass('sidebar')) {
				//	tr.addEvent('click', function(){
				//		if(this.getNext().hasClass('services')) {
				//			var id = this.getNext().getFirst().id;
				//			Site.tableSlides[id].toggle();
				//		}
				//	});
				//} else {
					tr.addEvent('click', function(){ 
						var a = this.getFirst().getChildren('a'); 
						if(a.length) window.location = a[0].get('href'); 
					});	
				//}
			});
			
			$$('table#services-table tr.services td div').each(function(div){
				var id = parseInt(div.getParent().id);
				Site.tableSlides[id] = new Fx.Slide(div);
				if(div.hasClass('opened')) {
					Site.tableSlides[id].show();	
				} else {
					if(Browser.Engine.trident4) {
						Site.tableSlides[id].slideOut();
					} else {
						Site.tableSlides[id].hide();
					}
				}
			});			
		}

	}, // activateServiceTable
	
	activateNewsletter: function() {

		if($('newsletter_add_btn')) { 
			$('newsletter_add_btn').addEvent('click', function(){ $('email_add').value = '1'; });
			$('newsletter_rem_btn').addEvent('click', function(){ $('email_add').value = '0'; });
		}
		
	}, // activateNewsletter
			
	loadMap: function() {
		try {
			if (GBrowserIsCompatible()) {
				var map = new GMap2($('gmap'));
				var centrala = new GLatLng(52.184842,21.044966);
				var center = new GLatLng(52.209563,21.027431);
				var marker_centrala = new GMarker(centrala);
				map.addControl(new GSmallMapControl()); //kontrolki
				map.addControl(new GMapTypeControl());
				map.enableDoubleClickZoom();                    
				map.setCenter(center, 12);
				map.addOverlay(marker_centrala);
			}
		} catch(ex) {}
		
	}, //loadMap

	activateQuotes: function() {

		if($('quote')) {
			$$('ul#quote li').each(function(li, i) { li.setStyle('opacity', 0); });
			var elems = $$('ul#quote li');
			var random = $random(0, elems.length-1);
			
			Effects = new Array();
			
			
			Effects[random] = new Fx.Tween(elems[random], {duration: Site.fadeDuration, link: 'chain', 
			    onStart: function(li){
				li.display = 'none';
			    },
			    onComplete: function(li){
				li.display = 'block';
				li.addClass('active')
			}}).start('opacity', 0, 1);
			
			if($$('ul#quote li').length > 1) {
				var periodical = Site.nextQuote.periodical(2 * Site.fadeDuration + Site.delayDuration);
			}
		}

	}, //activateQuotes

	nextQuote: function() {
		var lis = $$('ul#quote li.active');
		new Fx.Tween(lis[0], {
			duration: Site.fadeDuration, 
			onComplete: function(li){
				li.removeClass('active');
				//setTimeout(null, 200);
				var next = (li.getNext()) ? li.getNext() : li.getParent().getFirst();
				next.addClass('active');
				li.display = 'none';
				new Fx.Tween(next, {
					onStart: function(li){
					    li.display = 'block';
					},
					link: 'chain',
					duration: Site.fadeDuration
				}).start('opacity', 0, 1);
			}
		}).start('opacity', 1, 0);
	}, //nextQuote
	
	activateChart: function() {
		
		if($('chart')) { 
			var chartTips = new Tips('div#chart ul li', { className: 'tooltip', offset: {'x': -5, 'y': -32} });
			$$('.tooltip').each(function(tip){ tip.setStyle('opacity', 0.9); });
			$$('div#chart ul li').each(function(li){ new Fx.Tween(li, {duration: 1000}).start('height', 0, li.getHeight() - 3); });
		}
		
	}, //activateChart
	
	activateSIFR: function() {

		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"h1.caption", sFlashSrc:"/public/flash/font.swf", sColor:"#ed1c24", sLinkColor:"#ed1c24", sBgColor: null, sHoverColor:"#ed1c24", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode: 'transparent'}));
			sIFR.replaceElement(named({sSelector:"div#today-number div.number", sFlashSrc:"/public/flash/font.swf", sColor:"#20a2df", sLinkColor:"#20a2df", sBgColor: null, sHoverColor:"#20a2df", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=right&offsetTop=0", sWmode: 'transparent'}));
			sIFR.replaceElement(named({sSelector:"div#service-price", sFlashSrc:"/public/flash/font.swf", sColor:"#20a2df", sLinkColor:"#20a2df", sBgColor: null, sHoverColor:"#20a2df", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=right&offsetTop=0", sWmode: 'transparent'}));
		}
		
	}, //activateSIFR

	showMail: function(user, domain, contry, attr) {
		var start = "<a href=\"mailto:" + user + "@" + domain + "." + contry + "\"" + attr + ">";
		var end = "</a>";
		document.write(start + user + "@" + domain + "." + contry + end);
		return false;
	}, // showMail
	
	checkTitles: function(form) {
		form.getElements('input[type=text]').each(function(obj){
			if (obj.value == obj.title) obj.value = '';
		});
		form.getElements('textarea').each(function(obj){
			if (obj.innerHTML == obj.title) obj.innerHTML = '';
		});
	}, // checkTitles
	
	activateForms: function() {
		/*$$('input[type=text]').each(function(obj){
			obj.onclick = function() { if (obj.value == obj.title) { obj.value = '';} };
			obj.onblur = function()  { if (obj.value == '') { obj.value = obj.title;} };
		});*/

		$$('textarea').each(function(obj){
			obj.onclick = function() { if (obj.innerHTML == obj.title){obj.innerHTML = '';} };
			obj.onblur = function()  { if (obj.innerHTML == ''){obj.innerHTML = obj.title;} };
		});

		$$('form').each(function(obj){
			obj.onsubmit = function() { Site.checkTitles(this); };
		});
		
	} // activateForms
});

var NewsScroller = new Class({
	initialize: function() {
		this.scroll_id = 'news-scroll';
	},
	
	
	activate: function(){
		this.container = $(this.scroll_id);
		if (this.container) this.initScroller();
	}, // activate
	
	initScroller: function(){
		var scroll_elem = this.container;
		this.scrollLen = 0;
		scroll_elem.getElements('ul li').each(function(obj){
			newsScroller.scrollLen = newsScroller.scrollLen+obj.getStyle('width').toInt()+obj.getStyle('margin-left').toInt();
		});
		//if (Browser.Engine.trident) newsScroller.scrollLen = newsScroller.scrollLen + 22;
		//alert(newsScroller.scrollLen);
		
		this.boxWidth =  this.scrollLen;
		this.scrollMax = this.scrollLen;
		this.boxHeight = scroll_elem.getStyle('height').toInt();

		this.container_clone = this.container.clone();
		this.container_clone.set('id', this.scroll_id+'_clone');
		this.container_clone.setStyle('margin-left', this.boxWidth);
		this.container_clone.inject($(this.scroll_id), 'after');
		
		this.fx  = new Fx.Morph(this.container, { duration: 75000, transition: 'linear', onComplete: function(obj){ newsScroller.scrollBack(obj); newsScroller.scrollIt();  }});
		this.fx2 = new Fx.Morph(this.container_clone, { duration: 75000, transition: 'linear', onComplete: function(obj){ newsScroller.scrollBack(obj); newsScroller.scrollIt(); }});
		
		this.scrollIt();
		
	}, // initScroller
	
	scrollIt: function(){
		var pos_x = this.container.getStyle('margin-left').toInt();
		var pos_x_clone = this.container_clone.getStyle('margin-left').toInt();

		this.fx.start({'margin-left': pos_x-this.boxWidth});
		this.fx2.start({'margin-left': pos_x_clone-this.boxWidth});
	},

	scrollBack:function(obj) {
		if (obj.getStyle('margin-left').toInt() <= -(this.scrollMax)) {
			obj.setStyle('margin-left', this.scrollMax);
		}
	} // scrollBack
	


}); // NewsScroller

var Site = new SiteClass();
var newsScroller = new NewsScroller();

window.addEvent('domready', function(){ Site.domReady(); });

