﻿/* jQuery plugin roomswitcher
---------------------------------------------------------------------*/
$.fn.roomswitcher = function(settings) {
    var options = jQuery.extend({
        loadTheme: null,
        width: 150,
        height: 200,
        closeOnSelect: true,
        buttonHeight: 14,
        onOpen: function() { },
        onClose: function() { },
        onSelect: function() { }
    }, settings);

    //markup 
    var button = $('<a href="#" id="switcher_trigger" class="button_default"><span id="switcher_icon" class="switcher_icon">' + options.switchPrompt + '</span><span id="switcher_title" class="switcher_title">' + options.initialText + '</span></a>');
    var switcherpane = $(options.panel);

    //button events
    button.click(
		function() {
		    if (switcherpane.is(':visible')) { switcherpane.spHide(); }
		    else { switcherpane.spShow(); }
		    return false;
		}
	);

    //menu events (mouseout didn't work...)
    switcherpane.hover(
		function() { },
		function() { if (switcherpane.is(':visible')) { $(this).spHide(); } }
	);

    //show/hide panel functions
    $.fn.spShow = function() {
        $(this).css({
            top: button.offset().top + options.buttonHeight + 6,
            left: button.offset().left
        }).slideDown('fast');
        //	                button.removeClass();
        //	                button.addClass("button_active"); 
        options.onOpen();
    }
    $.fn.spHide = function() {
        $(this).slideUp('fast', function() { options.onClose(); });
        //	        button.removeClass();
        //	        button.addClass("button_default"); 
    }


    /* Theme Loading
    ---------------------------------------------------------------------*/
    switcherpane.find('a').click(function() {
        var themeName = $(this).find('span').text();
        button.find('#switcher_title').text(options.buttonPreText + themeName);
        options.onSelect($(this), $(this).attr('rel'));
        if (options.closeOnSelect && switcherpane.is(':visible')) { switcherpane.spHide(); }
        return false;
    });

    /* Inline CSS 
    ---------------------------------------------------------------------*/
    switcherpane.find('ul').find('li').hover(function() {
        $(this).removeClass(); $(this).addClass("mOver");
    }, function() {
        $(this).removeClass();
        $(this).addClass("mOut");
    });

    //	//button css
    //	button.css(button_default)
    //	.hover(
    //		function(){ 
    //			$(this).css(button_hover); 
    //		},
    //		function(){ 
    //		 if( !switcherpane.is(':animated') && switcherpane.is(':hidden') ){	$(this).css(button_default);  }
    //		}	
    //	)
    //	
    //pane css





    // .css({

    //	}).end()

    //	.find('img').css({
    //		float: 'left',
    //		border: '1px solid #333',
    //		margin: '0 2px'
    //	}).end()
    //	.find('.themeName').css({
    //		float: 'left',
    //		margin: '3px 0'
    //	}).end();


    $(this).append(button);
    switcherpane.hide();

    return this;
};


