var i,j;
var loading="<div style='height:150px;' align='center'><img src='/img/loading2.gif' /></div>";
function unactive(containerId,elementsName,className){
	var container = document.getElementById(containerId);
	var oa = container.getElementsByTagName("a");
	for(i=0;i<oa.length;i++){
		oa[i].className = className;
	}
}

var aContentSlideState = new Array;
for(i=0;i<=50;i++) aContentSlideState[i] = 0;
//aContentSlideState[50] = 1; //mapa schowana
/*function toggleSlide1(container,index){
	var containerId = container + "_" + index;
	if(aContentSlideState[index] == 0) {
		Effect.SlideUp(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/hide",{asynchronous:true})});
		aContentSlideState[index] = 1;
		document.getElementById("img_slide_" + index).src = "/img/arrow_news_off.gif";
	} else {
		Effect.SlideDown(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/unhide",{asynchronous:true})});
		aContentSlideState[index] = 0;
		document.getElementById("img_slide_" + index).src = "/img/arrow_news_on.gif";
	}
}*/

function toggleSlide(container,index,img_on,img_off){
	var img_on = (img_on) ? img_on : "/img/arrow_on.gif";
	var img_off = (img_off) ? img_off : "/img/arrow_off.gif";
	
	var containerId = container + "_" + index;
	if(aContentSlideState[index] == 0) {
		Effect.SlideUp(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/hide",{asynchronous:true})});
//		alert("/index/save_box_state/"+index+"/hide");
		aContentSlideState[index] = 1;
		var oImg = document.getElementById("img_slide_" + index);
		if(oImg) oImg.src = img_off;
		var oDiv = document.getElementById("div_slide_" + index)
		if(oDiv) oDiv.innerHTML = "rozwiń";
	} else {
		Effect.SlideDown(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/unhide",{asynchronous:true})});
//		alert("/index/save_box_state/"+index+"/unhide");
		aContentSlideState[index] = 0;
		var oImg = document.getElementById("img_slide_" + index);
		if(oImg) oImg.src = img_on;
		var oDiv = document.getElementById("div_slide_" + index)
		if(oDiv) oDiv.innerHTML = "zwiń";
	}
}

function minimize(container,index){
	var containerId = container + "_" + index;
	if(aContentSlideState[index] == 0) {
		Effect.SlideUp(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/hide",{asynchronous:true})});
		aContentSlideState[index] = 1;
		//document.getElementById("img_slide_" + index).src = "/img/arrow_news_off.gif";
	} else {
		return true;
	}
}

function maximize(container,index){
	var containerId = container + "_" + index;
	if(aContentSlideState[index] == 0) {
		return true;
	} else {
		Effect.SlideDown(containerId,{duration:0.5,onSuccess:new Ajax.Request("/index/save_box_state/"+index+"/unhide",{asynchronous:true})});
		aContentSlideState[index] = 0;
	}
}

function loadHotNews(contentDivId,url,cssClass,activElementId){
	new Ajax.Updater(contentDivId,url,{asynchronous:true});
	var tables = new Array(document.getElementById('hot_news_table_1'),document.getElementById('hot_news_table_2'));
	for(i=0;i<tables.length;i++){
		var rows = tables[i].getElementsByTagName('tr');
		for(j=0;j<rows.length;j++){
			rows[j].className = contentDivId + "_off";
			rows[j].firstChild.className = "";
			rows[j].lastChild.className = "";
		}
	}
	var elem = document.getElementById(activElementId);
	elem.className = contentDivId + "_on";
	elem.firstChild.className = contentDivId + "_td_left";
	elem.lastChild.className = contentDivId + "_td_right";

}

var aRec = new Array();
aRec[0] = new Array("najnowsze",1);
aRec[1] = new Array("patronaty",1);
aRec[2] = new Array("zapowiedzi",1);
function loadRec(i,idx){
	if((aRec[idx][1]<=1) && (i==-1)) return;
	if((aRec[idx][1]>=12) && (i==1)) return;
	aRec[idx][1] = aRec[idx][1] + i;
	new Ajax.Updater("rec_"+aRec[idx][0],"/index/rec_plyty/"+aRec[idx][0]+"/"+aRec[idx][1],{asynchronous:true,evalScripts:true});
//	new Ajax.Updater(aRec[idx][0],"/index/"+aRec[idx][0]+"/"+aRec[idx][1],{asynchronous:true,evalScripts:true});
}
function butRec(idx,isFirst,isLast){
	if(isFirst){
//		var lnk = document.getElementById(aRec[idx][0]+"_prev");
		var lnk = document.getElementById("rec_"+aRec[idx][0]+"_prev");
		var img = lnk.firstChild;
		img.setAttribute("src","/img/rec_btn_prev_.gif");
//		lnk.setAttribute("onclick","javascript:void(0)");
		lnk.onclick = function onclick(event){javascript:void(0);}
	} else if(isLast){
//		var lnk = document.getElementById(aRec[idx][0]+"_next");
		var lnk = document.getElementById("rec_"+aRec[idx][0]+"_next");
		var img = lnk.firstChild;
		img.setAttribute("src","/img/rec_btn_next_.gif");
//		lnk.setAttribute("onclick","javascript:void(0)");
		lnk.onclick = function onclick(event){javascript:void(0);}
	} else {
//		var lnk_prev = document.getElementById(aRec[idx][0] + "_prev");
		var lnk_prev = document.getElementById("rec_"+aRec[idx][0] + "_prev");
//		var lnk_next = document.getElementById(aRec[idx][0] + "_next");
		var lnk_next = document.getElementById("rec_"+aRec[idx][0] + "_next");
		var img_prev = lnk_prev.firstChild;
		var img_next = lnk_next.firstChild;
//		lnk_prev.setAttribute("onclick","loadRec(-1,"+idx+")");
		lnk_prev.onclick = function onclick(event){loadRec(-1,idx);}
//		lnk_next.setAttribute("onclick","loadRec(1,"+idx+")");
		lnk_next.onclick = function onclick(event){loadRec(1,idx);}
//		lnk_next.setAttribute("href","new Ajax.Updater('rec_najnowsze','/index/rec_plyty/najnowsze/3',{asynchronous:true})");
		img_prev.setAttribute("src","/img/rec_btn_prev.gif");
		img_next.setAttribute("src","/img/rec_btn_next.gif");
//		alert(lnk_next.onclick);
	}
}

function redirFromSelect(url,htmlSelect){
	var val = htmlSelect.value;
	var lbl = htmlSelect.options[htmlSelect.selectedIndex].label;
	document.location.href = url + val+","+lbl;
	return;
//	alert(val+','+lbl);
}

function calendarPopup(e){
	var left = e.screenX;
	var top = e.screenY;
	window.open("/_extras/calendar/calendar.html","calendar","width=175,height=170,resizable=no,status=no,toolbar=no,menubar=no,directories=no,scrollbars=no,left="+left+",top="+top);
}
function box_muzyka_switch_news(td,src){
	var tdNodes = td.parentNode.parentNode.getElementsByTagName('td');
	for(i=0;i<tdNodes.length;i++){
		//td.parentNode.childNodes[i].className = 'box_muzyka_switch_news_off';
		if(tdNodes[i].className == 'box_muzyka_switch_news_on') tdNodes[i].className = 'box_muzyka_switch_news_off';
	}
	//alert(td.parentNode.childNodes.length);
	//alert(td.parentNode.parentNode.getElementsByClassName('box_muzyka_switch_news_on').length);
	
	var img = document.getElementById('img_muzyka');
	img.src = src;
	td.className = 'box_muzyka_switch_news_on';
}
var aElementsCounter = new Array();
function updateElements(action,type,div){
	if(type == 7 || type == 8){ //box_muzyka
		var minCount = 3;
		var maxCount = 7;
		if(!aElementsCounter[type]) aElementsCounter[type]=3;
	} else {
		var minCount = 7;
		var maxCount = 12;
		if(!aElementsCounter[type]) aElementsCounter[type]=7;
	}
	

	if(action == "add"){
		if(aElementsCounter[type] == maxCount) return true;
		if(aElementsCounter[type] < maxCount) aElementsCounter[type] += 1;
		new Ajax.Updater(div,"/ajaxx/index_boxes_elements/"+action+"/"+type+"/"+aElementsCounter[type],{asynchronous:true});
	}
	if(action == "del"){
		if(aElementsCounter[type] == minCount) return true;
		if(aElementsCounter[type] > minCount) aElementsCounter[type] -= 1;
		new Ajax.Updater(div,"/ajaxx/index_boxes_elements/"+action+"/"+type+"/"+aElementsCounter[type],{asynchronous:true});
	}
}

Cookie = {};
Cookie.Set = function(c_name,value,path,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
    ((path==null) ? "" : ";path="+path);
}
Cookie.Get = function(c_name){
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return false;
}
/* ujednlocic z video */
VideoIndexObj = Class.create({
	initialize: function(name){
		this.name = name;
		this.lastClickedItem = false;
		this.topVideoCurrentPage = 1;
		this.topVideoNextButton = 1;
		this.topVideoPrevButton = 0;
	},
	Page: function(num){
		if(num == 1){
			if(this.topVideoNextButton == 0) return true;
			this.topVideoCurrentPage += 1;
			if(this.topVideoCurrentPage == 10) {
				this.topVideoNextButton = 0;
				$('video_top_next').select('img').each(function(obj){obj.src='/img/btn_next_off.gif'});
				new Ajax.Updater('video_top','/index/video/'+this.topVideoCurrentPage+"/0",{onLoading:$('video_top').update(loading)});
				return true;
			}
			this.topVideoPrevButton = 1;
			if(Element.readAttribute($('video_img_top_prev'),'src') == '/img/btn_prev_off.gif') $('video_img_top_prev').src='/img/btn_prev.gif';

			new Ajax.Updater('video_top','/index/video/'+this.topVideoCurrentPage+"/0",{onLoading:$('video_top').update(loading)});
		}
		else if(num == -1){
			if(this.topVideoPrevButton == 0) return true;
			this.topVideoCurrentPage -= 1;
			if(this.topVideoCurrentPage == 1) {
				this.topVideoPrevButton = 0;
				$('video_top_prev').select('img').each(function(obj){obj.src='/img/btn_prev_off.gif'});
				new Ajax.Updater('video_top','/index/video/'+this.topVideoCurrentPage+"/0",{onLoading:$('video_top').update(loading)});
				return true;
			}
			this.topVideoNextButton = 1;
			if(Element.readAttribute($('video_img_top_next'),'src') == '/img/btn_next_off.gif') $('video_img_top_next').src='/img/btn_next.gif';
			new Ajax.Updater('video_top','/index/video/'+this.topVideoCurrentPage+"/0",{onLoading:$('video_top').update(loading)});
		}
}
});
var VideoIndex = new VideoIndexObj('VideoIndex');

InfomusicSuggest = {};
InfomusicSuggest.Search = Class.create({
	initialize: function(strSearch,strSuggestElement){
		var suggest = $(strSuggestElement);
		
		if(strSearch=='') suggest.setStyle({'visibility':'hidden'});
		else {
	//		suggest.setStyle({'visibility':'visible'});
			new Ajax.Request('/ajaxx/search/search:'+strSearch,{
				onComplete: function(transport){
					if(transport.responseText != ''){
						suggest.update(transport.responseText);
						suggest.setStyle({'visibility':'visible'});
					} else suggest.setStyle({'visibility':'hidden'});
				}
			});
	//		suggest.update(strSearch);
		}

		var e = window.event;
		var key = e.keyCode || e.wich;
		if (key == Event.KEY_UP) alert('KEY_UP');
		if (key == Event.KEY_DOWN) alert('KEY_DOWN');
		if (key == Event.KEY_ESC) suggest.setStyle({'visibility':'hidden'});
	}
});
/*var toggleCalendar = 0;
function calendar(elemID){
	if(toggleCalendar == 0){
		new Ajax.Updater(elemID,'/_extras/calendar/calendar.html',{asynchronous:true,evalScripts:true});
		document.getElementById(elemID).style.display = 'block';
		toggleCalendar = 1;
	}
	else {
		document.getElementById(elemID).style.display = 'none';
		toggleCalendar = 0;
	}

}*/

// importy
document.write("<script type='text/javascript' src='/_extras/autocomplete/js/autocomplete.js'></scr"+"ipt>");

