var tabImage;
window.addEvent('domready', function() {
	if ($('tabs'))	StartTabs();

	// Create variables (in this case two arrays) representing our bubbles and pages
	var myPages = $$('.wrapperbox');
	var myBubbles = $$('.bubble');
	var speed = 350;
	var menuSpeed = 400;

	// Set bubbles opacity to zero so they're hidden initially and toggle visibility on for their container
	if (myBubbles[0]) {
		myBubbles.setStyle('opacity', 0);
		$('bubbleWrap').setStyle('visibility','visible')
	}

	// Add our events to the pages
	if (myPages) {
		myPages.each(function(el, i) {
			el.addEvents({
				'mouseenter': function() {
					 var flx1 = new Fx.Styles(myBubbles[i], {duration: speed, wait: false, transition: Fx.Transitions.linear}).start({'opacity': 1,'margin-top': -15});
				},
				'mouseleave' : function() {
					var flx1 = new Fx.Styles(myBubbles[i], {duration: speed, wait: false, transition: Fx.Transitions.linear}).start({'opacity': 0,'margin-top': 0});
				}
			});
		});
	}

/*    var mainMenu = $$('#main-menu li');
    mainMenu.each(function(el, i) {
		var subMenu = el.getElementsByTagName('ul')[0];

		if (subMenu && (el.className.search('current_page_item') == -1 && el.className.search('current_page_parent') == -1)) {
			subMenu.addEvents({
				'mouseenter': function() {

                    subMenu.style.display = 'block';
                },
				'mouseleave' : function() {

                    subMenu.style.display = 'none';
                }
			});
			el.addEvents({
				'mouseenter': function() {
                
                    subMenu.style.display = 'block';
                },
				'mouseleave' : function() {
                
                    subMenu.style.display = 'none';
                }
			});
		}
	});
	*/

});



function StartTabs(){
	fl = null;

	$$('#tabs a').each(function(el){
		if(fl == null){ fl = el; }
		el.onclick = function(){

			if(el.locked){ return false; }

			$$('#tabs a').each(function(el){
				el.locked = true;
				el.getFirst().src = el.getFirst().src.replace('-hover.gif', '.gif');
			});

            tabImage = this.getFirst();

			var fxTab = new Fx.Styles(tabImage, {duration: 500, wait: false});
			fxTab.start({'opacity': 0.5});

            var fx = new Fx.Styles('tab-content', {duration: 500, wait: false});
            fx.set({'left':500});
            fx.start({'left': 0}).addEvent('onComplete', function (e) {
                new Ajax(el.href, {method: 'get', update: $('tab-content'),onSuccess: onSuccess}).request();
			});
			return false;
		}
	});
	fl.getFirst().src = fl.getFirst().src.replace('.gif', '-hover.gif');
    new Ajax(fl.href, {method: 'get', update: $('tab-content'), evalScripts: false}).request();
}
function onSuccess () {

	tabImage.src = tabImage.src.replace('.gif', '-hover.gif');
	var fxTab = new Fx.Styles(tabImage, {duration: 500, wait: false});
	fxTab.start({'opacity': 1});

    $$('#tabs a').each(function(el){ el.locked = false; });
}