$(document).ready(function(){
						   
if ($(".communitySection").length != 0) {

YAHOO.namespace("SW.local.CommunityArea");
(function(){
    var yuiDom = YAHOO.util.Dom;
    var yuiEvent = YAHOO.util.Event;

    var nHContainer = null;
    var nGSContainer = null;
    var nGSContainerTimeOut = null
    var nHContainerTimeOut = null;
    var normalizerTimeout = null

    SW.local.CommunityArea = {
        init: function() {
            nHContainer = yuiDom.get("newHotelsSection");

            var nHNormalizer = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsSection"),
                showAttributes: {width:{to: 241}},
                hideAttributes: {width:{to: 0}},
                showOnStart: function(config) {
                    nHContainer.contentNormalizer.show();
                    nHContainer.openToggler.hide();
                    nHContainer.closeToggler.hide();
                },
                showDuration:.500,
                hideDuration:.500
            });
            var nHContentNormalizer = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsContentContainer"),
                showAttributes: {width:{to: 241}},
                showOnStart: function () {
                    yuiDom.addClass(yuiDom.get("newHotels_leftContent"), "indicator");
                },
                showDuration:.500,
                hideDuration:.500
            });

            var nHToggler = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsSection"),
                showAttributes: {width:{to: 493}},
                hideAttributes: {width:{to: 20}},
                showOnStart: function(config) {
                    nHContainer.openToggler.hide();
                    nHContainer.contentToggler.show();
                    nGSContainer.toggler.hide();
                    yuiDom.removeClass(yuiDom.get("newHotels_leftContent"), "indicator");
                },
                showOnComplete: function() {
                    nHContainer.closeToggler.show();
                },
                hideOnStart: function() {
                    nHContainer.contentToggler.hide();
                    nHContainer.closeToggler.hide();
                },
                hideOnComplete: function () {
                    nHContainer.openToggler.show();
                },
                showDuration:.500,
                hideDuration:.500
            });

            var nHContentToggler = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsContentContainer"),
                showAttributes: {width: {to: 473}},
                hideAttributes: {width: {to: 0}},
                showDuration:.800,
                hideDuration:.500
            });

            var nHOpenHandleToggler = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsOpenHandle"),
                showAttributes: {width: {to: 15}, height: {to: 73}},
                hideAttributes: {width: {to: 0}, height: {to: 0}},
                showDuration:.300,
                hideDuration:.300
            });

            var nHCloseHandleToggler = SW.widget.displayToggler({
                element: yuiDom.get("newHotelsCloseHandle"),
                showAttributes: {width: {to: 15}, height: {to: 73}},
                hideAttributes: {width: {to: 0}, height: {to: 0}},
                showDuration:.300,
                hideDuration:.300
            });

            nHContainer.normalizer = nHNormalizer;
            nHContainer.contentNormalizer = nHContentNormalizer;
            nHContainer.toggler = nHToggler;
            nHContainer.contentToggler = nHContentToggler;
            nHContainer.openToggler = nHOpenHandleToggler;
            nHContainer.closeToggler = nHCloseHandleToggler;

            nGSContainer = yuiDom.get("newStoriesSection");

            var nGSNormalizer = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesSection"),
                showAttributes: {width:{to: 241}},
                hideAttributes: {width:{to: 0}},
                showOnStart: function(config) {
                    nGSContainer.contentNormalizer.show();
                    nGSContainer.openToggler.hide();
                    nGSContainer.closeToggler.hide();
                },
                showDuration:.250,
                hideDuration:.500
            });
            var nGSContentNormalizer = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesContentContainer"),
                showAttributes: {width:{to: 241}},
                showOnStart: function () {
                    yuiDom.addClass(yuiDom.get("newStories_leftContent"), "indicator");
                },                
                showDuration:.250,
                hideDuration:.500
            });

            var nGSToggler = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesSection"),
                showAttributes: {width:{to: 493}},
                hideAttributes: {width:{to: 20}},
                showOnStart: function(config) {
                    nGSContainer.openToggler.hide();
                    nHContainer.openToggler.show();
                    nHContainer.toggler.hide();
                    nGSContainer.contentToggler.show();
                    yuiDom.removeClass(yuiDom.get("newStories_leftContent"), "indicator");
                },
                showOnComplete: function() {
                    nGSContainer.closeToggler.show();
                },
                hideOnStart: function() {
                    nGSContainer.contentToggler.hide();
                    nGSContainer.closeToggler.hide();
                },
                hideOnComplete: function () {
                    nGSContainer.openToggler.show();
                },
                showDuration:.500,
                hideDuration:.500
            });

            var nGSContentToggler = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesContentContainer"),
                showAttributes: { width: {to: 493}},
                hideAttributes: {width: {to: 0}},
                showDuration:.800,
                hideDuration:.500
            });

            var nGSOpenHandleToggler = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesOpenHandle"),
                showAttributes: {width: {to: 15}, height: {to: 73}},
                hideAttributes: {width: {to: 0}, height: {to: 0}},
                showDuration:.300,
                hideDuration:.300
            });

            var nGSCloseHandleToggler = SW.widget.displayToggler({
                element: yuiDom.get("newStoriesCloseHandle"),
                showAttributes: {width: {to: 15}, height: {to: 73}},
                hideAttributes: {width: {to: 0}, height: {to: 0}},
                showDuration:.300,
                hideDuration:.300
            });


            nGSContainer.normalizer = nGSNormalizer;
            nGSContainer.contentNormalizer = nGSContentNormalizer;
            nGSContainer.toggler = nGSToggler;
            nGSContainer.contentToggler = nGSContentToggler;
            nGSContainer.openToggler = nGSOpenHandleToggler;
            nGSContainer.closeToggler = nGSCloseHandleToggler;

            yuiEvent.addListener(yuiDom.get("newHotelsContentContainer"), "mouseover", SW.local.CommunityArea.toggleNewHotels, nHContainer);
            yuiEvent.addListener(yuiDom.get("newStoriesContentContainer"), "mouseover", SW.local.CommunityArea.toggleNewStories, nGSContainer);

            yuiEvent.addListener(yuiDom.get("newHotelsOpenHandle"), "mouseover", SW.local.CommunityArea.toggleNewHotels, nHContainer);
            yuiEvent.addListener(yuiDom.get("newStoriesOpenHandle"), "mouseover", SW.local.CommunityArea.toggleNewStories, nGSContainer);

            yuiEvent.addListener(yuiDom.get("newHotelsCloseHandle"), "click", SW.local.CommunityArea.normalize, nHContainer);
            yuiEvent.addListener(yuiDom.get("newStoriesCloseHandle"), "click", SW.local.CommunityArea.normalize, nGSContainer);
