/*
Copyright (c) 2007 Mediasparx (http://www.mediasparx.com)
Notes: Stylesheet switcher
*/

$.addLoadListener = function(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		return false;
	}
	return true;
};

$.attachEventListener = function(eventType, functionRef, capture) {
    if (typeof window.addEventListener != "undefined") {
        window.addEventListener(eventType, functionRef, capture);
    } else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
};

$.checkBrowserWidth = function() {
	if (window.innerWidth) {
		browserWidth = window.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth != 0) {
		browserWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		browserWidth = document.body.clientWidth;
	}
	if (browserWidth == 0) {
        if(document.cookie.match('StylesheetSwitcher_','i') ) {
            var cookies = document.cookie.split(';');
    	    for(var i=0;i < cookies.length;i++)	{
                if(cookies[i].match('StylesheetSwitcher_','i')) {
                    var styleTitle = cookies[i].split('=')[0].split('_')[1];
                    var styleStatus = cookies[i].split('=')[1];
                    $.setStylesheet(styleTitle, eval(styleStatus));
        	    }
            }
        }
	}
	if (browserWidth < 800)	{
		$.setStylesheet("1024", false);
	} else 	{
		$.setStylesheet("1024", true);
	}
};

$.setStylesheet = function(styleTitle, styleStatus) {
//    $('link[@rel*=style]').each(function(i) {
    $('link').each(function(i) {
        if (this.getAttribute('title') == styleTitle) {
            this.disabled = true;
            this.disabled = styleStatus;
        }
    });
    document.cookie = 'StylesheetSwitcher_'+styleTitle+'='+styleStatus;
};

$(function() {
    $.checkBrowserWidth();
    $.attachEventListener("resize", $.checkBrowserWidth, false);

// redirect
    function strrev(str) {
        return str.split("").reverse().join("");
    }
    $('.redirect').each(function(index) {
        $(this).replaceWith('<a href="mailto:'+strrev($(this).html())+'">'+strrev($(this).html())+'</a>');
    });

// temp chat client
/*	config = wc_config();
	config.vars["hide_when_away"] = 1;
	config.vars["hide_not_available"] = 1;
	config.vars["disableGoogleAnalytics"] = 1;
	wc_init("9686-34112082-10-6949", config); */


// end temp chat client
});
