/**
 * Main JS file for Dixcart blogs
 * Designed to be included last on the page
 * Depends on YUI
 * @author richard.benson
 */

// Just get everything set up
if (typeof RB == "undefined" || !RB) {
    var RB = {};
}

// Function to aid in making new namespaces
RB.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=RB;

        // RB is implied, so it is ignored if it is included
        for (j=(d[0] == "RB") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
}

// Create a namespace to put this all in
RB.namespace("blogs");

// Assign some useful YUI functions to our namespace
if (typeof YAHOO == "object") {
	//RB.Ld = YAHOO.util.YUILoader; // Loader not used on blogs yet
	RB.Dm = YAHOO.util.Dom;
	RB.Ev = YAHOO.util.Event;
} else {
	alert("YUI not loaded, functions will be impaired and other errors may occur.");
}

// Our main class wrapper
RB.blogs = function() {
	var o = {
		headerOverlayLoaded: false,
		headerOverlayVisible: false,
		
		init: function() {
			// Stick a listener on the "Explore" button to open/close the overlay
			RB.Ev.addListener("explore-dixcart-link", "click", RB.blogs.toggleOverlay);
		},
		
		toggleOverlay: function(e) {
			// Stop the A tag from doing it's job
			RB.Ev.preventDefault(e);
			
			// Check if the overlay has been created, if not, create it
			if (!this.headerOverlayLoaded) {
				this.headerOverlay = new YAHOO.widget.Overlay("header-explore-overlay", { 
					visible: false,
					context:["explore-dixcart-button","tl","bl", ["beforeShow", "windowResize"]],
					effect: {
						effect:YAHOO.widget.ContainerEffect.FADE,
						duration:0.25
					}
				});
				this.headerOverlay.render();
				this.headerOverlayLoaded = true;
			}
			
			// The actual toggle part, if it's open, close it and vice versa
			if (!this.headerOverlayVisible) {
				this.headerOverlay.show();
				this.headerOverlayVisible = true;
			} else {
				this.headerOverlay.hide();
				this.headerOverlayVisible = false;
			}
		}
		
	}
	
	return o;
}();

// Attach our initialisation function to DOMReady so it loads as soon
// as everything else is prepared
RB.Ev.onDOMReady(RB.blogs.init);

