// JavaScript Document
window.onload = setBehaviours;

function goToStartPage() {
	window.location.href = sBaseHref;
}

function inputOnFocus (oObj, sTxt) {
	if (oObj.value == sTxt) oObj.value = '';
}
function inputOnBlur (oObj, sTxt) {
	if (oObj.value == '') oObj.value = sTxt;
}

function sendSearchBoxForm(oForm) {
	var s = oForm.q.value;
	s = s.replace(/^\s+/, '').replace(/\s+$/, '');
	
	if (s != '' && s != sSearchTxt) {
		s = encodeURIComponent(s).replace(/%20/g, "+").replace(/%2C/g, ' ').replace(/%2F/g, '/');
		window.location.href = oForm.action + '?fraza=' + s + '&strona=1';
	}
	return false;
}

function sendSearchForm(oForm) {
	var s = oForm.q.value;
	var sLocation = '';
	s = s.replace(/^\s+/, '').replace(/\s+$/, '');
	
	if (s != '' && s != sSearchTxt) {
		s = encodeURIComponent(s).replace(/%20/g, "+").replace(/%2C/g, ' ').replace(/%2F/g, '/');
		sLocation = oForm.action + '?fraza=' + s + '&strona=1';
		window.location.href = sLocation;
	}
	
	
	return false;
}

function sendNewsletterBoxForm(oForm, sTxt) {
	var sEmail = oForm.n_email.value;
	sEmail = sEmail.replace(/^\s+/, '').replace(/\s+$/, '');
	
	if (sEmail == '' || sEmail == sTxt) {
		return false;
	}
}



function setBehaviours() {
	if (document.getElementById) {
		// WYSZUKIWARKA
		// onfocus, onblur
		if (oSearchInp = document.getElementById('q')) {
			oSearchInp.value = sSearchTxt;
			oSearchInp.onfocus = function() {inputOnFocus(oSearchInp, sSearchTxt);};
			oSearchInp.onblur = function() {inputOnBlur(oSearchInp, sSearchTxt);};
		}
		// onsubmit
		if (oSearchBoxForm = document.getElementById('searchBoxForm')) {
			oSearchBoxForm.onsubmit = function() {return sendSearchBoxForm(oSearchBoxForm);};
		}
		if (oSearchForm = document.getElementById('searchForm')) {
			oSearchForm.onsubmit = function() {return sendSearchForm(oSearchForm);};
		}
		
		// NEWSLETTER
		// onfocus, onblur
		if (oNewsletterInp = document.getElementById('n_email')) {
			oNewsletterInp.value = sNewsletterTxt;
			oNewsletterInp.onfocus = function() {inputOnFocus(oNewsletterInp, sNewsletterTxt);};
			oNewsletterInp.onblur = function() {inputOnBlur(oNewsletterInp, sNewsletterTxt);};
		}
		// onsubmit
		if (oNewsletterBoxForm = document.getElementById('newsletterBoxForm')) {
			oNewsletterBoxForm.onsubmit = function() {return sendNewsletterBoxForm(oNewsletterBoxForm, sNewsletterTxt);};
		}
	}
}


function pokaz(el) {
var i=0
for(var i=0; i<=20; i++) {
document.getElementById('div'+i).style.display = "none";
}
document.getElementById(el).style.display = "block";
}


