
/* animated gallery */

var scrollPro = new Array();
var counterPro = new Array();
var countPro = new Array();
var itemsPro = new Array();
var itemsDescPro = new Array();
var dotImgList = new Array();

var slideshowInterval;
var slideshowTime = 3000;

function initGallery( id ) {

    if ( $$('#'+ id +'_list .'+ id +'_list_item') == undefined ) return ;

    counterPro[id] = 0;
    itemsDescPro[id] = $$('#'+ id +'_list .'+ id +'_list_pos');

    scrollPro[id] = new Fx.Scroll(''+ id +'_list', {
    	transition:Fx.Transitions.Quad.easeOut,
    	duration:500,
        onStart: function(){
        },
        onComplete: function(){
            if ( itemsDescPro[id].length > 0 )
            itemsDescPro[id][counterPro[id]].setStyle( 'display', '' );
        }
    });

    countPro[id] = $$('#'+ id +'_list .'+ id +'_list_item').length-1;
    dotImgList[id] = $$('#'+ id +'_pos_list div');
    scrollPro[id].toElement(id+'_list_item_0');
}

function galleryNext( id ) {

    if ( itemsDescPro[id].length > 0 )
    	itemsDescPro[id][counterPro[id]].setStyle( 'display', 'none' );
    
    counterPro[id]++;

    if ( counterPro[id] > countPro[id]  )
        counterPro[id] = 0;


    if ( $$('#'+ id +'_pos_list .gallery_pos_list_active').length > 0 ) { 
    	$$('#'+ id +'_pos_list .gallery_pos_list_active')[0].className = 'gallery_pos_list_unactive';
    	dotImgList[id][counterPro[id]].className = 'gallery_pos_list_active';
    }

    scrollPro[id].toElement(id+'_list_item_'+counterPro[id]);
}

function galleryGoTo( id, index ) {

    counterPro[id] = index;
    
    if ( itemsDescPro[id].length > 0 )
    itemsDescPro[id][index].setStyle( 'display', 'none' );

    $$('#'+ id +'_pos_list .gallery_pos_list_active')[0].className = 'gallery_pos_list_unactive';
    dotImgList[id][index].className = 'gallery_pos_list_active';

    scrollPro[id].toElement(id+'_list_item_'+index);
}

function galleryPrev( id ) {

    if ( itemsDescPro[id].length > 0 )
    	itemsDescPro[id][counterPro[id]].setStyle( 'display', 'none' );
    
    counterPro[id]--;
    
    if ( counterPro[id] < 0 )
        counterPro[id] = countPro[id] ;

    if ( counterPro[id] < 0 )
        counterPro[id] = 0;

    if ( $$('#'+ id +'_pos_list .gallery_pos_list_active').length > 0 ) {
	    $$('#'+ id +'_pos_list .gallery_pos_list_active')[0].className = 'gallery_pos_list_unactive';
	    dotImgList[id][counterPro[id]].className = 'gallery_pos_list_active';
    }

    scrollPro[id].toElement(id+'_list_item_'+counterPro[id]);
}

function galleryInterval(){
	if( !isNaN(slideshowInterval) ) clearInterval( slideshowInterval );
	slideshowInterval = setInterval( galleryIntervalShow, slideshowTime );
}

function galleryIntervalShow(){
	galleryNext(  'gallery'  );
}





function changeFontSize( size ) {
	
	var fontSize;
	
	if ( size == 'normal' ) {
		fontSize = 11;
	}
	
	if ( size == 'avgerage' ) {
		fontSize = 13;
	}
	
	if ( size == 'big' ) {
		fontSize = 15;
	}
	
	if ( fontSize ) {
		$$('.changeFontSize').each(function(item,index){
			item.setStyle('font-size',fontSize);
		});
		eraseCookie('changeFontSize');
		createCookie( 'changeFontSize', fontSize, 3 );
	}
}

