jQuery.fn.currencySwitcher = function(){
/* "this" refers to each instance of the selected element,
* So, if you were to call the plugin like this:
* $('a').currencySwitcher(); then the following would occur
* when clicking on any anchor within the document:
*/
$(this).click(function(){
// We're passing this element object through to the
// loadStyleSheet function.
loadStyleSheet(this);
var parentClass = $(this).parent().attr('class');
// class name must be first in stack and have 8 chars!
var targetClass = '.'+parentClass.substr(0,8);
$('dl.currency-switcher ul li').removeClass('selected-currency');
$(targetClass).addClass('selected-currency');
// And then we're returning false.
return false;
});
function loadStyleSheet(obj) {
$(obj).parent().parent().parent().prev().prepend('
');
$('#overlay')
.css({
position:'absolute',
bottom:'12px',
display: 'none',
zIndex: 10001
})
.fadeIn(500,function(){
// obj.href refers to the href of the clicked link
$.get(obj.href+'&js',function(data){
// trimmedData is the currency type parameter passed with the url get var
var trimmedData = $.trim(data);
// change the stylesheet
$('#currency-stylesheet').attr('href','/css/currency-'+trimmedData+'.css');
cssDummy.check(function(){
$('#overlay').fadeOut(500,function(){
$(this).remove();
$('dl.currency-switcher').accordion("activate", false)
});
});
});
});
}
var cssDummy = {
init: function(){
$('