function clearText(thefield){
    if (thefield.defaultValue==thefield.value)
        thefield.value = ""
} 

// Extend inplace editor to allow html tags
Object.extend(Ajax.InPlaceEditor.prototype, {
    onLoadedExternalText: function(transport) {
        Element.removeClassName(this.form, this.options.loadingClassName);
        this.editField.disabled = false;
        this.editField.value = transport.responseText;
        Field.scrollFreeActivate(this.editField);
    }
});

Object.extend(Ajax.InPlaceEditor.prototype, {
    getText: function() {
        return this.element.childNodes[0] ? this.element.childNodes[0].nodeValue : '';
    }
});


Ajax.Responders.register({
    onCreate: function() {
        if (Ajax.activeRequestCount > 0)
            Element.appear('activityIndicator', {duration:0.5});
    },
    onComplete: function() {
        if (Ajax.activeRequestCount == 0)
            Element.fade('activityIndicator', {duration:0.3});
    }
});


HelpBalloon.Options.prototype = Object.extend(
    HelpBalloon.Options.prototype,
    {
        icon: '/public/images/hb/icon.gif',
        button: '/public/images/hb/button.png',
        balloonPrefix: '/public/images/hb/balloon-',
        cacheRemoteContent: false
    }
);




/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 */
/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 */
var handlePrevButtonState = function(type, args) {

    var enabling = args[0];
    var leftImage = args[1];
    if(enabling) {
        leftImage.src = "http://media.grooveattack.com/images/carousel/left_enabled_blue.png";    
    } else {
        leftImage.src = "/public/images/carousel-button-disabled.png";    
    }
};

var handleNextButtonState = function(type, args) {
    var enabling = args[0];
    var rightImage = args[1];

    if(enabling) {
        rightImage.src = "http://media.grooveattack.com/images/carousel/right_enabled_blue.png";
    } else {
        rightImage.src = "/public/images/carousel-button-disabled.png";
    }

};
var showButtons = function(type, args) {
    YAHOO.util.Dom.setStyle("next-arrow", "visibility", "visible");
    YAHOO.util.Dom.setStyle("prev-arrow", "visibility", "visible");
};

function countChildElements(parent, child)
     {
          var parent = document.getElementById(parent);
          var childCount = parent.getElementsByTagName(child).length;
  	      return childCount;
     }




var loader = new YAHOO.util.YUILoader({
    
    base: "http://media.grooveattack.com/javascripts/yui/build/",
    require: ["menu","button","animation"],
    
    loadOptional: false,
     //Set your skins member here:
    skin: {
        // The default skin, which is automatically applied if not
        // overriden by a component-specific skin definition.
        // Change this in to apply a different skin globally 
       

        // Any component-specific overrides can be specified here,
        // making it possible to load different skins for different
        // components. It is possible to load more than one skin
        // for a given component as well.
        overrides: { 
            menu: ['none']
            
        }
    },
    onSuccess: function(o) {
        
        // main menubar for site
        YAHOO.util.Event.onContentReady("ga_menubar", function () {
            var oMenuBar = new YAHOO.widget.MenuBar(
                "ga_menubar", {
                    autosubmenudisplay: true
                });                    
                oMenuBar.render(); 
            }
        );

		// carousel 2
		 YAHOO.util.Event.onContentReady("ga_carousel_parent", function () {
		 var carousel = new YAHOO.extension.Carousel("ga_carousel", {
		 numVisible: 6,
		 animationSpeed: 0.9,
		 scrollInc: 2,
		 navMargin: 20,
		 prevElement: "prev-arrow",
		 nextElement: "next-arrow",
		prevButtonStateHandler:   handlePrevButtonState,
		            nextButtonStateHandler:   handleNextButtonState,
		size: countChildElements("ga_carousel_parent","li"),
		 wrap: true,
		autoPlay: 0
		 //prevButtonStateHandler: handlePrevButtonState,
		 //nextButtonStateHandler: handleNextButtonState
		 });
		 });
		
		
			// carousel 2
			 YAHOO.util.Event.onContentReady("hl_carousel_parent", function () {
			 var carousel = new YAHOO.extension.Carousel("hl_carousel", {
			 numVisible: 6,
			 animationSpeed: 0.9,
			 scrollInc: 2,
			 navMargin: 20,

			 prevElement: "prev-arrow",
			 nextElement: "next-arrow",
			prevButtonStateHandler:   handlePrevButtonState,
			            nextButtonStateHandler:   handleNextButtonState,
			size: countChildElements("hl_carousel_parent","li"),
			 wrap: true,
			autoPlay: 0
			 //prevButtonStateHandler: handlePrevButtonState,
			 //nextButtonStateHandler: handleNextButtonState
			 });
			 });
		
		//countChildElements("smallcarousel_parent","li");
		YAHOO.util.Event.onContentReady("news_carousel_parent", function () {
		 var carousel = new YAHOO.extension.Carousel("news_carousel", {
		 numVisible: 1,
		 animationSpeed: 8,
		orientation:'vertical',
		 scrollInc: 1,
		 navMargin: 20,
		 //prevElement: "prev-arrow",
		 //nextElement: "next-arrow",
		prevButtonStateHandler:   handlePrevButtonState,
		            nextButtonStateHandler:   handleNextButtonState,
		size: countChildElements("news_carousel_parent","li"),
		 wrap: true,
		autoPlay: true
		 //prevButtonStateHandler: handlePrevButtonState,
		 //nextButtonStateHandler: handleNextButtonState
		 });
		 });
		

       
        
        // buttons
        YAHOO.util.Event.onContentReady("submitbutton1", function () {
            var oButton = new YAHOO.widget.Button("submitbutton1", { value: "submitbutton1value" });  
        });
        
        YAHOO.util.Event.onContentReady("submitbutton2", function () {
            var oButton = new YAHOO.widget.Button("submitbutton2", { value: "submitbutton1value" });  
        });
        
        YAHOO.util.Event.onContentReady("submitbutton_search", function () {
            var oButton = new YAHOO.widget.Button("submitbutton_search", { value: "Go" });  
        });        
    }
});
loader.insert();

