$(document).ready(function(){
   $('.sameGame').jcarousel({
      visible: 3,
      scroll: 1
   });
   $('.topMenu a').click(function(){
      if($(this).hasClass("sec")){
         $('.topMenu').css('background-position',"0px 100%");
         $(".bl2").slideDown('slow');
         $(".bl1").slideUp('slow');
      } else{
         $('.topMenu').css('background-position',"0px 0px");
         $(".bl1").slideDown('slow');
         $(".bl2").slideUp('slow');
      }
   });
//Show Modal Window

	var modalWind = $('.reg-box');
	$('.enter').click(function(e){
		e.preventDefault();
		var topPx = (($(window).width()) - (modalWind.width())) / 3 ;
		var leftPx = (($(window).height()) - (modalWind.height())) / 5 ;

		modalWind.css({
			'left':topPx,
			'top':leftPx
		})
		modalWind.fadeIn();
		$('body').append('<div id="fade"></div>'); 
		$('#fade').fadeIn();

	});

// Close modal category
	$('#fade').live('click', function(e){
		e.preventDefault();
		$('#fade, .reg-box ').fadeOut(function() {
			$('#fade').remove();  
		});
	})



});

/* Сварачивающиеся панели в меню слева */
(function($) {
    $.fn.extend({
        collapsiblePanel: function() {
            return $(this).each(ConfigureCollapsiblePanel);
        }
    });
})(jQuery);

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires = " + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) return unescape(y);
    }
}

function ConfigureCollapsiblePanel() {
    $(this).addClass("ui-widget");
    
    if ($(this).children().length == 0) {
        $(this).wrapInner("<div></div>");
    }
    
    $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");
    
    var display = '';
    if ($(this).attr('id') != 'left_panel_5') display = getCookie($(this).attr('id'));
    else display = 'block';
    $(this).find('.collapsibleContainerContent').css('display', display);
    
    $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("widgettitle") + "</div></div>").prependTo($(this));

    $(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
}
  
function CollapsibleContainerTitleOnClick() {
    $(".collapsibleContainerContent", $(this).parent()).slideToggle('slow', function() {
        setCookie($(this).parent().attr('id'), $(".collapsibleContainerContent", $(this).parent()).css('display'), 365);
    });
}

$(document).ready(function() {
    $(".collapsibleContainer").collapsiblePanel();
});
