/*Usage:

	var hasher = new hashChanger();
	hasher.set('hash');
	window.addEvent('load', function(){
		hasher.addEvent('change', function(hash){ myFunction(hash); });
	});
*/

var hashChanger = new Class({
	
	Implements: Events,
	
	hash: '',
	
	delay: 500,
	
    initialize: function() {
        this.hashCheck.periodical(this.delay, this);
    },
    
    set: function(value) {
    	this.hash = value;
    	document.location.hash = value; 
    },
    
    hashCheck: function() {
    	var hashTmp = document.location.hash.replace('#', ''); 
    	
        if (hashTmp != this.hash)
        {
        	this.hash = hashTmp;
        	this.fireEvent('change', this.hash);
        }
    }
	
});

function popRadio(){
	
	request_url = host_url_radio+"/www/radio_ie.php";
	var isIE = (window.ActiveXObject) ? true : false;
	if (isIE)
	{
		window.open(request_url,"mywindow","menubar=0,resizable=1,width=303,height=180"); 
	}	
}

var scroll = new Array();
var scrollCounter = new Array();
var scrollCount = new Array();
var scrollConfig = new Array();

function initscroll(id, config)
{		
    if ( $('scroll-'+id) == null ) return;    
    if ( $('scroll-content-'+id) == null ) return;

    scrollCount[id] = $$('div.scroll-item-'+id).length;
    scrollCounter[id] = 0;    
    scrollConfig[id] = config;
    
    if (scrollCount[id] <= config.items)
    {
    	$('scroll-'+id+'-prev').destroy();
    	$('scroll-'+id+'-next').destroy();    	
    	return;
    }
    
    if (config.size == undefined)
    {
    	config.size = $('scroll-item-'+id+'-0').getSize();    	
    	if (config.align == 'width')
    		config.size = config.size.x;
    	else
    		config.size = config.size.y;
    }
    
    $('scroll-content-'+id).setStyle(config.align, (config.size * scrollCount[id])+'px');

    scroll[id] = new Fx.Scroll('scroll-'+id);
    
    if (config.auto != undefined)
    {
    	(function(){ scrollAuto(id); }).periodical(config.auto);
    }
}

function scrollPrev(id)
{
	scrollCounter[id]--;
    
	if (scrollCounter[id] < 0)
		scrollCounter[id] = scrollCount[id] - scrollConfig[id].items;

	scroll[id].toElement('scroll-item-' + id + '-' + scrollCounter[id]);
}

function scrollNext(id)
{
	scrollCounter[id]++;
    
	if (scrollCounter[id] > scrollCount[id] - scrollConfig[id].items)
		scrollCounter[id] = 0;

	scroll[id].toElement('scroll-item-' + id + '-' + scrollCounter[id]);
}

function scrollSet(id, idPic)
{
	if (idPic < 0 || idPic > scrollCount[id]-1) return;
	
	scroll[id].toElement('scroll-item-' + id + '-' + idPic);
}

function scrollAuto(id)
{
	scrollCounter[id]++;
    
	if (scrollCounter[id] > scrollCount[id] - scrollConfig[id].items)
		scrollCounter[id] = 0;

	scroll[id].toElement('scroll-item-' + id + '-' + scrollCounter[id]);
}

function wwwBrowserSet(idPic)
{
	var id = 'gallerybm';
	
	if (idPic < 0 || idPic > scrollCount[id]-1) return;
	
	scroll[id].toElement('scroll-item-' + id + '-' + idPic);
}

function wwwMenuLeftShow(subId, level)
{
	$$('div.menu-left-content-'+level+' div.menu-left-content').setStyle('display', 'none');
	$$('div.menu-left-content-'+level).setStyle('display', 'none');
	
	var sub = $('menu-left-'+subId);
	
	if (sub.getStyle('display') == 'none')
		sub.setStyle('display', '');
	else
		sub.setStyle('display', 'none');
}

function showDay(day){
	var cat = 'gcat_'+day;
	var art = 'gart_'+day;
	
	var icat = 'gicat_'+day;
	
	if ( cat!=gcat ){
		//o(cat).className = 'menu_group_a'; //zwykle linki
	//	o(gcat).className = 'menu_group_i';
		
		o(icat).className = 'active-pagerr program-a'; //czerwone boxy
		o(gicat).className = 'program-a';
		gcat = cat;
		gicat = icat;
	}
	if ( art!=gart ){
		o(art).className = 'group_box_a';
		o(gart).className = 'group_box_i';
		gart = art;
		
	}
}

function active_square(id){
	var id = 'gicat_'+id;
	if ($(id).get('class')!='active-pagerr program-a')
	$(id).set('class','active-pagerr program-a pom');
	
}

function inactive_square(id){
	var id = 'gicat_'+id;
	if ($(id).get('class')=='active-pagerr program-a pom')
	$(id).set('class','program-a');
	
}

function goTo( theURL ){
	document.location.href = theURL;
}

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;
}

function loadAktualnosci(id_frame,timer) {

	var pic = 'pic_id_' + id_frame;
	var pager_links = $$('div.news-box-pager a');
	var frames = $$('div[id^=news-list-frame]');
	$each(frames, function(item) {
		item.setStyle('display', 'none');
	});
	$each(pager_links, function(item) {
		item.set('class', '');
	});
	$('pager-link-'+ id_frame).set('class', 'active-pager');

	id = 'news-list-frame-' + id_frame;
	//id = 'news-list-container';
	$(id).set('tween', {
		onComplete: function(id) {
			$(id).set('tween', { onComplete: Class.empty });
			//$(id).innerHTML = html;
			if (!$(pic).get('src')) $(pic).set('src',Pics[id_frame]);
			$(id).setStyle('display', 'block')
			Cufon.refresh('div.news-box-lid a');
			Cufon.refresh('div.news-box-title a');
			Cufon.refresh('div.news-box-subtitle a');
			$(id).tween('opacity', 1);
		},
		duration: 200
	});
	$(id).tween('opacity', 0);		
	
	//if (timer) 
	
} 

function loadNextAktualnosci() {
	
	var active = $$('a.active-pager');

	active.each(function(item){
	   var active_id = item.id;
	   var active_id = active_id.substring(11);
	   
	   if (active_id == 4)	var nextItem = 1;
	   else var nextItem = 1 + parseInt(active_id);
	  // alert(nextItem);
	   loadAktualnosci(nextItem,false);
	});
	
	
}

function loadNextAktualnosciTimer() {
	
	//alert('sdfdf');
	var active = $$('a.active-pager');

	active.each(function(item){
	   var active_id = item.id;
	   var active_id = active_id.substring(11);
	   
	   if (active_id == 4)	var nextItem = 1;
	   else var nextItem = 1 + parseInt(active_id);
	 //  alert(nextItem);
	   loadAktualnosci(nextItem,true);
	});	
	setTimeout("loadNextAktualnosciTimer()", 6000);
}

function loadContent(id,type)
{
	var request_url = host_url+'/www/content_ajax.php?id='+id+'&type='+type;
	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}



