window.addEvent('domready', function(){
    
    Clientcide.setAssetLocation('/assets/js/mootools/clientcide/Assets/');
    Clientcide.preLoadCss();
    
    // img.remooz
    ReMooz.assign('.remooz', {
        'origin': 'img',
        'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
        'resizeFactor': 0.8, // resize to maximum 80% of screen size
        'cutOut': false, // don't hide the original
        'opacityResize': 0.4, // opaque resize
        'dragging': false, // disable dragging
        'centered': true // resize to center of the screen, not relative to the source element
    });
	
	new Request({
	    method: 'get',
	    url: '/cs/user/main?x-p=cs_lay/ping',
		noCache: true,
	    initialDelay: 3000,
	    delay: 15000,
	    limit: 45000
	}).startTimer();
	
	$('toggle_chat_status').addEvent('click',function(e){
	    e.stop();
	    var status = this.get('text');
	    
	    if (status == 'ON') {
	        this.set('text','OFF');
	    } else {
	        this.set('text','ON');
	    }
	    
	    new Request({
    	    method: 'get',
    	    url: '/cs/user/main?x-p=cs_lay/toggle_chat_status;current_status=' + status,
    		noCache: true,
    		onSuccess: function(txt){
                location.reload(true);
    		}
    	}).send();
	});
});

/*
Pop up window in center of screen, if no params are set uses defaults
Example: onclick="popUp('/pub/htdocs/my_e-myth')" or onclick="popUp('/pub/htdocs/my_e-myth',{width:300,height:200,scrollbars:1})"
*/
function popUp(url,params){
    ($defined(params)) ? params : (params = {});
    var fromTop = screen.availHeight / 2 - $pick(params.height,400) / 2;
    var fromLeft = screen.availWidth / 2 - $pick(params.width,500) / 2;
    var settings =
        'height=' + $pick(params.height,400) +
        ',width=' + $pick(params.width,500) +
        ',top=' + fromTop +
        ',left=' + fromLeft +
        ',scrollbars=' + $pick(params.scrollbars,0) +
        ',resizable=' + $pick(params.resizable,1) +
        ',menubar=' + $pick(params.menubar,0) +
        ',toolbar=' + $pick(params.toolbar,0) +
        ',location=' + $pick(params.location,0) +
        ',statusbar=' + $pick(params.statusbar,0)
    ;
    win = window.open(url,'popUp',settings);
}
