//////////////////// tabs jquery plugin ////////////////////////////////////////////////////////////////////////////
$.tabs = function(containerId, start) {
    var ON_CLASS = 'on';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:eq(' + i + ')').css({display:"block"});
    $(id + '>ul>li:nth-child(' + (i+1) + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').css({display:"none"});
                target.css({display:"block"});
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                alert('There is no such container.');
            }
        }
        return false;
    });
};


///////////// Styleswitch switcher built on jQuery ///////////////////////////////////////////////////////
function switchStylestyle(styleName) {
	$('link[@rel*=style][@title]').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	$.cookie('style',styleName, {expires: 365});
       return false;
}

$(document).ready(function(){

//// Only make tab-box li's inline only when js enabled
$("#tab-list li ").css("display","inline");
$("#tab-1,#tab-2,#tab-3").css("display","none");

///// Check login box is normal, otherwise activate tab 3
if ($(".tx-newloginbox-pi1 h3").text() == "User login" ) {
   $.tabs('tab-box');
}
else {
   $.tabs('tab-box',3);
}

	var c = $.cookie('style');
	if (c) switchStylestyle(c);

});