$(function () {
    $("ul.dropdown li").hover(
	function(){
		if (!($(this).hasClass('png'))&&($('ul:first',this).length)){
			$(this).addClass("hover");
			$('ul:first',this).css('display', 'block');
		}
    },
	function(){
		if (!($(this).hasClass('png'))){
			$(this).removeClass("hover");
			$('ul:first',this).css('display', 'none');
		}
    });

	if ($("#birthday").length) {
		$("#birthday").datepicker({
			showOn: 'both',
			buttonImage: 'img/icon-calendar.png',
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true
		});
        var yearRange = $("#birthday").datepicker("option", "yearRange");
        $("#birthday").datepicker("option", "yearRange", '1950:2000');

		var dateFormat = $("#birthday").datepicker("option", "dateFormat");
		$("#birthday").datepicker("option", "dateFormat",  "dd'.'mm'.'yy");
	}

	if ($(".partners").length) {
		$(".showmore").click(function(){
			$(this).next("div").slideToggle("slow", function(){
				$(this).prev().css('display','none');
			});
		});
		$("span.hidemore").click(function(){
			$(this).parent().slideToggle("slow", function(){
				$(this).prev().css('display','inline-block');
			});
		});
	}
	
	if($("#help").length) {
		$(".help_ttl:first").addClass("active");
	    $(".help_text:not(:first)").hide();	 
	    $(".help_ttl").click(function(){	 
	        $(this).next(".help_text").slideToggle("slow")
	        .siblings(".help_text:visible").slideUp("slow");
	        $(this).toggleClass("active");
	        $(this).siblings(".help_ttl").removeClass("active");
	     });
	}
	if($(".seeshort").length) {
		$(".seeshort").tooltip({
			bodyHandler: function() {
				return $($(this).attr("rel")).html();
			},
			showURL: false
		});
	}
	
	$('ul#banner').innerfade({
		speed: 300,			
		timeout: 3000,			
		type: 'sequence',			
		containerheight: '60px'			
	});

	if ($(".addcomment_ttl").length) {
		$(".addcomment_body").hide();
		$(".addcomment_ttl").click(function(){
			$(this).next("div").slideToggle("slow");
			$(this).addClass("addcomments_active");
		});
		/*$("span.hidemore").click(function(){
			$(this).parent().slideToggle("slow", function(){
				$(this).prev().css('display','inline-block');
			});
		});*/
	}
        
/*wish*/
$('#is_public').click(function(){
    $('#public_info').toggle();
})
        
});
function getfilepath(sorse,dest) {var str = $('#'+sorse).val();$('#'+dest).val(str);}
function clearlbl(sorse) {$('.'+sorse).empty();}
function PNG(element){
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
	var src;
	if (element.tagName=='IMG'){
			if (/\.png$/.test(element.src)){
				src = element.src;
				element.src = "img/t.gif"; // = 1*1px  transparent image and path for it
			}
		}
		else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if(src){
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
	if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}

function updateCart(count) {
    if ($("#cart_amount")) {
        $("#cart_amount").fadeOut(1000, function() {$("#cart_amount").html(count).fadeIn(1000)});
    }
}
$(document).ready(function() {
     $(".order input").change(function() {
         $.post("cart/update", {id: this.id, quantity: this.value, ajax: '1'},
                 function(data){
                     if (data.success) {
                         $("#total_price").html(data.data.total_price);
                         $("#" + data.data.id).val(data.data.nb_items);
                     }
              }, "json");

         return false;
     });

});

/*donate page*/
function donateValidate() {
    var err = '';
    if (!($("#amt").val())) {
        err = 'Поле "Сумма" обязательно для заполнения';
    }else
    if (!(/^\d+$/.test($("#amt").val()))) {
        err = 'Поле "Сумма" должно быть целым числом';
    }

    if (err){
        $("#amt_error").html(err);
        $("#amt_error").show();
        $("#amt").addClass('err');
        $("#amt").focus();
        return false;
    }

    $("#amt_error").hide();
    $("#amt").removeClass('err');
    return true;
}

/*donate page end*/

    function galleryClick(id){
    $.ajax({
      url: '/photo/pictureview',
      dataType: 'json',
      data: {id: id},
      success: function(data){}
    });
    }

