$(document).ready(function()
{
	$("a.fancybox").fancybox();
	$(".Photo-Line li a").fancybox({ 'titlePosition' : 'over', 'showCloseButton' : 'true' });
    $("button").button();	
});

// Для модуля "Опросы"
$(document).ready(
   function()
   {
	   $(".Polls.Panel  .PollBackButton").live("click", function()
	   {
			poll_id = $(".Polls.Panel .results input[name=poll_id]").val();
			$(".Polls.Panel .results").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');			   
			$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'form' : '1' }, function (data)
			{
				$(".Polls.Panel .results").html(data);
				$(".Polls.Panel button").button();					
			}, 'html');		   
	   });
	   $(".Polls.Panel form[name=poll]").live("submit",
	   	function()
		{
			str = $(this).serialize();
			poll_id = $(".Polls.Panel .form input[name=poll_id]").val();				
			$.post("/user-asynch.php?mod=Polls", str, function (data)
			{
				if (data.status == "error")
				{
					$(".Polls.Panel form[name=poll] .message").html(data.message);
					$(".Polls.Panel form[name=poll] .message").removeClass("message-ok");
					$(".Polls.Panel form[name=poll] .message").addClass("message-error");					
				}
				if (data.status == "ok")
				{
					$(".Polls.Panel form[name=poll] .message").html(data.message);
					$(".Polls.Panel form[name=poll] .message").removeClass("message-error");
					$(".Polls.Panel form[name=poll] .message").addClass("message-ok");
					$(".Polls.Panel .form").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');	
					$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'results' : '1' }, function (data)
					{
						$(".Polls.Panel .form").html(data);
						$(".Polls.Panel button").button();					
					}, 'html');
				}
				
			}, 'json');
			return false;
		});
	   $(".Polls.Panel .PollResultsButton").live("click", function()
	   {
		    poll_id = $(".Polls.Panel .form input[name=poll_id]").val();				
			$(".Polls.Panel .form").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');		   
			$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'results' : '1' }, function (data)
			{
				$(".Polls.Panel .form").html(data);
				$(".Polls.Panel button").button();					
			}, 'html');		   
	   });
//
	   $(".content .Polls  .PollBackButton").live("click", function()
	   {
			poll_id = $(".content .Polls .results input[name=poll_id]").val();
			$(".content .Polls .results").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');			   
			$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'form' : '1' }, function (data)
			{
				$(".content .Polls .results").html(data);
				$(".content .Polls button").button();					
			}, 'html');		   
	   });
	   $(".content .Polls form[name=poll]").live("submit",
	   	function()
		{
			str = $(this).serialize();
			poll_id = $(".content .Polls .form input[name=poll_id]").val();				
			$.post("/user-asynch.php?mod=Polls", str, function (data)
			{
				if (data.status == "error")
				{
					$(".content .Polls form[name=poll] .message").html(data.message);
					$(".content .Polls form[name=poll] .message").removeClass("message-ok");
					$(".content .Polls form[name=poll] .message").addClass("message-error");					
				}
				if (data.status == "ok")
				{
					$(".content .Polls form[name=poll] .message").html(data.message);
					$(".content .Polls form[name=poll] .message").removeClass("message-error");
					$(".content .Polls form[name=poll] .message").addClass("message-ok");
					$(".content .Polls .form").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');	
					$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'results' : '1' }, function (data)
					{
						$(".content .Polls .form").html(data);
						$(".content .Polls button").button();					
					}, 'html');
				}
				
			}, 'json');
			return false;
		});
	   $(".content .Polls .PollResultsButton").live("click", function()
	   {
		    poll_id = $(".content .Polls .form input[name=poll_id]").val();				
			$(".content .Polls .form").empty().html('<div style="text-align:center; line-height: 100px; height: 100px;">&nbsp;<img src="/user/images/ajax/loading.gif" align="absmiddle" />&nbsp;</div>');		   
			$.post("/user-asynch.php?mod=Polls", { 'poll_id' : poll_id, 'results' : '1' }, function (data)
			{
				$(".content .Polls .form").html(data);
				$(".content .Polls button").button();					
			}, 'html');		   
	   });
  });






