/* pj_tools.js Toolbar Selector and other JQuery-based Functions used in this
* Pure Joomla! Pro Templates Club Template
* Pure Joomla! - www.pure-joomla.com - "Keep it Pure!"
*/
//Default States must correspond with those for width and font in template_css.css
var defWid = readCookie("width_set") ? readCookie("width_set") : "thinwidth";
var defSiz = readCookie("font_size") ? readCookie("font_size") : "smallfonts";
var defCol = readCookie("style_color") ? readCookie("style_color") : "blue";

function switchWidth(newWidth)
{
    $("#wrapping").removeClass().addClass(newWidth);
    createCookie('width_set', newWidth, 365);
    return false;
}

function switchFont(newFont)
{
    $("body").removeClass().addClass(newFont);
    createCookie('font_size', newFont, 365);
    return false;
}

function switchStylestyle(styleName, cmode, availStyles)
{
    $('link[@rel*=style][@title]').each(function(i)
    {
        if (in_array(this.getAttribute('title'), availStyles))
        {
            this.disabled = true;

            if (this.getAttribute('title') == styleName)
            {
                this.disabled = false;
            }
        }
    });

    createCookie('style_' + cmode, styleName, 365);
}

function createCookie(name, value, days)
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
    {
        var expires = "";
    }

    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];

        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);

        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }

    return null;
}

function eraseCookie(name)
{
    createCookie(name, "", -1);
}

// Arrays for Style Switching
function in_array(needle, haystack)
{
    for (h in haystack)
    {
        if (haystack[h] == needle)
        {
            return true;
        }
    }

    return false;
}

var style_id_list_c = new Array("red", "blue", "green", "orange");

$.preloadImages = function()
{
    for (var i = 0; i < arguments.length; i++)
    {
        img = new Image();
        img.src = arguments[i];
    }
};

$('.sizeswitch').each(function(i)
{
    style_id_list_s[i] = $(this).rel();
});

switchStylestyle(defCol, "color", style_id_list_c);
switchFont(defSiz);
switchWidth(defWid);

$(document).ready(function()
{
    $('.styleswitch').click(function()
    {
        switchStylestyle(this.getAttribute("rel"), "color", style_id_list_c);
        $('.styleswitch').removeClass("active-option");
        $(this).addClass("active-option");
        return false;
    });

    $('.fontswitch').click(function()
    {
        switchFont(this.getAttribute("rel"));
        $('.fontswitch').removeClass("active-option");
        $(this).addClass("active-option");
        return false;
    });
	
    $('.widthswitch').click(function()
    {
        switchWidth(this.getAttribute("rel"));
        $('.widthswitch').removeClass("active-option");
        $(this).addClass("active-option");
        return false;
    });

    $(".styleswitch[@rel*=" + defCol + "]").addClass("active-option");
    $(".fontswitch[@rel*=" + defSiz + "]").addClass("active-option");
	$(".widthswitch[@rel*=" + defWid + "]").addClass("active-option");

});
/* jQMinMax v0.1 - Copyright (c) 2006 Dave Cardwell (http://davecardwell.co.uk/)
   Released under the MIT License (http://www.opensource.org/licenses/mit-license.php) */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('u m(){$.5={D:y,v:y};$(G).12(m(){8 h=G.W(\'I\');$(h).e({\'3\':\'J\',\'6-3\':\'K\'});$(\'L\').M(h);$.5.v=(h.s&&h.s==2);$(h).N();b($.5.v)o;$.5.D=O;$.5.A();$(\':5\').5()});$.5.A=m(){8 p=u E(\'6-3\',\'6-4\',\'9-3\',\'9-4\');8 5=u E();Q(8 i=0;i<p.R;i++){8 n="$.e(a,\'"+p[i]+"\')!=\'S\'&&"+"$.e(a,\'"+p[i]+"\')!=\'z\'&&"+"$.e(a,\'"+p[i]+"\')!=f.g";b(p[i].U(2)==\'x\')n+="&&$.e(a,\'"+p[i]+"\')!=\'X\'";$.n[\':\'][p[i]]=n;5[i]=\'(\'+n+\')\'}$.n[\':\'][\'5\']=5.Y(\'||\')};$.Z.5=m(){o $(c).10(m(){8 7={\'6-3\':r(c,\'6-3\'),\'9-3\':r(c,\'9-3\'),\'6-4\':r(c,\'6-4\'),\'9-4\':r(c,\'9-4\')};8 3=c.s;8 4=c.w;8 k=3;8 l=4;b(7[\'9-3\']!=f.g&&k>7[\'9-3\'])k=7[\'9-3\'];b(7[\'6-3\']!=f.g&&k<7[\'6-3\'])k=7[\'6-3\'];b(7[\'9-4\']!=f.g&&l>7[\'9-4\'])l=7[\'9-4\'];b(7[\'6-4\']!=f.g&&l<7[\'6-4\'])l=7[\'6-4\'];b(k!=3)$(c).e(\'3\',k);b(l!=4)$(c).e(\'4\',l)})};m r(t,p){8 q=$(t).e(p);b(q==f.g||q==\'z\')o f.g;8 j;j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)%$/);b(j){o T.V(C((/3$/.h(p)?$(t).F().H(0).s:$(t).F().H(0).w)*j[1]/P))}j=q.B(/^\\+?(\\d*(?:\\.\\d+)?)(?:11)?$/);b(j){o C(j[1])}o f.g}}();',62,65,'|||width|height|minmax|min|constraint|var|max||if|this||css|window|undefined|test||result|newWidth|newHeight|function|expr|return||raw|calculate|offsetWidth|obj|new|native|offsetHeight||false|auto|expressions|match|Number|active|Array|parent|document|get|div|1px|2px|body|append|remove|true|100|for|length|0px|Math|charAt|round|createElement|none|join|fn|each|px|ready'.split('|'),0,{}))
//