/*# AVOID COLLISIONS #*/
;if(jQuery) (function($){
/*# AVOID COLLISIONS #*/

$.fn.colorChooser = function() {

    var colors = {'white':'FFFFFF', 'black':'000000', 'gray':'716B77', 'blue':'425B85', 'green':'00594C', 'purple':'4F4389', 'orange':'DE9127', 'red':'BE2E26'}

    $('#color-buttons').empty();
    $('button[name="preview"]').remove();
    
    var colorsHtml = '<input type="hidden" name="color" id="color" value=""/><span id="white" tabindex="1" role="button"><span>White</span></span><span id="black" tabindex="2" role="button"><span>Black</span></span><span id="gray" tabindex="3" role="button"><span>Gray</span></span><span id="blue" tabindex="4" role="button"><span>Blue</span></span><span id="green" tabindex="5" role="button"><span>Green</span></span><span id="purple" tabindex="6" role="button"><span>Purple</span></span><span id="orange" tabindex="7" role="button"><span>Orange</span></span><span id="red" tabindex="8" role="button"><span>Red</span></span><div><a href="#" id="transparent">Transparent</a></div>';
    $('#color-buttons').html(colorsHtml);

    $('#color-buttons').click(function(event) {
        if(colors[event.target.id]) {
            $(".gallery-item .tc1").css("background-color", "#"+colors[event.target.id]);
            $('#color').attr('value', colors[event.target.id]);
            $('#color-hex').attr('value', colors[event.target.id]);
        }
        return false;
    });
    
    $('#transparent').click(function(event) {
        $(".gallery-item .tc1").css("background-color", "");
        $('#color').attr('value', "");
        $('#color-hex').attr('value', "");
        return false;
    });
    
    $('#color-hex').keyup(function(event) {
        if($('#color-hex').attr('value').length > 2) {
            $(".gallery-item .tc1").css("background-color", "#"+$('#color-hex').attr('value'));
        }
    });
}
/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/

;if(jQuery) (function($){
    $.fn.themes = function() {
        if(($.cookie('themes_open') == null) || $.cookie('themes_open') == 0) {
            $("#themes ul").hide();
            $("#themes h4").removeClass('open');
        }
        
        $("#themes h4").click(function() {
            $("#themes ul").toggle();
            if($("#themes ul").css('display') == 'block') {
                $("#themes h4").addClass('open');
                $.cookie('themes_open', 1, {'path': '/'});
            } else {
                $("#themes h4").removeClass('open');
                $.cookie('themes_open', 0, {'path': '/'});
            }
        })
    }
})(jQuery);

$(document).ready(function() {
   $("#themes").themes(); 
});