function ShopAddToBasket(id, count)
{
	$.post('/user-asynch.php', {'mod': 'ShopV1', 'id': id, 'count' : count},
					function(data) {
						// Whatever you want to do here
						$("#basket").load("/user-asynch.php?mod=ShopV1&getBasketHtml", null);
					}, 'json'
			 	);			
}

function updateShopBasket1(currency)
{
	summa = 0;
	count = 0;
	a = 1;
	var res = 0;
	while ($("div#price" + a).length)
	{
		res = parseFloat($("input#cnt" + a).attr('value'), 10) * parseFloat($("div#price" + a).text(), 10);
		if (res < 0 || res > 10000000 || isNaN(res))
		  res = 0;
		$("div#res" + a).html(res + " " + currency);
		summa += parseFloat($("div#res" + a).text(), 10);
		c = parseFloat($("input#cnt" + a).attr('value'), 10);
		if (c >= 0 && c <= 10000)
			count += c;
		a++;
	}
	$("div#res").html(summa  + " " + currency);
	$("div#cnt").html(count);	
}

function updateShopBasket(i, currency)
{
	if (!$("div#price" + i).length)
	return;
	var res = parseFloat($("input#cnt" + i).attr('value'), 10) * parseFloat($("div#price" + i).text(), 10);
	if (res <0 || res > 10000000 || isNaN(res))
	  res = 0;
	$("div#res" + i).html(res + " " + currency);
	summa = 0;
	count = 0;
	a = 1;
	while ($("div#res" + a).length)
	{
		summa += parseFloat($("div#res" + a).text(), 10);
		c = parseFloat($("input#cnt" + a).attr('value'), 10);
		if (c >= 0 && c <= 10000)
			count += c;
		a++;
	}
	$("div#res").html(summa + " " + currency);
	$("div#cnt").html(count);	
	$.post('/user-asynch.php', {'mod':'ShopV1', 'item' : $("input#id" + i).attr('value'), 'count' : parseFloat($("input#cnt" + i).attr('value'), 10)}, function () { /*$("#basket").load("/user-asynch.php?mod=ShopV1&getBasketHtml", null);*/});
}
function dostavka_change()
{
	val = document.forms.orderform.dostavka.value;
	if (val == 2)
		document.getElementById('address').style.display = 'inline';
	else
	    document.getElementById('address').style.display = 'none';
}
function oplatachange()
{
	val = document.forms.orderform.oplata.value;
	if (val == 3)
	{
		document.getElementById('webmoneyspan1').style.display = 'inline';
		document.getElementById('webmoneyspan2').style.display = 'inline';
		document.getElementById('webmoneyspan3').style.display = 'inline';
		document.getElementById('webmoneyspan4').style.display = 'inline';
	}
	else
	{
	    document.getElementById('webmoneyspan1').style.display = 'none';
	    document.getElementById('webmoneyspan2').style.display = 'none';
	    document.getElementById('webmoneyspan3').style.display = 'none';
	    document.getElementById('webmoneyspan4').style.display = 'none';
	}
}

$(document).ready(function(){
    $("a.video").click(function() {
        $.fancybox({
                'padding' : 0,
                'autoScale' : false,
                'title' : this.title,
                'overlayOpacity' : '.6',
                'overlayColor' : '#333',
                'transitionIn' : 'none',
                'transitionOut' : 'none',
                'centerOnScroll' : false,
                'showCloseButton' : true,
                'hideOnOverlayClick': false,
                'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type' : 'swf',
                'swf' : {
                'wmode': 'transparent',
                'allowfullscreen': 'true'
                }
        });
        return false;
    });
});

