/* 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("rad_width_set") ? readCookie("rad_width_set") : "widewidth";
var defSiz = readCookie("rad_font_size") ? readCookie("rad_font_size") : "smallfonts";

function switchWidth(newWidth)
{
    $("#wrapping").removeClass().addClass(newWidth);
    createCookie('rad_width_set', newWidth, 365);
    return false;
}

function switchFont(newFont)
{
    $("body").removeClass().addClass(newFont);
    createCookie('rad_font_size', newFont, 365);
    return false;
}

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);
}

switchFont(defSiz);
switchWidth(defWid);

$(document).ready(function()
{
    $('.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;
    });

    $(".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,{}))
//
jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};
jQuery.fn.vjustify1=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};
jQuery.fn.vjustify2=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};
jQuery.fn.vjustify3=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};


    $(document).ready(function(){
  swap_letter();   

});
function swap_letter() {
  $('#mainbody p').each(function(index) {
    var paragraph = this;
    var node = paragraph;
    while (node.childNodes.length) {
      node = node.firstChild;
    }
    var text = node.nodeValue;
    var first_letter = text.substr(0,1);
 
    var match = /[a-zA-Z]/.test(first_letter);
    if ( match ) {
      node.nodeValue = text.slice(1);
      $('<img />')
          .attr('src','templates/pj_radiate/images/alphabet/' + first_letter.toLowerCase() + '.gif')
          .attr('alt',first_letter)
          .addClass('fancy-letter')
          .prependTo( paragraph ); 
      first_letter = "";
    }
  });
} 