//              stop the body event from triggering when we're inside area

            yuiEvent.addListener(yuiDom.get("communityArea"), "mouseover", function(e) {yuiEvent.stopPropagation(e);});
            yuiEvent.addListener(document.body, "mouseover", SW.local.CommunityArea.normalize);

        },
        toggleNewHotels: function(e) {
//                console.log("hover nh")
            if(nHContainerTimeOut == null) {
                if(nGSContainerTimeOut != null) {
                    clearTimeout(nGSContainerTimeOut);
                    nGSContainerTimeOut = null;
                }
                if(normalizerTimeout != null) {
                    clearTimeout(normalizerTimeout);
                    normalizerTimeout = null;
                }
//                    nHContainerTimeOut = setTimeout("console.log(\""+"show nH"+"\")", 1750);
                nHContainerTimeOut = setTimeout(SW.local.CommunityArea.showNewHotels, 500);
            }
            yuiEvent.stopPropagation(e);
        },
        showNewHotels: function () {
//                console.log("show nH");
            nHContainer.toggler.show();
        },
        toggleNewStories: function(e) {
//                console.log("hover ngs")
            if(nGSContainerTimeOut == null) {
                if(nHContainerTimeOut != null) {
                    clearTimeout(nHContainerTimeOut);
                    nHContainerTimeOut = null;
                }
                if(normalizerTimeout != null) {
                    clearTimeout(normalizerTimeout);
                    normalizerTimeout = null;
                }
//                  nGSContainerTimeOut = setTimeout("console.log(\""+"show nGS"+"\")", 1750);
                nGSContainerTimeOut = setTimeout(SW.local.CommunityArea.showNewStories, 500);
            }
            yuiEvent.stopPropagation(e);
        },
        showNewStories: function () {
//                console.log("show nGS");
            nGSContainer.toggler.show();
        },
        normalize: function(e) {
            if(normalizerTimeout == null) {
                if(nHContainerTimeOut) {
                    clearTimeout(nHContainerTimeOut);
                    nHContainerTimeOut = null;
                }
                if(nGSContainerTimeOut) {
                    clearTimeout(nGSContainerTimeOut);
                    nGSContainerTimeOut = null;
                }

                normalizerTimeout = setTimeout(SW.local.CommunityArea.doNormalize, 500);
            }
            yuiEvent.stopPropagation(e);
        },
        doNormalize: function() {
            if(nHContainer.toggler.isShowing() || nGSContainer.toggler.isShowing()) {
                nGSContainer.normalizer.show();
                nHContainer.normalizer.show();
                nHContainer.toggler.setIsShowing(false);
                nGSContainer.toggler.setIsShowing(false);
            }
        }
    };

    yuiEvent.onDOMReady(function() {
        SW.local.CommunityArea.init();
    });
})();

