// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function resizePlayer() {
    embed = document.getElementById("zoundsPlayerEmbed");
    obj = document.getElementById("zoundsPlayer");
    if (embed != null) {
        embed.setAttribute('height', 180);
    }
    if (obj != null) {
        obj.setAttribute('height', 180);
    }
}

var querystring = window.location.search.substring(1);

function windowHref(loc) {
    window.location.href = loc;
}

function buyNow(productId) {
    showPopWin('/store/variation_selection/' + productId, 600, 400, null, true);
}

Tab = Class.create({
    initialize: function(divId, activeImageSrc, inactiveImageSrc, continuationDiv, continuationStyle) {
        this.divId = divId;
        this.activeImageSrc = "url(" + activeImageSrc + ")";
        this.inactiveImageSrc = "url(" + inactiveImageSrc + ")";
        this.continuationDiv = continuationDiv;
        this.continuationStyle = continuationStyle;
    },
    activate: function() {
        $(this.divId).style.backgroundImage = this.activeImageSrc;
        $(this.continuationDiv).className = this.continuationStyle;
    },
    deactivate: function() {
        $(this.divId).style.backgroundImage = this.inactiveImageSrc;
    },
    getName: function(){
        return this.divId;
    }
});

TabState = Class.create({
    initialize: function(tabs){
        this.tabs = tabs;
        this.currentTab = tabs.first();
    },
    setActive: function(tabName){
        if (this.currentTab.getName() != tabName){
            for (var index = 0; index < this.tabs.length; ++index){
                var t = this.tabs[index];
                if (t.getName() == tabName){
                    this.currentTab = t;
                    t.activate();
                } else {
                    t.deactivate();
                }
            }
        }
    }
});


var tabs = new TabState(
    [
        new Tab("tab1", "/images/tab_store_enabled.gif", "/images/tab_store_disabled.gif", "tab-continuation", "tab-cont-1"),
        new Tab("tab2", "/images/tab_mymix_enabled.gif", "/images/tab_mymix_disabled.gif", "tab-continuation", "tab-cont-2")
    ]
);

function showSubmittingWin(div) {
        width = 300;
        height = 300;
        document.getElementById("popCloseBox").style.display = "none";
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);

	var titleBarHeight = 0;


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = height + "px";

	setMaskSize();

	document.getElementById('popupInner').innerHTML = document.getElementById(div).innerHTML;

	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}

}

/**
 * Changes the value of the given element to proper case, by capitalizing the first letter.
 *
 * - element_id: The ID of the element whose value needs to be converted into proper case.
 * 
 */
function ProperCase(element_id) {
    var value = $(element_id).value;
    $(element_id).value = value.toLowerCase().replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); });
}

/**
 * The default namespace for all the custom methods.
 */
YesFitnessMusic = {
	/**
	 * Toggles the comment boxes on the account_details partial. Selecting "Other"
	 * shows the comment box. Selecting any other item, hides those boxes.
	 *
	 * - sId: The ID of the select tag.
	 * - tId: The ID of the text area to toggle.
	 */
    toggleCommentBoxesOnAccountDetails: function(sId, tId) {
        if ($(sId)[$(sId).selectedIndex].text == "Other") {
            $(tId).show("blind");
            Effect.BlindDown(tId, {
                duration: 0.5
            });
        } else {
            Effect.BlindUp(tId, {
                duration: 0.5
            });
        }
    }
};

/* protoload 0.1 beta by Andreas Kalsch
 * last change: 09.07.2007
 *
 * This simple piece of code automates the creating of Ajax loading symbols.
 * The loading symbol covers an HTML element with correct position and size - example:
 * $('myElement').startWaiting() and $('myElement').stopWaiting()
 */
 
Protoload = {
	// the script to wait this amount of msecs until it shows the loading element
	timeUntilShow: 0,
	
	// opacity of loading element
	opacity: 0.8,

	// Start waiting status - show loading element
	startWaiting: function(element, className, timeUntilShow) {
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (className == undefined)
			className = 'bigWaiting';
		if (timeUntilShow == undefined)
			timeUntilShow = Protoload.timeUntilShow;
		
		element._waiting = true;
		if (!element._loading) {
			var e = document.createElement('div');
			(element.offsetParent || document.body).appendChild(element._loading = e);
			e.style.position = 'absolute';
			try {e.style.opacity = Protoload.opacity;} catch(e) {}
			try {e.style.MozOpacity = Protoload.opacity;} catch(e) {}
			try {e.style.filter = 'alpha(opacity='+Math.round(Protoload.opacity * 100)+')';} catch(e) {}
			try {e.style.KhtmlOpacity = Protoload.opacity;} catch(e) {}
			
			/*var zIndex = 0;
			if (window.UI)
				if (UI.zIndex)
					zIndex = ++UI.zIndex;
			if (!zIndex)
				zIndex = ++Protoload._zIndex;
			e.style.zIndex = zIndex;*/
		}
		element._loading.className = className;
		window.setTimeout((function() {
			if (this._waiting) {
				var left = this.offsetLeft, 
					top = this.offsetTop,
					width = this.offsetWidth,
					height = this.offsetHeight,
					l = this._loading;
					
				l.style.left = left+'px';
				l.style.top = top+'px';
				l.style.width = width+'px';
				l.style.height = height+'px';
				l.style.display = 'inline';
			}
		}).bind(element), timeUntilShow);
	},
	
	// Stop waiting status - hide loading element
	stopWaiting: function(element) {
		if (element._waiting) {
			element._waiting = false;
			element._loading.parentNode.removeChild(element._loading);
			element._loading = null;
		}
	}/*,
	
	_zIndex: 1000000*/
};

if (Prototype) {
	Element.addMethods(Protoload);
	Object.extend(Element, Protoload);
}
/* End of Protoload */