function initChangeFontSize() {
	var cookie = readCookie('changeFontSize');

	if ( cookie ) {
		changeFontSize( cookie );
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}


function getAccordion() {
	
	var accordion = new Accordion('.time_event_box', '.time_event_box_text', {
      onActive: function(toggler, element){
          toggler.setAttribute('id', 'header_active_sub');
          var alist = toggler.getChildren()[0].getChildren();
          
          
          $$('.time_event_ico_down').each( function(item, index){
        	  item.className = 'time_event_ico_up';
          });
       	  $('time_event_ico_'+this.previous).className = 'time_event_ico_down';
          
          setHref( $('time_event_href_'+this.previous));
      },
      onBackground: function(toggler, element){
          toggler.setAttribute('id', 'header_inactive_sub');
          var alist = toggler.getChildren()[0].getChildren();
          alist[0].href = 'javascript:void(0);';
          alist[0].target = '_self';
      }
   
	}, $('accordion'));
}


function setHref(item)
{
    (function(){ item.setAttribute('href', item.title); item.setAttribute('target', item.rel); } ).delay(1000);
}

function dayShow(url){

	location.href = url;
}


function P7_HScroller(el,dr,tx,ox,spd) { //v1.6 by PVII
 var g,gg,fr,sp,pa='',slw=true,m=false,w,ww,lx,rx;tx=parseInt(tx);
 if((g=MM_findObj(el))!=null){gg=(document.layers)?g:g.style;}else{return;}
 if(dr=="Stop"){if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=false;}
 if((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1)&& !window.opera){pa="px";}
 if(navigator.userAgent.indexOf("NT")>-1 || navigator.userAgent.indexOf("Windows 2000")>-1){slw=false;}
 if(spd=="Slow"){sp=(slw)?2:1;fr=(slw)?40:30;}else if(spd=="Medium"){sp=(slw)?4:1;fr=(slw)?40:10;
 }else{sp=(slw)?8:4;fr=(slw)?40:10;}if(spd=="Warp"){sp=5000;}var xx = parseInt(gg.left);if(isNaN(xx)){
 if(g.currentStyle){xx=parseInt(g.currentStyle.left);}else if(document.defaultView){
 xx=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("left"));}else{xx=0;}}
 if(document.all || document.getElementById){w=parseInt(g.offsetWidth);if(!w){w=parseInt(g.style.pixelWidth);}
 if(g.hasChildNodes){for(wx=0;wx<g.childNodes.length;wx++){ww=parseInt(g.childNodes[wx].offsetWidth);
 if(ww>w){w=ww;}}}}else if(document.layers){w=parseInt(g.clip.width);}lx=tx-w+parseInt(ox);rx=tx;
 if(dr=="Right"){if(xx>lx){m=true;xx-=sp;if(xx<lx){xx=lx;}}}
 if(dr=="Left"){if(xx<rx){m=true;xx+=sp;if(xx>rx){xx=rx;}}}
 if(dr=="Reset"){gg.left=tx+pa;if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=false;}
 if(m){gg.left=xx+pa;if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=true;
  eval("g.p7Magic=setTimeout(\"P7_HScroller('"+el+"','"+dr+"',"+tx+","+ox+",'"+spd+"')\","+fr+")");
 }else{g.toMove=false;}
}


function o(identyfikator) {
	return document.getElementById(identyfikator);
}


function openPage(theUrl,W,H){
    var theWin ="'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+W+",height="+H+"'"
	littleWin = window.open(theUrl,'',theWin);
	//littleWin.resizeTo(W+10,H+29);
 	littleWin.focus();
}

function newsletterAdd(){
	
	var form = document.forms['form_newsletter'];
	var email = form.newsletter_email.value;
	
	if(validateEmail(email)){
		form.form_type.value = 'add';
		form.submit();
	}
	else{
		alert('Niepoprawny adres e-mail');
	}
}


function newsletterDel(){
	
	var form = document.forms['form_newsletter'];
	var email = form.newsletter_email.value;
	
	if(validateEmail(email)){
		form.form_type.value = 'del';
		form.submit();
	}
	else{
		alert('Niepoprawny adres e-mail');
	}
}


/*********************************************************/
/* Web Pages Menu                                        */
/*********************************************************/

function showSubMenu(obj){

	var selectObj = document.getElementById( obj );
	if (selectObj==null)	return;
	
	if (selectObj.style.display != ""){
		//alert('tak');
		selectObj.style.display = "";
	}
	else 
		selectObj.style.display = "none";
	
	return;
}

function hideSubMenu(obj){
	
	if ( obj!="" ){
		var selectObj = document.getElementById( obj );

		if (selectObj != null)
			selectObj.style.display = "none";
	}
}

function highSubItem(obj){
	
	if ( obj!="" ){
		var selectObj = document.getElementById( obj );

		if (selectObj != null){
			if(selectObj.className=='menu_i')
				selectObj.className='menu_a';
				
			if(selectObj.className=='menu_si')
				selectObj.className='menu_sa';
				
			if(selectObj.className=='menu_top_i')
				selectObj.className='menu_top_a';
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function validateEmail(string) {
	
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	return false;
}

