var LoadedGlobal;
$(function(){
$('.slides').shuffle();
	$('.slider_bg').loopedSlider();
});

var loaded = false;
LoadedGlobal = loaded;

$(document).ready(function(){
		$('#photos').galleryView({
			panel_width: 805,
			panel_height: 241,
			frame_width: 58,
			frame_height: 37
		});
$(document).pngFix();
Cufon.replace('.reg, .reg a, .headerbar a, .allmenu a, .selected a, .bluemenu a, .greymenu a, a.two_line, a.two_line2,', { fontFamily: 'BlissPro', hover: true});
	Cufon.replace('.title, .lr_title, .p_title, .title a, .lr_title a', { fontFamily: 'BlissPro', hover: true, textShadow: '#dbdbdb 0px 2px, #dbdbdb -2px 0px,  #dbdbdb 2px 0px'});
$(".filmstrip>li>img").each(function(idx) { 
var w = $(this).width();
var w2 = -(w - 58) / 2
$(this).css('margin-left', -(w - 58) / 2);
});
$('div.footer_b>div:eq(0)').css('width', '200px');
$('div.footer_b>div:eq(1)').css('width', '140px');
$('div.footer_b>div:eq(2)').css('width', '100px');
$('div.footer_b>div:eq(3)').css('width', '120px');
$('div.footer_b>div:eq(4)').css('width', '120px');
$('div.footer_b>div:eq(6)').css('width', '200px');
$('div.footer_b>div:eq(7)').css('width', '110px');
$('div.footer_b>div:eq(8)').css('width', '140px');
$('div.footer_b>div:eq(9)').css('width', '140px');
$('div.footer_b>div:eq(10)').css('width', '120px');

//$('div.footer_b>div:eq(1)>div.footer_title').addClass('pad');

$('div.main_menu>div:eq(1)>a').addClass('two_line');

$firstContent = $('div.center_column:eq(0)');
$firstNews = $('.news-latest-container>div.news_block:lt(2)');
if($firstNews.size() > 0)
{
$wrapper = $('<div class="center_col_b"></div>');
$wrapper.append($firstNews);
$wrapper.append('<div style="clear:both;"></div>');
$firstContent.prepend($wrapper);
$firstContent.prepend('<div class="center_col_h"></div>');
$('<div class="center_col_f"></div>').insertAfter($wrapper);
}

$firstContent = $('div.center_column:eq(0)');
$firstNews = $('.news-latest-container>div.news_block:lt(2)');
if($firstNews.size() > 0)
{
$wrapper = $('<div class="center_col_b"></div>');
$wrapper.append($firstNews);
$wrapper.append('<div style="clear:both;"></div>');
$firstContent.prepend($wrapper);
$firstContent.prepend('<div class="center_col_h"></div>');
$('<div class="center_col_f"></div>').insertAfter($wrapper);
}

// Menu wrapping
$firstContent = $('div.center_column:eq(0)');
$firstNews = $('.news-latest-container>div.news_block:lt(2)');
if($firstNews.size() > 0)
{
$wrapper = $('<div class="center_col_b"></div>');
$wrapper.append($firstNews);
$wrapper.append('<div style="clear:both;"></div>');
$firstContent.prepend($wrapper);
$firstContent.prepend('<div class="center_col_h"></div>');
$('<div class="center_col_f"></div>').insertAfter($wrapper);
}
function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}

// Wrapping main content

$maincontent = $('#maincontentholder');

$newsLists = $('.news-latest-container');
$newsLists.each(function(index) {
    if(trim($(this).html()) == "") $(this).remove();
});
$divs = $('.center_column div.csc-default');

$contWrapper = $('<div class="cont_block"></div>');
$contWrapper.append($divs);
$maincontent.append($contWrapper);

$('div.news_block:odd').before('<div class="newssplitter" style="float: left; width: 2px; background: #CCCCCC;"></div>');
$('div.p_item a').attr('target', '_blank');
$('.newssplitter').each(function() {
$(this).height($(this).parent().height());
});
// Setting normal month name
$pollwrap = $("<div class='cont_block'></div>");

$poll = $('.tx-jkpoll-pi1:parent').parent();
$pollparent = $poll.parent().parent();
//alert($pollparent.html());
$pollwrap.append($poll);
$pollwrap1 = $('<div class="center_col_b"></div>');
$pollwrap1.append($pollwrap);
$pollwrap1.insertBefore($pollparent);
$pollwrap1.after('<div class="center_col_f"></div><div class="center_col_h"></div>');

$('div.month>a').each( function() { 
var txt = $(this).text();
switch(txt)
{
   case "января":
txt = "Январь";
break;
   case "февраля":
txt = "Февраль";
break;
   case "марта":
txt = "Март";
break;
   case "апреля":
txt = "Апрель";
break;
   case "мая":
txt = "Май";
break;
   case "июня":
txt = "Июнь";
break;
   case "июля":
txt = "Июль";
break;
   case "августа":
txt = "Август";
break;
   case "сентября":
txt = "Сентябрь";
break;
   case "октября":
txt = "Октябрь";
break;
   case "ноября":
txt = "Ноябрь";
break;
   case "декабря":
txt = "Декабрь";
break;
}
$(this).text(txt);

loaded = true;
GlobalLoaded = true;
} );

$('.monthToday').removeClass('numbers');
//$maincontent.append($divs);
$('.last_p>a>img').css('border', '1px solid black');
//alert($maincontent.html());
// Setting bottom menu size


$('.last_p:odd').after('<div style="clear: both"></div>');

Galleria.loadTheme('fileadmin/html/js/galleria.lightbox.js');
    $('#top_gal').galleria({
        data_source: '.slides>div',
        keep_source: true,
		thumbnails: false,
        data_config: function(img) {
            return {
                description: ""
            }
        }
    });

});

function closeFeedBackWindow(){
	$('#box').fadeOut("slow" , function() {
			$('#hide_all').css('display', 'none');
	});	
}

function openFeedBackWindow(){
	$('#hide_all').css('display', 'block');
	$('.pop').css('display', 'block');
	$('#box').fadeIn('slow');
}

ddaccordion.init({
	headerclass: "headerbar", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: true, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}});


function closeFeedBackWindow(){
	$('#box').fadeOut("slow" , function() {
			$('#hide_all').css('display', 'none');
	});	
}

function openFeedBackWindow(){
	$('#hide_all').css('display', 'block');
	$('.pop').css('display', 'block');
	$('#box').fadeIn('slow');
}

(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }

  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);

var V = VK;
DoVK();
function DoVK()
{
if(loaded)
{
VK.init({apiId: 2130258, onlyWidgets: true});
VK.Widgets.Like("vk_like", {type: "mini"});

VK.Widgets.Comments("vk_comments", {limit: 10, width: "480", attach: "*"});
return;
}
else
{

setTimeout('DoVK();', 1000);
}
}

