$(function(){var hantswebLayout=new HantswebLayout();hantswebLayout.getLayout();$("#mediumYb").click(function(){hantswebLayout.setMedium("yb");return false;});$("#mediumYp").click(function(){hantswebLayout.setMedium("yp");return false;});$("#mediumDefault").click(function(){hantswebLayout.setMedium("default");return false;});$("#textSizeLarge").click(function(){hantswebLayout.setTextSize("large");return false;});$("#textSizeMedium").click(function(){hantswebLayout.setTextSize("medium");return false;});$("#textSizeSmall").click(function(){hantswebLayout.setTextSize("small");return false;});});function HantswebLayout(){this.COOKIE_NAME="Hantsweb_layout";this.COOKIE_DOMAIN="hants.gov.uk";this.COOKIE_PATH="/";this.CORE_CSS=$("#corecss");};HantswebLayout.prototype.getLayout=function(){var objAACookie=new Object();var strAACookie=this.getCookie();if(strAACookie)objAACookie=$.evalJSON(strAACookie);if(objAACookie){for(var prop in objAACookie){this[prop]=objAACookie[prop];};this.refresh();this.setMedium();this.setTextSize();};};HantswebLayout.prototype.setMedium=function(_medium){var strMedium=this.medium;var bolOnLoad=true;if(_medium!==undefined){bolOnLoad=false;strMedium=_medium;this.refresh();};if(strMedium!==undefined){this.coreCssHref=this.removeMedium(this.coreCssHref);if(strMedium=="yb"||strMedium=="yp"){if(!bolOnLoad)this.medium=strMedium;this.coreCssHref=this.insertMedium(this.coreCssHref,strMedium);}else delete this.medium;this.setLayout(!bolOnLoad);};};HantswebLayout.prototype.setTextSize=function(_textSize){var strTextSize=this.textSize;var bolOnLoad=true;if(_textSize!==undefined){bolOnLoad=false;strTextSize=_textSize;this.refresh();};if(strTextSize){this.coreCssHref=this.removeTextSize(this.coreCssHref);if(strTextSize=="large"||strTextSize=="medium"){if(!bolOnLoad)this.textSize=strTextSize;this.coreCssHref=this.insertTextSize(this.coreCssHref,strTextSize);}else delete this.textSize;this.setLayout(!bolOnLoad);};};HantswebLayout.prototype.removeTextSize=function(_string){return _string.replace(/hantsweb-homepage-?[^\.]*\.css/i,"hantsweb-homepage.css");};HantswebLayout.prototype.removeMedium=function(_string){return _string.replace(/^(http:\/\/www\.hants\.gov\.uk\/css\/)(yb|yp)\//i,"$1");};HantswebLayout.prototype.insertMedium=function(_url,_string){return _url.replace(/^(http:\/\/www\.hants\.gov\.uk\/css\/)/i,"$1"+_string+"/");};HantswebLayout.prototype.insertTextSize=function(_url,_string){return _url.replace(/([^\.]+)\.css/i,"$1-"+_string+".css");};HantswebLayout.prototype.setCookie=function(){var strAACookie,objAACookie=new Object();if(this.medium)objAACookie.medium=this.medium;if(this.textSize)objAACookie.textSize=this.textSize;if(objAACookie)strAACookie=$.toJSON(objAACookie);if(strAACookie)$.cookie(this.COOKIE_NAME,strAACookie,{domain:this.COOKIE_DOMAIN,path:this.COOKIE_PATH});else this.deleteCookie();};HantswebLayout.prototype.deleteCookie=function(){if(this.getCookie())$.cookie(this.COOKIE_NAME,null);};HantswebLayout.prototype.getCookie=function(){return $.cookie(this.COOKIE_NAME);};HantswebLayout.prototype.refresh=function(){this.getCoreCssHref();};HantswebLayout.prototype.getCoreCssHref=function(){this.coreCssHref=this.getHref(this.CORE_CSS);};HantswebLayout.prototype.getPrintCssHref=function(){this.printCssHref=this.getHref(this.PRINT_CSS);};HantswebLayout.prototype.getHref=function(_elem){return _elem.attr("href");};HantswebLayout.prototype.setLayout=function(_setCookie){var bolSetCookie=_setCookie===undefined?false:_setCookie;this.setCoreCssHref();if(bolSetCookie)this.setCookie();};HantswebLayout.prototype.setCoreCssHref=function(){this.setHref(this.CORE_CSS,this.coreCssHref);};HantswebLayout.prototype.setPrintCssHref=function(){this.setHref(this.PRINT_CSS,this.printCssHref);};HantswebLayout.prototype.setHref=function(_elem,_href){_elem.attr({"href":_href});};
