
function BitChannelPlayer(bckey){
	this._bckey = bckey;
	
	//default values
	this._gallery=1;
	this._galleryitems = 20;
	this._galleryitemwidth = 120;
	this._paginator = 1;
	this._player=1;
	this._playeruri = '';
	this._itemtitlemaxchars = 50;
	this._layout='standard';
	this._styles = new Array();
}

BitChannelPlayer.prototype.hideGallery = function(){
	this._gallery = 0;
}

BitChannelPlayer.prototype.hidePaginator = function(){
	this._paginator = 0;
}

BitChannelPlayer.prototype.hidePlayer = function(){
	this._player = 0;
}

BitChannelPlayer.prototype.loadVideo = function(v){
	this._loadVideo = v;
}

BitChannelPlayer.prototype.setHeight = function(v){
	this._height = v;
}

BitChannelPlayer.prototype.setWidth = function(v){
	this._width = v;
}

BitChannelPlayer.prototype.setLayout = function(v){
	this._layout = v;
	if(v=='compactGallery'){
		this.setWidth(420);
		this.setHeight(1100);
	} else {
		this.setWidth(410);
		this.setHeight(470);
	}
}

BitChannelPlayer.prototype.setGalleryPageItems = function(v){
	this._galleryitems = v;	
}

BitChannelPlayer.prototype.setGalleryItemWidth = function(v){
	this._galleryitemwidth = v;	
}

BitChannelPlayer.prototype.setPlayerUri = function(v){
	this._playeruri = v;
}

BitChannelPlayer.prototype.addStyle = function(c, k, v){
	this._styles.push(c+'{'+k+':'+v+';}');
}

BitChannelPlayer.prototype.setItemTitleMaxChars = function(v){
		this._itemtitlemaxchars = v;
}

BitChannelPlayer.prototype.render = function(elId)
{
	var newIframe = document.createElement('iframe');
	
	var cnturl = location.href;
	if(this._playeruri!=''){
		cnturl = this._playeruri;
	}
	
	var iframesrc = 'http://www.bit-channel.it/services/externalplayer?bckey='+this._bckey;
	iframesrc += '&rnd=4c80cb66a0640';
	iframesrc += '&layout='+this._layout;
	iframesrc += '&gallery='+this._gallery;
	iframesrc += '&galleryitems='+this._galleryitems;
	iframesrc += '&paginator='+this._paginator;
	iframesrc += '&player='+this._player;
	iframesrc += '&cnturl='+escape(cnturl);
	iframesrc += '&galleryitemwidth='+this._galleryitemwidth;
	
	iframesrc += '&itemtitlemaxchars='+this._itemtitlemaxchars;
	
	if(this._loadVideo){
		iframesrc += '&bcvpid='+this._loadVideo;
	}
	
	if(this._playeruri!=''){
		iframesrc += '&playeruri='+escape(this._playeruri);
	}
	
	if(this._styles.length>0){
		iframesrc += '&styles='+escape(this._styles.join(''));	
	}
	
	newIframe.src = iframesrc;
	
	if(this._width){
		newIframe.width=this._width;
	}else{
		newIframe.width=660;
	}
	
	if(this._height){
		newIframe.height=this._height;
	}else{
		if(this._gallery==1){
			newIframe.height=980;
		}else{
			newIframe.height=380;
		}
	}
	newIframe.style.border=0;
	newIframe.frameBorder=0;
	newIframe.scrolling='no';
	newIframe.style.overflow='hidden';
	newIframe.style.margin=0;
	newIframe.style.padding=0;
	var oldDiv = document.getElementById(elId);
	var para = oldDiv.parentNode;
	para.replaceChild(newIframe,oldDiv);
}