/*
window.onload = function() {
      settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true
      }
      var myBoxObject = new curvyCorners(settings, "rounded");
      myBoxObject.applyCornersToAll();
  }
*/


/*  Needed for concealer
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
function clearText(thefield){
    if (thefield.defaultValue==thefield.value)
        thefield.value = ""
}
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function conceal(classname) {
	var arguments = getElementsByClassName('conceal','span');
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : '' );
	}
}
function expand_all(classname) {
	var arguments = getElementsByClassName('text','tr');
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : '' );
	}
}

// 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: '/images/hb/icon.gif',
        button: '/images/hb/button.png',
        balloonPrefix: '/images/hb/balloon-',
        cacheRemoteContent: false
    }
);

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 = "http://media.grooveattack.com//images/clear.gif";    
    }
};

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 = "http://media.grooveattack.com//images/clear.gif";
    }

};
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","container"],
    loadOptional: false,   

    onSuccess: function(o) {

	YAHOO.util.Event.onContentReady("ga_menubar", function () {
	            var gaMenuBar = new YAHOO.widget.MenuBar("ga_menubar", { 
		                autosubmenudisplay: true, 
		                hidedelay: 750, 
		                lazyload: false });
		            gaMenuBar.render();

			var ua = YAHOO.env.ua,
			    oAnim;  // Animation instance


			/*
			     "beforeshow" event handler for each submenu of the MenuBar
			     instance, used to setup certain style properties before
			     the menu is animated.
			*/

			function onSubmenuBeforeShow(p_sType, p_sArgs) {

			    var oBody,
			        oElement,
			        oShadow,
			        oUL;


			    if (this.parent) {

			        oElement = this.element;

			        /*
			             Get a reference to the Menu's shadow element and 
			             set its "height" property to "0px" to syncronize 
			             it with the height of the Menu instance.
			        */

			        oShadow = oElement.lastChild;
			        oShadow.style.height = "0px";


			        /*
			            Stop the Animation instance if it is currently 
			            animating a Menu.
			        */ 

			        if (oAnim && oAnim.isAnimated()) {

			            oAnim.stop();
			            oAnim = null;

			        }


			        /*
			            Set the body element's "overflow" property to 
			            "hidden" to clip the display of its negatively 
			            positioned <ul> element.
			        */ 

			        oBody = this.body;


			        //  Check if the menu is a submenu of a submenu.

			        if (this.parent && 
			            !(this.parent instanceof YAHOO.widget.MenuBarItem)) {


			            /*
			                There is a bug in gecko-based browsers where 
			                an element whose "position" property is set to 
			                "absolute" and "overflow" property is set to 
			                "hidden" will not render at the correct width when
			                its offsetParent's "position" property is also 
			                set to "absolute."  It is possible to work around 
			                this bug by specifying a value for the width 
			                property in addition to overflow.
			            */

			            if (ua.gecko) {

			                oBody.style.width = oBody.clientWidth + "px";

			            }


			            /*
			                Set a width on the submenu to prevent its 
			                width from growing when the animation 
			                is complete.
			            */

			            if (ua.ie == 7) {

			                oElement.style.width = oElement.clientWidth + "px";

			            }

			        }


			        oBody.style.overflow = "hidden";


			        /*
			            Set the <ul> element's "marginTop" property 
			            to a negative value so that the Menu's height
			            collapses.
			        */ 

			        oUL = oBody.getElementsByTagName("ul")[0];

			        oUL.style.marginTop = ("-" + oUL.offsetHeight + "px");

			    }

			}


			/*
			    "tween" event handler for the Anim instance, used to 
			    syncronize the size and position of the Menu instance's 
			    shadow and iframe shim (if it exists) with its 
			    changing height.
			*/

			function onTween(p_sType, p_aArgs, p_oShadow) {

			    if (this.cfg.getProperty("iframe")) {

			        this.syncIframe();

			    }

			    if (p_oShadow) {

			        p_oShadow.style.height = this.element.offsetHeight + "px";

			    }

			}


			/*
			    "complete" event handler for the Anim instance, used to 
			    remove style properties that were animated so that the 
			    Menu instance can be displayed at its final height.
			*/

			function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {

			    var oBody = this.body,
			        oUL = oBody.getElementsByTagName("ul")[0];

			    if (p_oShadow) {

			        p_oShadow.style.height = this.element.offsetHeight + "px";

			    }


			    oUL.style.marginTop = "";
			    oBody.style.overflow = "";


			    //  Check if the menu is a submenu of a submenu.

			    if (this.parent && 
			        !(this.parent instanceof YAHOO.widget.MenuBarItem)) {


			        // Clear widths set by the "beforeshow" event handler

			        if (ua.gecko) {

			            oBody.style.width = "";

			        }

			        if (ua.ie == 7) {

			            this.element.style.width = "";

			        }

			    }

			}


			/*
			     "show" event handler for each submenu of the MenuBar 
			     instance - used to kick off the animation of the 
			     <ul> element.
			*/

			function onSubmenuShow(p_sType, p_sArgs) {

			    var oElement,
			        oShadow,
			        oUL;

			    if (this.parent) {

			        oElement = this.element;
			        oShadow = oElement.lastChild;
			        oUL = this.body.getElementsByTagName("ul")[0];


			        /*
			             Animate the <ul> element's "marginTop" style 
			             property to a value of 0.
			        */

			        oAnim = new YAHOO.util.Anim(oUL, 
			            { marginTop: { to: 0 } },
			            .5, YAHOO.util.Easing.easeOut);


			        oAnim.onStart.subscribe(function () {

			            oShadow.style.height = "100%";

			        });


			        oAnim.animate();


			        /*
			            Subscribe to the Anim instance's "tween" event for 
			            IE to syncronize the size and position of a 
			            submenu's shadow and iframe shim (if it exists)  
			            with its changing height.
			        */

			        if (YAHOO.env.ua.ie) {

			            oShadow.style.height = oElement.offsetHeight + "px";


			            /*
			                Subscribe to the Anim instance's "tween"
			                event, passing a reference Menu's shadow 
			                element and making the scope of the event 
			                listener the Menu instance.
			            */

			            oAnim.onTween.subscribe(onTween, oShadow, this);

			        }


			        /*
			            Subscribe to the Anim instance's "complete" event,
			            passing a reference Menu's shadow element and making 
			            the scope of the event listener the Menu instance.
			        */

			        oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);

			    }

			}


			/*
			     Subscribe to the "beforeShow" and "show" events for 
			     each submenu of the MenuBar instance.
			*/

		//	gaMenuBar.subscribe("beforeShow", onSubmenuBeforeShow);
	//		gaMenuBar.subscribe("show", onSubmenuShow);
        });
    
        
        // 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" });  
        });

        YAHOO.util.Event.onContentReady("email_form_submit", function () {
            var emailButton = new YAHOO.widget.Button("email_form_submit", { value: "Send message" });  
        });




 YAHOO.util.Event.onContentReady("sort_button", function () {
var sort_button = new YAHOO.widget.Button("sort_button", { type: "split",
                                        menu: "sort_button_menu" });
	});


		YAHOO.util.Event.onContentReady("ga_carousel_parent", function () {
		 var carousel = new YAHOO.extension.Carousel("ga_carousel", {
		 numVisible: 6,
		 animationSpeed: 0.5,
		 scrollInc: 3,
		 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
		 });
		 });
		
	
			YAHOO.util.Event.onContentReady("news_carousel_parent", function () {
			 var carousel = new YAHOO.extension.Carousel("news_carousel", {
			 numVisible: 1,
			 animationSpeed: 6,
			 scrollInc: 1,
			 navMargin: 0,
			animationMethod: null,
			size: countChildElements("news_carousel_parent","li"),
			wrap: true,
			autoPlay: 1,
			orientation:"vertical"

			 });
			 });


    }
    
     
});
loader.insert();