var robot = true;

function Slideshow(blockId, time) {
	this.elements = new Array();
	
	this.box = document.getElementById(blockId);
	
	this.idx = 0;
	
	this.time = time;
		
	this.setOpacity = function(element, value) {
		if (navigator.appName.indexOf("Microsoft")!=-1 && parseInt(navigator.appVersion)>=4) {
			element.style["filter"] = "alpha(opacity="+(value*100)+")";
		} else {
			element.style.opacity = value;
		}		
	}
	this.opacityChange = function(element,change) {
		
		if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
			if (change < 0) change = -10;
			else change = 10;
			
			var opacity = parseFloat(element.filters.alpha.opacity);		
			opacity = opacity + change;
			element.filters.alpha.opacity = opacity;
		} else {
			if (change < 0) change = -0.1;
			else change = 0.1;
			
			var opacity = parseFloat(element.style.opacity);		
			opacity = opacity + change;
			element.style.opacity = opacity;
		}
	}
	
	this.create = function() {
		
		var nodes = this.box.childNodes;
		var k =0;
		for(var i = 0;i < nodes.length;i++) {
			if ( nodes[i].nodeType == 1 ) {
				if (k > 0) {	
					this.setOpacity(nodes[i],0);
					nodes[i].style.zIndex = 10;
				} else {
					this.setOpacity(nodes[i],1);
					nodes[i].style.zIndex = 11;
				}
				k++;
				this.elements.push(nodes[i]);
			}
		}
		setTimeout("slideshow.swap(100);",this.time);
	}
	
	this.swap = function(loop) {
		if (loop > 0) {
			
			this.opacityChange(this.elements[this.idx],-1);
			
			var tmp = this.idx + 1;
			if (tmp == this.elements.length) {
				tmp = 0;
			}
			
			this.opacityChange(this.elements[tmp],1);
						
			setTimeout("slideshow.swap("+(loop-10)+");",100);
			
			
		} else if (loop == 0) {
			this.elements[this.idx].style.zIndex = 10;
			this.idx++;
			if (this.idx == this.elements.length) {
				this.idx = 0;
			}
			this.elements[this.idx].style.zIndex = 11;
					
			setTimeout("slideshow.swap(100);", this.time);
		}
	}
	
	this.show = function () {
		document.getElementById(this.id + this.slide).style.backgroundImage = 'url("'+this.photos[this.idx]+'")';
		
		this.idx++;
		this.slide++;
		if (this.slide == 3) {
			this.slide = 1;
		}
		
		if (this.idx == this.photos.length) {
			this.idx = 0;
		}
	}
	
}

var Fosta= {

};

Fosta.SHL = function(box,tabs) {
	this.id  = tabs[0];	
	this.box = box;
	document.getElementById(this.id).style.display = "block";
	
	for (idx in tabs) {
		document.getElementById('a'+tabs[idx]).setAttribute('onclick',this.box+'.swap(\''+tabs[idx]+'\');return false;');
	}
	
	this.swap = function (id) {
		document.getElementById(this.id).style.display = "none";
		document.getElementById(id).style.display = "block";
		this.id = id;
	};
};

Fosta.showHide = function (id) {
	var box = document.getElementById(id);
	
	if (box.style.display == "none") {
		box.style.display = "inline";
	} else {
		box.style.display = "none";
	}
}





Fosta.Flash = {
	embed : function(width,height,file,flashvars) {	
		
		var html = '<object '+
			'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0";' + 
			'width="'+width+'" height="'+height+'">'+
			'<param name="movie" value="'+file+'" />'+
			'<param name="quality" value="high" />'+
			'<param name="wmode" value="transparent" />'+
			'<param name="flashvars" value="'+flashvars+'" />	'+	
			'<param name="allowFullScreen" value="true" />' +
			'<embed src="'+file+'" quality="high" allowFullScreen="true" wmode="transparent" flashVars="'+flashvars+'"'+
			'   	pluginspage="http://www.macromedia.com/go/getflashplayer"; '+
			'	    type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>'+
		' </object>';
		
		
		document.write(html);
	},
	getVersion : function () {
		
	}
};

Fosta.Adv = {
	put : function(advid) {
		new Ajax.Request('adv.php?id='+advid, {
			method: 'post',
			onSuccess: function(transport){
				
				document.getElementById('adv'+advid).innerHTML = transport.responseText;
	    	},
	    	onFailure: function(){ 
			
			}
		});	
	}
};

Fosta.Wysiwyg = {
		
	create : function(areaid) {
		this.id = areaid;
		
		this.area = document.getElementById(areaid+'_area');
		this.preview = document.getElementById(areaid+'_preview');
			
		this.previewChange();
	},
	previewChange : function() {
			
		var value = this.area.value;
			
		value = value.replace(/\n/g,'<br/>');
			
		document.getElementById(this.id).value = value;
			
		this.preview.innerHTML = value;
			
	},
	getSelection : function() {
		this.area.focus();  
		
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(start);
		var sel = this.area.value.substring(start,end);
			
		return sel;
	},
	setB : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<b>"+sel+"</b>"+selAft;
		}
		this.previewChange();
	},
	setI : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<i>"+sel+"</i>"+selAft;
		}
		this.previewChange();		
	},
	setA : function() {
		var link = prompt("Podaj adres odnośnika");
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			sel = prompt("Podaj nazwe odnośnika");
		} 
			
		this.area.value = selBef+"<a href=\""+link+"\">"+sel+"</a>"+selAft;
			
	},
	setH1 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			
		} else {
			this.area.value = selBef+"<h1>"+sel+"</h1>"+selAft;
		}
		this.previewChange();		
	},
	setH2 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<h2>"+sel+"</h2>"+selAft;
		}
		this.previewChange();		
	},
	setH3 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			
		} else {
			this.area.value = selBef+"<h3>"+sel+"</h3>"+selAft;
		}
		this.previewChange();		
	},	
	setUL : function() {
			
	},
	setOL : function() {
			
	}			
};





	

