﻿(function($) {
    var availableStylesheets = [];
    $.stylesheetSwitch = function(styleName) {
        $('link[@rel*=style][title]').each(
				function(i) {
				    this.disabled = true;
				    if (this.getAttribute('title') == styleName) {
				        this.disabled = false;

				    }
				}
			);
        if (isUserAuth) {
            $.get('/json/SaveTheme?theme=' + encodeURIComponent(styleName));
        }
        createCookie('most_style', styleName, 365);



    };

    $.stylesheetInit = function() {
        $('link[rel*=style][title]').each(
				function(i) {
				    availableStylesheets.push(this.getAttribute('title'));
				}
			);
        var c = readCookie('most_style');
        if (c) {
            $.stylesheetSwitch(c);
        }
        else {
            createCookie('most_style', "", 365);
        }
    };

}
)(jQuery);
 
 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);
 }
 

if (window.jQuery) {
    jQuery(function() {
       
        (function() { $('a.settings_dd_link').bind('click', function(event, ui) { var target = jQuery('#theme_setup'); target.toggle(0); var target = jQuery('a.settings_dd_link'); target.toggleClass('settings_dd_link_active'); var target = jQuery('span.settings_dd_link'); target.toggleClass('settings_dd_link_active') }); })();
        (function() {
            jQuery('#reset_settings').bind('click', function(event, ui) {
            $.stylesheetSwitch('');
            
                        
            });
        })();
        (function() {
            jQuery('a.black').bind('click', function(event, ui) {
            $.stylesheetSwitch('black');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
           

            });
        })();
        (function() {
            jQuery('a.green').bind('click', function(event, ui) {

            $.stylesheetSwitch('green');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
            
           

            });
        })();
        (function() {
            jQuery('a.orange').bind('click', function(event, ui) {
            $.stylesheetSwitch('orange');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
            
            

            });
        })();
        (function() {
            jQuery('a.purple').bind('click', function(event, ui) {
            $.stylesheetSwitch('purple');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
            
           

            });
        })();
        (function() {
            jQuery('a.blue').bind('click', function(event, ui) {
            $.stylesheetSwitch('blue');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
            


            });
        })();
        (function() {
            jQuery('a.red').bind('click', function(event, ui) {
            $.stylesheetSwitch('red');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');
            


            });
        })();
        (function() {
            jQuery('a.pink').bind('click', function(event, ui) {
            $.stylesheetSwitch('pink');
            if (!isUserAuth)
                ShowAlertMesage('Вы изменили тему!');

            });
        })();
        (function() {
        jQuery('a.blue_bokeh').bind('click', function(event, ui) {
        $.stylesheetSwitch('blue_bokeh');
                if (!isUserAuth)
                    ShowAlertMesage('Вы изменили тему!');

            });
        })();
        (function() {
        jQuery('a.winter').bind('click', function(event, ui) {
        $.stylesheetSwitch('winter');
                if (!isUserAuth)
                    ShowAlertMesage('Вы изменили тему!');

            });
        })();
        (function() {
            jQuery('a.most').bind('click', function(event, ui) {
                $.stylesheetSwitch('most');
                if (!isUserAuth)
                    ShowAlertMesage('Вы изменили тему!');

            });
        })();
            

    })
};

