var s2tWare = {
	    name            : 's2tWare',
        id              : '#s2tWare',
        /* s2tWare options */
        height          : 'max',
        width           : 'max',
        margin          : '10',
        /*-> Logo */
        logoWidth       : '182',
        logoHeight      : '153',
        /*-> Timing */
        fadeInDuration  : '700',
        fadeOutDuration : '200',
        elements        : ['tabbedCats', 'playlists', 'contents'],
        baseUrl         : '/templates/rhuk_milkyway/s2tWare/',
        /*-> other */
        display         : false,
	    loaded		: false, 
        scrollWidth     : '20',
        onMove          : false, 
        /* ajax list Load */
        comUrl          : '/index2.php?option=com_s2tWare&task=',

        htmlElement : {
            playSound:      '.playSound',
            playerListAdd:  '.playerList-add',
            playerToggle : '#s2tPlayerToggle, .s2tWLogo',
	        wrapper:		'#wrapper'
        },
        /* methodes générales */
        constructHtml: function () {
            var HTML  = '<a href="javascript:void(0)" id="s2tPlayerToggle"></a>';
                HTML += '<div id="s2tWare"><div class="s2tLogo"></div></div>';
            $j('body').prepend(HTML);
        },
        hide: function() {
	       var me = this; 
           $j('body').css({"overflow-y":"scroll"})
           $j('#ja-wrapper').css({marginRight: 0})
           $j(me.id).fadeOut( this.fadeOutDuration, function(){ $j(this).hide(); });
           me.display = false;
        },
        init: function() {
            this.constructHtml(); 
            playerUi.constructHtml();
            playlistUi.constructHtml();
            playerUi.update();
            this.initBinds();
        },
        initBinds : function () {
            me = this;
            _html = me.htmlElement;
            $j('body').click(function(e){
                tar = $j(e.target);
                if(!tar.parents(".context.on").length) { 
                    $j('.on').removeClass('on');
                }
            });
            $j(_html.playerToggle).click(function(e) {
                if(typeof(window.event) == 'undefined')
                {  isWare = e.shiftKey }
                else {isWare = window.event.shiftKey}
                s2tWare.toggle(isWare);
            });
            $j(".s2tLogo").click(function(e) {
                if(typeof(window.event) == 'undefined')
                {  isWare = e.shiftKey }
                else {isWare = window.event.shiftKey}
                s2tWare.toggle(isWare);
            });

            $j(window).bind('resize', function() {
                s2tWare.resize();
            });

            /** binds tabbedCats **/
            $j('#s2tWare-tabbedCats .list tr').live('click', function() {
                contents.unSelectTr("playlists")
                contents.loadSoundList($j(this).attr("id"));
                return false;
            });
            $j('#s2tWare-tabbedCats .tabs a').live('click', function() {
                tabbedCats.loadCatsList($j(this).attr("id"));
                return false;
            });
            $j('#s2tWare-contents .tabs a').live('click', function() {
                contents.loadCatsContent($j(this).attr("id"));
                return false;
            });
            $j('#s2tWare-playlists .tabs a').live('click', function() {
                playlists.loadPlayLists($j(this).attr("id"));
                return false;
            });
            $j('#newPLaylist a').live('click', function() {
                playlists.createNewlist($j(this).parent().find('input').attr('value'));
                return false;
            });
            $j('#s2tWare-playlists .list tr').live('click', function() {
                contents.unSelectTr("tabbedCats")
                contents.loadSoundList($j(this).attr("id"));
                return false;
            });
            
            /* binds rémo */
            $j(s2tWarePlayer.htmlElement.playerListAdd).live('click', function() {
                s2tWarePlayer.addToPlaylist(this.id); 
            });
            $j(s2tWarePlayer.htmlElement.playSound).live('click', function() {
                s2tWarePlayer.getSound(this.id, false, true); 
            });

        },
        initAll: function () {
            this.innerConstruct();
            this.show();
        },
        innerConstruct: function() {
            tabbedCats.init()
            playlists.init()
            contents.init()
            playZone.init()
            this.resize();
	        this.loaded = true; 
        },
        resize: function() {
            if(this.display) {
                this.height = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || $(window).innerHeight()) - this.margin*2;
                this.width = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || $(window).innerHeight()) - this.margin*2 - this.scrollWidth;
                $j('#s2tWare').css ({ "width": this.width +"px", "height": this.height +"px", 'left': this.margin + 'px', top: this.margin + "px"})
                tabbedCats.resize();
                playlists.resize();
                playZone.resize();
                contents.resize(); 
            }
        },
        show: function(){
           var me = this
	        s2tWarePlayer.closeInterface();	
            $j('body').css({"overflow-y":"hidden"})
            $j('#ja-wrapper').css({marginRight: 16})
            $j(this.id).fadeIn(this.fadeInDuration);
            this.display = true;
            this.resize();
        },

        toggle: function(s2tWare) {
            s2tLog(playerUi.isOnMove + " " + playlistUi.isOnMove);
            
            if(!playerUi.isOnMove && !playlistUi.isOnMove) {    
                if( !popupPlayer ) { 
                        s2tWarePlayer.openPopup(); 
                } 
                if (playerUi.loaded && !s2tWarePlayer.open) { 
                    if(this.loaded && this.display) {
                        this.hide();
                    }
                    s2tWarePlayer.openInterface(); 
                } else {  
                    if(!this.loaded && s2tool.isUser) { this.initAll(); }
                    else if (!this.display) { 
                        this.show();
                        window.scrollTo(0,0);
                    }
                    s2tWarePlayer.closeInterface();
                }
            } 
        },

	    isIE: function () {
	        if (navigator.appName == "Microsoft Internet Explorer") {    return  true;    }
             else { return false }
	    },
	    getTheDamnOffset: function (e) {
	        var targetOffset = $j(this.getTheDamnTarget(e)).offset(); 
	        var OffsetX, OffsetY; 	      
	        if (this.isIE()){
		        OffsetX = window.event.offsetX;
		        OffsetY = window.event.offsetY;
	        } else if ($j.browser.safari) {
		        OffsetX = e.offsetX
		        OffsetY = e.offsetY
            } else {
	            OffsetX = e.pageX - targetOffset.left;
	            OffsetY = e.pageY - targetOffset.top;
	        }	
            return { x:OffsetX, y:OffsetY };
	    },
	    getTheDamnTarget: function(e) {
	        if(this.isIE()){
		        return (e && e.target?e.target:window.event.srcElement);
	        } else {
		        return e.target;
	        }
        }
}

