/*
 * Fray'z
 * 2008 
 */

$(document).ready(function()
{
	
    
	var menustatus = $.cookie('menus');
	if (menustatus == null)
	{
		$.cookie('menus', '0000', {expires: 300});
		var menustatus = "0000";
	}
	
	$(".collaps").each(function(i) {
		if (menustatus.substring(i, i+1) == "1")
		{
			$(this).find("+ ul").hide();
		}
	});

	$(".col_nhead").each(function(i) {
		if (i > 1)
		{
			$(this).parent().children().not(".col_nhead").not(".col_nbot").children().hide();
		}
	});
	
	$(".gallery").each(function(){
  		$(this).find(".adm_button_picpanel").hide();
	});
	
	$(".collaps").click(function() {
		$(this).parent().children().not(".collaps").toggle(300, function(){
			var tr;
			var menustatus = "";
		
		$(".collaps").each(function(i) {
			if ($(this).parent().children().not(".collaps").is(':visible')){tr = 0;}
			if ($(this).parent().children().not(".collaps").is(':hidden')){tr = 1;}	
			menustatus = menustatus + tr;
			/*alert (menustatus);*/
		});
		$.cookie('menus', menustatus, {expires: 300});
		});
		
	});


	//$(".adm_button").click(function() {
	//		alert($(this).parent().parent().parent().parent().parent().attr('class'));
	//});


	$(".col_nhead").click(function() {
			$(this).parent().children().not(".col_nhead").not(".col_nbot").children().toggle();
	});
	
	$(".adm_button_open").click(function() {
			$(this).parent().children().not(".adm_button_open").toggle("fast");
	});
	
	//$('#menulist ul a').hover(function() {
	//	$(this).addClass('menulist-hover');
	//	}, function() {
  	//	$(this).removeClass('menulist-hover');
	//});
	
	$(".gallery").hover(function(){
  		$(this).find(".adm_button_picpanel").show();
	},function(){
  		$(this).find(".adm_button_picpanel").hide();
	});
	
	//Firefox 3 temporary bugfix
	//var kostil = $(".col_nhead").width();
	//$(kostil).appendTo("#upback");
	//alert('Hello world!');
	
	$('.gallery > a').lightBox(
		{
		txtImage: 'Изображение',
		txtOf: 'из'
		}
	);
	
	$('.jcarousel-skin-linx').jcarousel(
		{
			scroll: 1
		}
	);
});

//Now there goes da flash!

window.onload = function() {

     $("div[@flash='true']").each(function(i) {
		var filename = "/media/swf/" + (this).id + ".swf";
		var fw = $(this).width();
		var fh = $(this).height();
		$(this).flash(
		{		
			src: filename,
        	wmode: 'transparent',
			width: fw,
    		height: fh
		},
		{ 
		version: '9.0.45',
		expressInstall: true
		}
		);
	});

} 