window.addEvent('domready',function(){

	if(Cookie.read('fontsize') && $$('div.content')) {
		var offset = Cookie.read('fontsize').toInt() - 11;
		$$('div.content, div.content *').each(function(el) { 
			el.setStyle('font-size',el.getStyle('font-size').toInt()+offset+'px');
		});
	}
	
	if($('accordion')){
		var accordion = new Accordion($$('.toggler'),$$('.element'), {
			opacity: 0,
			start: 'all-closed',
			alwaysHide: true,
			onActive: function(toggler) { toggler.setStyles({'color':'#fe5622'}); },
			onBackground: function(toggler) { toggler.setStyles({'color':'#fe5622'}); }
		});
	}

	if($('content') && $('scrollbar')) makeScrollbar( $('content'), $('scrollbar'), $('handle') );
	
	var myImages = new Asset.images(banners);
	$('akcijeimg').set('src',banners.getRandom());
	(function(){
		var index = banners.indexOf($('akcijeimg').get('src'));
		index = (index<banners.length-1) ? ++index : 0;
		$('akcijeimg').set('src',banners[index]).removeClass('none');
	}).periodical(6000)
	
	$$('#content img').each(function(el){
		new Element('a', {
			'href' : el.src.replace('/small/','/medium/'),
			'rel' : 'milkbox:gal1'
		}).wraps(el);
	});
	
	milkbox = new Milkbox();
});

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y+100))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var csteps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y+100))
			step = Math.round(csteps * (step/this.steps))
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

// fontsizer('+','content',[10,14])
function fontsizer(way,cn,limit){
	var current = $$('div.'+cn)[0].getStyle('font-size').toInt();
	if(way=='+' && current<limit[1]) $$('div.'+cn+', div.'+cn+' *').each(function(el) { 
		el.setStyle('font-size',el.getStyle('font-size').toInt()+1+'px');
	});
	if(way=='-' && current>limit[0]) $$('div.'+cn+', div.'+cn+' *').each(function(el){
		el.setStyle('font-size',el.getStyle('font-size').toInt()-1+'px');
	});
	Cookie.write('fontsize',$$('div.'+cn)[0].getStyle('font-size').toInt()); 
}

function printup(url,width,height) {
	var newwindow=window.open(url,'name','height='+height+',width='+width+',scrollbars=yes');
	if (window.focus) {
		newwindow.focus();
	}
	return false;
}


