new Ya.share({
	element: 'ya_share1',
		elementStyle: {
			'type': 'none',
			'quickServices': ['yaru', 'vkontakte', 'facebook', 'twitter', 'odnoklassniki', 'moimir', 'lj', 'friendfeed']
   }
});


$(document).ready(function() {
	if (document.readyState != "complete"){ //make timeout if browser is Safari (problem with height of block)
	setTimeout( arguments.callee, 100 );
		return;
	} 

$('[placeholder]').placeholder();
var aside = $(".shop aside").height();
var content = $(".shop .content").height();
var asideCard = $(".pagecard aside").height();
var contentCard = $(".pagecard .card").height();
maxH = Math.max(aside, content);
maxHC = Math.max(asideCard, contentCard);

$(".shop aside").height(maxH);
$(".shop .content").height(maxH);

$(".pagecard aside").height(maxHC);
$(".pagecard .card").height(maxHC);


$('.gallery ul li:first-child').addClass('active'); // adds new class name to maintain degradability		
$('.gallery ul').galleria({
	history   : false, // activates the history object for bookmarking, back-button etc.
	clickNext : false, // helper for making the image clickable
	insert    : '#main_image' // the containing selector for our main image. 
						   // If not found or undefined (like here), galleria will create a container 
						   // before the ul with the class .galleria_container (see CSS)
});

$('ul.galleria img').each(function(index) {
	$.preloadImages($(this).attr("rel"));
});


$('.consent input').click(function(){
	$(".submit input").toggleClass("hover");
	if ($('.consent input:checked').length>0){
		$(".submit input").removeAttr("disabled")
		}
	else{
		$(".submit input").attr("disabled",true);
		}
})

	
$("#form1").validate({
	rules: {
		yourname: "required",
		yourmail: {
			required: true,
			email: true
		},
		msg: "required",
		theme: "required"
	},
	messages:{
		yourname: "поле не заполнено или заполнено не верно",
		theme: "поле не заполнено или заполнено не верно",
		msg: "поле не заполнено или заполнено не верно",
		yourmail: "поле не заполнено или заполнено не верно"
	},
	errorPlacement: function(error, element) {
		if (element.attr("name") == "yourname") error.insertAfter($("input[name=yourname]").next());
		
		if (element.attr("name") == "theme") error.insertAfter($("input[name=theme]").next());
		if (element.attr("name") == "msg") error.insertAfter($("textarea[name=msg]").next());
		if (element.attr("name") == "yourmail") error.insertAfter($("input[name=yourmail]").next());
	}	
});

$("#address").validate({
	rules: {
		site_users_name: "required",
		site_users_email: {
			required: true,
			email: true
		},
		full_address: "required",
		site_users_phone: "required"
	},
	messages:{
		site_users_name: "поле не заполнено или заполнено не верно",
		site_users_phone: "поле не заполнено или заполнено не верно",
		full_address: "поле не заполнено или заполнено не верно",
		site_users_email: "поле не заполнено или заполнено не верно"
	},
	errorPlacement: function(error, element) {
		if (element.attr("name") == "site_users_name") error.insertAfter($("input[name=site_users_name]").next());
		
		if (element.attr("name") == "site_users_phone") error.insertAfter($("input[name=site_users_phone]").next());
		if (element.attr("name") == "full_address") error.insertAfter($("input[name=full_address]").next());
		if (element.attr("name") == "site_users_email") error.insertAfter($("input[name=site_users_email]").next());
	}	
});		

$.validator.addMethod("validcb1", function(value){
	if ($(".f1 input:checked").length > 0) return true
	else return false;
},"");
$.validator.addMethod("validcb2", function(value){
	if ($(".f2 input:checked").length > 0) return true
	else return false;
},"");
$.validator.addMethod("validcb3", function(value){
	if ($(".f3 input:checked").length > 0) return true
	else return false;
},"");
$.validator.addMethod("validcb4", function(value){
	if ($(".f4 input:checked").length > 0) return true
	else return false;
},"");


$(".f1 input").click(function(){$(".f1 label.error").remove()});
$(".f2 input").click(function(){$(".f2 label.error").remove()});
$(".f3 input").click(function(){$(".f3 label.error").remove()});
$(".f4 input").click(function(){$(".f4 label.error").remove()});
$(".f5 input").click(function(){$(".f5 label.error").remove()});


$("#form2").validate({
		rules: {
			lastname: "required",
			firstname: "required",
			surname: "required",
			country: "required",
			city: "required",
			address: "required",
			size: "required",
			tune_74:{validcb1:true},
			brend_79:{validcb2:true},
			lw_80:{validcb3:true},
			source_92:{validcb4:true},
			email: {
				required: true,
				email: true
			}
		},
		messages:{
			lastname: "поле не заполнено или заполнено не верно",
			firstname: "поле не заполнено или заполнено не верно",
			surname: "поле не заполнено или заполнено не верно",
			country: "поле не заполнено или заполнено не верно",
			city: "поле не заполнено или заполнено не верно",
			address: "поле не заполнено или заполнено не верно",
			tune_74: "отметьте один или несколько пунктов",
			brend_79: "отметьте один или несколько пунктов",
			lw_80: "отметьте один или несколько пунктов",
			source_92: "отметьте один или несколько пунктов",
			size: "выберите один из пунктов",
			email: "поле не заполнено или заполнено не верно"
		},
		errorPlacement: function(error, element) {
			if (element.attr("name") == "lastname") error.insertAfter($("#form2 input[name=lastname]").next());
			if (element.attr("name") == "firstname") error.insertAfter($("#form2 input[name=firstname]").next());
			if (element.attr("name") == "surname") error.insertAfter($("#form2 input[name=surname]").next());
			if (element.attr("name") == "country") error.insertAfter($("#form2 input[name=country]").next());
			if (element.attr("name") == "city") error.insertAfter($("#form2 input[name=city]").next());
			if (element.attr("name") == "size") error.insertAfter($("#form2 .f5 input:last").next());
			if (element.attr("name") == "address") error.insertAfter($("#form2 input[name=address]").next());
			if (element.attr("name") == "tune_74") error.insertAfter($("#form2 .f1 input:last").next());
			if (element.attr("name") == "brend_79") error.insertAfter($("#form2 .f2 input:last").next());
			if (element.attr("name") == "lw_80") error.insertAfter($("#form2 .f3 input:last").next());
			if (element.attr("name") == "source_92") error.insertAfter($("#form2 .f4 input:last").next());
			if (element.attr("name") == "email") error.insertAfter($("#form2 input[name=email]").next());
		}	
	});		

$("#form3").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		messages:{
			email: "поле не заполнено или заполнено не верно"
		},
		errorPlacement: function(error, element) {
			if (element.attr("name") == "email") error.insertAfter($("#form3 input[name=email]").next());
		}	
	});		

	$('#dialog').jqm();
	$('#dialogpath').jqm({trigger: 'a.jqModalpath'});
	$('#dialogconsent').jqm({trigger: '.consent a'});

})

$.preloadImages = function () {
	var images = (typeof arguments[0] == 'object') ? arguments[0] : arguments;
	for (var i = 0; i < images.length; i++) {
		$("<img>").attr("src", images[i]);
	}
	$("<img>").attr("src", "/templates/template1/images/buy-btn.jpg");
}

function goBack(){
	history.back()
}


