function showHidePremium(inSwitch) {
	 var vWait = inSwitch ? 500 : 0;
	 (function(){ 
	 	var vBan = $(document.body).getElement('div.premium_banner');
		if(vBan&&inSwitch)       vBan.setStyle('visibility','visible');
		else if(vBan&&!inSwitch) vBan.setStyle('visibility','hidden');
	 }).delay(vWait);
}

function initTips(inTips) {
	var vTips = new Tips(inTips, {'className':'nav-tips',
		onShow: function(toolTip) {
			this.eff.start(0,1);
		},
		onHide: function(toolTip) {
			this.eff.start(1,0);
		}
	});
	vTips.eff = new Fx.Style(vTips.toolTip,'opacity',{wait:false});
	$$(inTips).each(function(a){ 
		if (a.hasClass('fr')) {
			a.addEvents({
				'mouseover': function(){ showHidePremium(false) },
				'mouseout': function(){ showHidePremium(true) }
			})
		}
	});
}

var ajaxVideoKarusel = new Class({
	initialize: function(inUrl,inOptions) {
		this.tElems   = '#ajaxKarusel img.voidTips';
		this.tUrl     = inUrl;
		this.tOptions = {
			onComplete: function(response) { this._after() }.bind(this), 
			onFailure:  function()         { alert('Ajax Error') } 
		};
		$extend(this.tOptions,inOptions);
	},
	_effect: function(inWait,inShow) {
		var vStart = 0;
		$$(this.tElems).each(function(img){ 
			vStart = vStart + inWait;
			(function(){ 
				var vEff = new Fx.Style(img,'opacity',{wait:false}).start((inShow ? 0 : 1),(inShow ? 1 : 0));
			}).delay(vStart);
		});
	},
	_before: function() {
		this._effect(100,false);
		if ($('getNext')) {
			$('getNext').innerHTML='';
			new Element('a',{'class':'fr karusel_right_end'}).inject($('getNext'));
		}
		if ($('getPrev')) {
			$('getPrev').innerHTML='';
			new Element('a',{'class':'fl karusel_left_end mrt_small'}).inject($('getPrev'));
		}
	},
	_after: function() {
		initTips(this.tElems);
		this._effect(100,true);
	},
	prev: function(inId) {
		this._before();
		$H(this.tOptions).extend({'data':'ajaxPrevId=' + inId.toInt() + (this.tOptions.prikolId ? '&ajaxPrikolId=' + this.tOptions.prikolId.toInt() : '')});
		(function(){ this.send() }.bind(this)).delay(1000);
	},
	next: function(inId) {
		this._before();
		$H(this.tOptions).extend({'data':'ajaxNextId=' + inId.toInt() + (this.tOptions.prikolId ? '&ajaxPrikolId=' + this.tOptions.prikolId.toInt() : '')});
		(function(){ this.send() }.bind(this)).delay(1000);
	},
	send: function() {
		new Requester(this.tUrl,this.tOptions);
	}
});

function sniveller(inUrl,inId,inLogin) {
	var vSpan=$('sniveller_' + inId);
	if (!inLogin) {
	    ShowLoginForm('');
	} else {
	    if (confirm(__REPLIC.sniveller)) {
	    new Requester(inUrl,{
    		data:'ajaxSniveller=' + inId,
    		onRequest: function() {
    			if (vSpan) {
    				vSpan.innerHTML=__REPLIC.ajaxWait + '...';
    				vSpan.setProperty('class','fl mar_link mrl ld small gray');
    			}
    		},
    		onFailure: function() {
    			if (vSpan) vSpan.innerHTML=__REPLIC.ajaxError;
    		},
    		onSuccess: function(inMess) {
    			if (vSpan) vSpan.innerHTML=inMess;
    			alert(__REPLIC.snivellerSend);
    		}
    	});
	    }
	}
	return false;
}

function playerEventStartMovie(inUrl) {
	
	var vId = inUrl.match(/\/(\d+)\.flv/i);
	    vId = vId && vId[1] ? vId[1] : 0;
	var vUpdate = $('viewsCount_' + vId);
	if (vId && vUpdate) {
		var vPr = vUpdate.getProperty('class').match(/voidId_(\d+)/i)
		    vPr = vPr && vPr[1] ? vPr[1] : 0;
		if (vPr) 
			new Requester('/countViews/', {
				update   : 'viewsCount_' + vId,
				data     : 'DEBUG_MODE=0&ajaxPrikolId=' + vPr,
				onRequest: function()       { vUpdate.setHTML(__REPLIC.ajaxWait + '...') },
				onFailure: function()       { vUpdate.setHTML(__REPLIC.ajaxError)        },
				onSuccess: function(inMess) { vUpdate.setHTML(inMess)                    }
			});
		
	}

}