﻿$(document).ready(function(){

				$("[title]").mbTooltip({ // also $([domElement]).mbTooltip  >>  in this case only children element are involved
					opacity : .97,       //opacity
					wait:500,           //before show
					cssClass:"default",  // default = default
					timePerWord:70,      //time to show in milliseconds per word
					hasArrow:false,			// if you whant a little arrow on the corner
					hasShadow:true,
					imgPath:"img/",
					ancor:"mouse", //"parent"  you can ancor the tooltip to the mouse position or at the bottom of the element
					shadowColor:"black", //the color of the shadow
					mb_fade:200 //the time to fade-in
				});

				$(document).enableTooltip();

				var cur_url = window.location.hash.split("#")[1];

				theTable = $('#main_table')
				$.uiTableFilter( theTable, cur_url )
				openAll();

				$('body').click(function()
				{
					$('.selector_otion').hide();
				});

				var offset = $("#jsddm").offset();

				var leftPos = offset.left;
				var topPos  = offset.top;

				var leftPosPlus = offset.left + $("#jsddm").width() + 50;
				var topPosPlus = offset.top + $("#jsddm").height();

				$.each($('.selector_otion'),function()
				{
					var off = $(this).offset();
					topPosPlus = topPosPlus + 25;
				})

				$('#jsddm').mouseout(function(e)
				{
					closeList();
				});

			});

			function openAll() {

				var trs = $("#main_table tr");

				$.each(trs,function()
				{
					if ($(this).attr("fltrd") == "1") {
						if ($(this).attr("class") == "proj-line") {
							var id = $(this).attr("id");
							openCustom(id.split("row")[1]);
						}
					}
				});

			}

			function openCustom(productid)
			{
				var vis = $("#product"+productid).attr('vis');

				if(vis == 0)
				{
					var trs = $("#main_table tr");

					$.each(trs,function()
					{
						if($(this).attr('sub_productid') == productid) $(this).show();
					});

					$("#product"+productid).attr('vis','1');
					$("#product"+productid).removeClass('proj_closed').addClass('proj_open');
				}
				else
				{
					closeCustom(productid);
					$("#product"+productid).attr('vis','0');
					$("#product"+productid).removeClass('proj_open').addClass('proj_closed');
				}
			}

			function closeCustom(productid)
			{

				//$("#main_table tr[sub_productid]="+productid).hide();

				var trs = $("#main_table tr");

					$.each(trs,function()
					{
						if($(this).attr('sub_productid') == productid) $(this).hide();
					});

				$("#product"+productid).attr('vis','0');
				$("#product"+productid).removeClass('proj_open').addClass('proj_closed');

			}

			var timer;
			var opened;

			function openList()
			{
				$('.selector_otion').show();
				timer = setTimeout("testList()","200");
				opened = 1;
			}

			function closeList()
			{
				$('.selector_otion').hide();
				clearTimeout(timer);
				opened = 0;
			}

			function closeListT()
			{
				opened = 0;
			}

			function reconf()
			{
				opened = 1;
			}

			function testList()
			{
				console.log(opened);
				if(opened == 0) closeList();
			}

			function dDown(sender)
			{
				$(sender).addClass('down');
			}

			function defPosition(event) {
				window.xX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft || window.scrollX);
			}

			function setD(sender) {
				window.xOld = window.xX;
				window.useId = parseInt($(sender).attr("slideshow"));
			}

			function checkD() {
				if (Math.abs(window.xX - window.xOld) < 5) {
					next();
				}
				//window.useId = -1;
			}

			function next() {
				id = window.useId;
				var step = parseInt($("#slideshow"+id).attr("step"));
				if (step == slideshows[id].steps)
					step = 1;
				else
					step++;
				slideshows[id].setStep(step);
				$("#slideshow"+id).attr("step",step);
			}
			
			function showPlayer() {
				$("body").append("<div id='overflow' onclick='hidePlayer();'></div><div id='ovcont'><div class='close' onclick='hidePlayer();'>закрыть</div><div class='cont'></div></div>");
				$("#ovcont div.cont").load("/tpl/video.html", function() {
					setTimeout(function() {
						$('#overflow').animate({opacity: 0.7}, 1000);
						$('#ovcont').animate({opacity: 1}, 1000);
					}, 100);
				});
			}
			
			function hidePlayer() {
				$('#overflow').animate({opacity: 0}, 1000);
				$('#ovcont').animate({opacity: 0}, 1000, function() { setTimeout(function() { $("#overflow").remove(); $("#ovcont").remove();},100)});
			}
			
			function moodPress() {
				$("#mood").addClass("pressed");
			}
			
			function moodUp() {
				$("#mood").removeClass("pressed");
			}