var SiteEngine = new Class ({
initialize : function(basehref){
	this.objectmenufix();
	this.offerbanners();
	this.gallery1();
	this.newslistimagecontent();
	this.paragraphnews();
	this.printbtn();
	this.marquee();
	this.othertips();
	this.tabs();
	this.specialoffers();
},

objectmenufix: function() {
	
	var item = null;
	
	if($defined($('handles1')))
	item = $('handles1');
	else
	if($defined($('menuObjectSubpage')))
	item = $('menuObjectSubpage');
		
	if(item)
	if(!item.hasClass('multimediaMenuSubpage')){
	
	current_size = item.getSize().x;
	
	while(current_size < 960) {
		item.getElements('span.tabCenter').each(function(span){
			if(current_size < 960) {
			span.setStyle('width',span.getSize().x + 1);		
			}
			current_size = item.getSize().x;
		});
		
	}
	}
	
},

specialoffers: function() {
	if($defined($('contentSpecjals'))) {
		
	var nS2 = new noobSlide({
		box: $('contentSpecjals'),
		items: $$('#contentSpecjals div'),
		size: 307,
		autoPlay: true,
		interval: 4000,
		handles: $$('#handles2 span') ,
		onWalk: function(currentItem,currentHandle){
			this.handles.removeClass('active1');
			currentHandle.addClass('active1');
		}
	});
	
	}
},


tabs: function() {
	
	$$('.jq-checkpointSubhead').setStyles({
		opacity: 0,
		display: 'block'
	});
	$$('.jq-checkpoints li.firstlevel').each(function(el,i) {
													  
		el.getElement('div').set('tween', {duration: 500})
		
		el2 = el.getElement('ul');
		
		if(el2)
		el2.addEvents({
			'mouseenter': function() {
				el.getElement('div').fade('in');
			},
			'mouseleave': function() {
				el.getElement('div').fade('out');
			}
		});
		
		el.addEvents({
			'mouseenter': function() {
				el.getElement('div').fade('in');
			},
			'mouseleave': function() {
				el.getElement('div').fade('out');
			}
		});
	});
	
	if($defined($('tabBox'))) {
		
	var current_slide = 0;	
	$$('#handles1 b').each(function(item,index){
		if(item.getAttribute('id') == 'currentTabC') current_slide = index;
	});
	
		
	var nS1 = new noobSlide({
		box: $('tabBox'),
		items: $$('#tabBox .contentTabs'),
		size: 960,
		autoPlay: false,
		interval: null,
		startItem:current_slide,

		handles: $$('#handles1 b') ,
		onWalk: function(currentItem,currentHandle){

			this.handles.removeClass('active');
			if(currentHandle) 
			currentHandle.addClass('active');
		}
	});
	
	
	if($defined($('zakladka1'))) {
	var nS3 = new noobSlide({
		box: $('zakladka1'),
		items: $$('#zakladka1 img'),
		size: 960,
		fx: 2000,
		interval: 4000,
		autoPlay: true,
		fade: true
	});
	}
	
	if($defined($('zakladka2'))) {
		var nS4 = new noobSlide({
			box: $('zakladka2'),
			items: $$('#zakladka2 img'),
			size: 960,
			fx: 2000,
			interval: 4000,
			autoPlay: true,
			fade: true
		});
	}
	
	if($defined($('zakladka3'))) {
		var nS5 = new noobSlide({
			box: $('zakladka3'),
			items: $$('#zakladka3 img'),
			size: 960,
			fx: 2000,
			interval: 4000,
			autoPlay: true,
			fade: true
		});
	}
	if($defined($('zakladka4'))) {
		var nS6 = new noobSlide({
			box: $('zakladka4'),
			items: $$('#zakladka4 img'),
			size: 960,
			fx: 2000,
			interval: 4000,
			autoPlay: true,
			fade: true
		});
	}
	
	if($defined($('zakladka5'))) {
		var nS7 = new noobSlide({
			box: $('zakladka5'),
			items: $$('#zakladka5 img'),
			size: 960,
			fx: 2000,
			interval: 4000,
			autoPlay: true,
			fade: true
		});
	}
	
	if($defined($('zakladka6'))) {
		var nS8 = new noobSlide({
			box: $('zakladka6'),
			items: $$('#zakladka6 img'),
			size: 960,
			fx: 2000,
			interval: 4000,
			autoPlay: true,
			fade: true
		});
	}

	//opacity / display fix
	$$('#tabss .hidenchild').removeClass('hidenchild');
	$$('#tabss .blenda').setOpacity(0.7);
	
	}
	
},


othertips: function() {
	if($defined($('nav'))) {
		var tips = new Tips($$('#nav .only_in_polish a'),{ className: 'tip_add'});
	}
},


marquee: function() {
	if($defined($('marquee_relative_to_me')))							 
			new marquee({marqueeIn:'marquee_relative_to_me',marqueeMe:'marquee_me',speed:50});
},

printbtn: function() {
	
	var drukuj = $$('a.print');

	if(drukuj)
	{
		
	var leftP = parseInt((window.getHeight() - 70)/2);

	var leftPpx = leftP + 'px';

	var printDivContainer = new Element('div', {
	    'styles': {
	        'display': 'none',
	        'text-align': 'center',
			'position':'fixed',
			'left':'0px',
			'top':leftPpx,
			'width':'100%'
	    },
		'id':'printDivContainer'
	});

	var printDiv = new Element('div', {
	    'styles': {
	        'border': '1px solid black',
			'background-color': '#fff',
			'margin':'0 auto',
			'width':'400px',
			'padding':'10px'
	    },
	    'class': 'myClassSuperClass'
	});


	var text = new Element('p');
	text.set('html','Podglad wydruku... </br>(ta ramka nie bedzie widoczna podczas drukowania.)</br></br>');

	var normalViewLink = new Element('a', {
									 'styles': {
	        'cursor': 'pointer'
	    },
	    'events': {
	        'click': function(){
	            $('main_css').removeProperty('disabled');
				$('printPreviewCss').setProperty('media','print');		
				$('printPreviewCss').setProperty('disabled','true');		
				$('printPreviewCss').dispose();
				//if(window.ie6 and !window.ie7) {new Asset.css('/css/ieprintfix.css', {id: 'printIeFix', title: 'printpreview'});}
				$('printDivContainer').setStyle('display','none');
	        }}
	    });

	normalViewLink.set('html','Wylacz podglad wydruku');

	var printLink = new Element('a', {
									 'styles': {
	        'cursor': 'pointer',
			'margin-right':'10px'
	    },
	    'events': {
	        'click': function(){
	            window.print();
	        }}
	    });

	printLink.set('html','Drukuj');

	printDiv.adopt(text);
	printDiv.adopt(printLink);
	printDiv.adopt(normalViewLink);
	printDivContainer.adopt(printDiv);

	$(document.body).adopt(printDivContainer);
	}


	$$('a.print').each(function(pr){
	pr.addEvent('click', function(){
	if(Browser.Engine.trident) {
	window.print();
	}
	else {
	//	showPrintPreview();
		if($defined($('printPreviewCss')))  $('printPreviewCss').dispose();
		if($defined($('main_css'))) $('main_css').setProperty('disabled','true');
		new Asset.css(base_href + 'css/print_preview.css', {id: 'printPreviewCss', title: 'printpreview'});
		$('printDivContainer').setStyle('display','block');
	}
		});					
		pr.setStyle('cursor','pointer');
	});
	
},

paragraphnews: function() {
	
	if($defined($('paragraphNews')) && $defined($('grow'))) {
		
		$('grow').addClass('current-font-size');	
			
		$('shrink').addEvent('click',function() {
		[$('shrink'),$('grow'),$('growmore')].each(function(item){item.removeClass('current-font-size')});
		this.addClass('current-font-size');									 
		$('paragraphNews').removeClass('bigger_fonts');
		$('paragraphNews').addClass('smaller_fonts');
		});

		$('grow').addEvent('click',function() {
		[$('shrink'),$('grow'),$('growmore')].each(function(item){item.removeClass('current-font-size')});
		this.addClass('current-font-size');									 
		$('paragraphNews').removeClass('bigger_fonts');
		$('paragraphNews').removeClass('smaller_fonts');
		});

		$('growmore').addEvent('click',function() {
		[$('shrink'),$('grow'),$('growmore')].each(function(item){item.removeClass('current-font-size')});
		this.addClass('current-font-size');									 
		$('paragraphNews').addClass('bigger_fonts');
		$('paragraphNews').removeClass('smaller_fonts');
		});
	}
	
},

newslistimagecontent: function() {
	
	if($defined($('newsListImagesContent'))) {
	var nSS4 = new noobSlide({
		box: $('newsListImagesContent'),
		items: $$('#newsListImagesContent img'),
		size: 625,
		autoPlay: false,
		playback: true,

		handles: $$('#handles3 span'),
		
		addButtons: {previous: $('prev'), next: $('next')},
		
		onWalk: function(currentItem,currentHandle){
			this.handles.removeClass('active3');
			currentHandle.addClass('active3');

			$('prev').set('html',''+this.items[this.previousIndex].innerHTML);
            $('next').set('html',this.items[this.nextIndex].innerHTML+ '');
            
            
           
			if(this.previousIndex == this.items.length-1) {
				$('prev').addClass('inactive');
			} else {
				$('prev').removeClass('inactive');
			}
			
			if(this.nextIndex == 0) {
				$('next').addClass('inactive');
			} else {
				$('next').removeClass('inactive');
			}

		}
	});
	}
	
},

gallery1: function() {
	if($defined($('gallery_container2')) && $('gallery_container2').getElements('div.thumbnail').length) {
	new SlideItMoo({itemsVisible:3, // the number of thumbnails that are visible
						currentElement: 0, // the current element. starts from 0. If you want to start the display with a specific thumbnail, change this
						thumbsContainer: 'thumbs2',
						elementScrolled: 'thumb_container2',
						overallContainer: 'gallery_container2'
	});
	}
},

offerbanners: function () {
	if($defined($('bannerPhotoBig'))) {
	var nSS1 = new noobSlide({
		box: $('bannerPhotoBig'),
		items: $$('#bannerPhotoBig img'),
		size: 636,
		fx: 2000,
		interval: 3000,
		autoPlay: true,
		fade: true
	});
}
	if($defined($('bannerSmallContent'))) {
		var nSS2 = new noobSlide({
			box: $('bannerSmallContent'),
			items: $$('#bannerSmallContent img'),
			size: 315,
			fx: 2000,
			interval: 3000,
			autoPlay: true,
			fade: true
		});
	}	
}

});


window.addEvent('domready',function(){
   thesite    = new SiteEngine(base_href);
});