/*
* A YUI Animation Utility wrapper that toggles display properties of an element
*
* @author Hao Tan, Dan Langan
*/

/*
 !NB: when using displayToggler
 a) have the css to set the element (to be toggled) to have display none
 b) define .show css class if doesn't exist (just a css property of display: block)
 c) if setting up some custom animation, you will most likely have to override the showOnStart function in your config
    to fit your animation's needs (please see DEFAULT_CONFIG's showOnStart function)

Eample usage 1: instantiate a displayToggler object with some settings

var myToggler = SW.widget.displayToggler({
    // Required:
    element:yuiDom.get("formName")

    // optional:

    // showTriggers:,
    // hideTriggers:,
    // toggleTriggers:,

    // (see DEFAULT_CONFIG)
});

myToggler.show();
myToggler.hide();
myToggler.toggle();

yuiEvent.addListener("myShowButton", "click", myToggler.show, myToggler, true);
*/

/*
Example usage 2: defining custom event

yuiEvent.onDOMReady(function(){
    SW.widget.displayToggler({
        element:yuiDom.get("resFormContainer"),
        showTriggers:"bookNowBt",
        hideTriggers:"closewin",
        showAttributes: {
            height: {from: 0, to: 170},
            top: {from: 0, to: -175}
        },
        hideAttributes: {
            height: {from: 170, to: 0 },
            top: {from: -175, to: 0}
        },
        showOnStart: function (config) {
            yuiDom.setStyle(config.element,"height",0);
        }
    });
});

*/
YAHOO.namespace("SW.widget.displayToggler");

(function(){
    var yuiDom = YAHOO.util.Dom;
    var yuiEvent = YAHOO.util.Event;
    
    var DEFAULT_CONFIG = {
        element:null, // NOTE: this must be supplied

        showTriggers:null,
        hideTriggers:null,
        toggleTriggers:null,

        showClass:"show",
        animatingClass:"animating",
        showDelay:0.35,
        hideDelay:0.5,
        showDuration:.175,
        hideDuration:.25,
        showTransition:YAHOO.util.Easing.easeNone,
        hideTransition:YAHOO.util.Easing.easeNone,
        showAttributes:{
            opacity:{from:0,to:1}
        },
        hideAttributes:{
            opacity:{from:1,to:0}
        },
        showOnStart:function(config){
//            yuiDom.setStyle(config.element,"opacity",0);
        },
        hideOnStart:function(config){
            // do nothing
        },
        showOnComplete:function(config){
            // do nothing
        },
        hideOnComplete:function(config){
            // do nothing
        }
    };

    function Toggler(config){
        if(!config.element){
            throw("no element supplied to Toggler");
        }

        for(var prop in DEFAULT_CONFIG) {
            if(!config.hasOwnProperty(prop)){
                config[prop] = DEFAULT_CONFIG[prop];
            }
        }

        var isShowing = !!config.isShowing;
        var animIn = new yuiAnim(config.element, config.showAttributes, config.showDuration, config.showTransition);
        animIn.onStart.subscribe(function(){
            yuiDom.addClass(config.element,config.showClass);
            yuiDom.addClass(config.element,config.animatingClass);
            config.showOnStart(config);
        });
        animIn.onComplete.subscribe(function(){
            yuiDom.removeClass(config.element,config.animatingClass);
            config.showOnComplete(config);
        });
        var animOut = new yuiAnim(config.element, config.hideAttributes, config.hideDuration, config.hideTransition);
        animOut.onStart.subscribe(function(){
            yuiDom.addClass(config.element,config.animatingClass);
            config.hideOnStart(config);
        });
        animOut.onComplete.subscribe(function(){
            yuiDom.removeClass(config.element,config.animatingClass);
            yuiDom.removeClass(config.element,config.showClass);
            config.hideOnComplete(config);
        });


        var self = {
            show:function(){
                isShowing = true;
                animIn.animate();
            },
            hide:function(){
                isShowing = false;
                animOut.animate();
            },
            toggle:function(){
                if(isShowing){
                    self.hide();
                }else{
                    self.show();
                }
            },
            isShowing: function() {
                return isShowing;
            },
            setIsShowing: function(showStatus) {
                isShowing = showStatus;
            }
        };

        if(config.showTriggers){
            yuiEvent.addListener(config.showTriggers, "click", self.show, self, true);
        }
        if(config.hideTriggers){
            yuiEvent.addListener(config.hideTriggers, "click", self.hide, self, true);
        }
        if(config.toggleTriggers){
            yuiEvent.addListener(config.toggleTriggers, "click", self.toggle, self, true);
        }

        return self;
    }

    SW.widget.displayToggler = function(config){
        return new Toggler(config);
    };
    
})();


}
});
