// Switch Site Width
// Copyright 2010 xcartmods.co.uk

$(document).ready(function() {

    // Initialise

    if ($.cookie('view_Width') == null) {
        // Set initial width cookie
        $.cookie('view_Width', 'fixed', {	// Set initial site width: fixed or fluid
            expires: 30
        });


        // View width state
        var view_Width = $.cookie('view_Width');
        // Set the users selection for the initial width state
        if (view_Width == 'fluid') {
            $('.container_fixed').addClass('container_fluid');
        } else {
            $('.container_fluid').addClass('container_fixed');
        };
    };

    //////////////////////////////

    $('a.switch_width').click(function() {
        $('a.switch_width').toggleClass('switch_width_button');
        $('.container_fixed').fadeOut('fast', function() {
            $(this).fadeIn('fast').toggleClass('container_fluid');
        });
        // Set cookie for chosen width state
        $.cookie('view_Width', $('.container_fixed').is('.container_fluid') ? 'fixed' : 'fluid', {
            expires: 30
        });
    });

    // Get width state
    var view_Width = $.cookie('view_Width');
    // Set the users selection for the chosen width state
    if (view_Width == 'fluid') {
        $('.container_fixed').addClass('container_fluid');
        $('a.switch_width').addClass('switch_width_button');
    } else {
        $('a.switch_width').removeClass('switch_width_button');
    };

    //////////////////////////////

    $('.switch_width').click(function() {
        $('<div style="position:absolute;left:120px;"><img src="skin/smart_template/custom/images/ajax_loader.gif" alt="" class="notlazy" /></div>').insertBefore($(this)).fadeIn('slow').animate({
            opacity: 1.0
        }, 1500).fadeOut('slow', function() {
            $(this).remove();
        });
    });

});

