var myPrPlay = 1;
var myPrPlay2 = 1;

function changemyPrPlay(pr)
{
	myPrPlay = pr;
	if (myPrPlay == 1)
		object.myFunct();
}

jQuery(document).ready(function() {

	//header corner login btn hover effect
	jQuery('#MAP .login-btn').hover(
		function() {
			jQuery('#head-corner img:not(.hover)').hide();
			jQuery('#head-corner img.hover').show();
		},
		function() {
			jQuery('#head-corner img:not(.hover)').show();
			jQuery('#head-corner img.hover').hide();
		}
	);


	//adverts catalog
	jQuery('.cat-menu>ul>li:has(ul)>a').click(function() {
		jQuery(this).toggleClass('expanded');
		jQuery(this).siblings('ul').slideToggle();
		return false;
	});


	//adverts list contacts
	jQuery('.addverts .addvert-item .contacts h3, .view-adverts-search .addvert-item .contacts h3').click(function() {
		jQuery(this).siblings('.contacts-content').slideToggle();
	});
	/*$("#mainslider").galleryView({
		panel_width: 563,
		panel_height: 280,
		frame_width: 150,
		frame_height: 106,
		pause_on_hover: true,
		nav_theme: 'dark',
		overlay_height: 100
	});*/


	//content block
	jQuery('.view-articles-by-category-block .view-content h3').click(function() {
		jQuery(this).toggleClass('expanded');
		jQuery(this).nextAll('.item-list').slideToggle();
		return false;
	});
	
	// Separation on columns on the home page. Not work yet.
	$elem_count = jQuery('.view-articles-by-category-main .view-content .view-item').length / 2;
	if ($elem_count) {
		jQuery('.view-articles-by-category-main .view-content .view-item:lt(' + Math.floor($elem_count) + ')').wrapAll('<div class="column"></div>');
		jQuery('.view-articles-by-category-main .view-content > .view-item ').wrapAll('<div class="column"></div>');
	}
	
	/* addvertisments slider */
/*	$("#content-area .scrollable").galleryScroll({
		btPrev: 'a.prev',
		btNext: 'a.next'
	});*/
	//$("#content-area .scrollable li a").prettyPhoto();
	jQuery(".view-articles-slider").css({'visibility':'visible'});
	
	
	/*---------------------------------------------------------*/
	

	
	/*jQuery(".login").fancybox({
		'padding' : 0,
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onStart' : function(){
			jQuery('#bforgot').hide();
			jQuery('#breg').hide();
			jQuery('#blogin').show();
			jQuery('#license_text').hide();
			jQuery(".login").css('top','0px');
		}
	});
	
	jQuery(".registration").fancybox({
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onStart' : function(){
			jQuery('#breg').show();
			jQuery('#bforgot').hide();
			jQuery('#blogin').hide();
		}
	});*/
	
	/*-------------------------------------------------------------*/
	
	jQuery("#add_comm").fancybox({
		'padding': '0',
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onClosed' : function(){
			location.href = location.href;
		}
	});

	jQuery("#add_comm2").fancybox({
		'padding': '0',
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onClosed' : function(){
			location.href = location.href;
		}
	});
	
	jQuery(".edit_comm").fancybox({
		'padding': '0',
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onClosed' : function(){
			location.href = location.href;
		}
	});
	
	jQuery("a[rel=image_group]").fancybox({
		'overlayColor' : '#333',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	jQuery("#add_faq").fancybox({
		'speedOut' : 100,
		'overlayColor' : '#333',
		'onClosed' : function(){
			location.href = location.href;
		}
	});
	
	/*jQuery(".show_photos").fancybox({
		'padding': '0',
		'speedOut' : 100,
		'overlayColor' : '#333',
		
	});*/

	/*--------------------------------------------------------------- Star */
	
	save_star();
	
	jQuery("#star_1").hover(function(){
		jQuery("#star_1").attr('class','star off');
		jQuery("#star_2").attr('class','star on');
		jQuery("#star_3").attr('class','star on');
		jQuery("#star_4").attr('class','star on');
		jQuery("#star_5").attr('class','star on');
	},function(){
		get_star();
	});
	
	jQuery("#star_2").hover(function(){
		jQuery("#star_1").attr('class','star off');
		jQuery("#star_2").attr('class','star off');
		jQuery("#star_3").attr('class','star on');
		jQuery("#star_4").attr('class','star on');
		jQuery("#star_5").attr('class','star on');
	},function(){
		get_star();
	});
	
	jQuery("#star_3").hover(function(){
		jQuery("#star_1").attr('class','star off');
		jQuery("#star_2").attr('class','star off');
		jQuery("#star_3").attr('class','star off');
		jQuery("#star_4").attr('class','star on');
		jQuery("#star_5").attr('class','star on');
	},function(){
		get_star();
	});
	
	jQuery("#star_4").hover(function(){
		jQuery("#star_1").attr('class','star off');
		jQuery("#star_2").attr('class','star off');
		jQuery("#star_3").attr('class','star off');
		jQuery("#star_4").attr('class','star off');
		jQuery("#star_5").attr('class','star on');
	},function(){
		get_star();
	});
	
	jQuery("#star_5").hover(function(){
		jQuery("#star_1").attr('class','star off');
		jQuery("#star_2").attr('class','star off');
		jQuery("#star_3").attr('class','star off');
		jQuery("#star_4").attr('class','star off');
		jQuery("#star_5").attr('class','star off');
	},function(){
		get_star();
	});
	
	function get_star(){
		jQuery("#star_1").attr('class',window.buf_star_1);
		jQuery("#star_2").attr('class',window.buf_star_2);
		jQuery("#star_3").attr('class',window.buf_star_3);
		jQuery("#star_4").attr('class',window.buf_star_4);
		jQuery("#star_5").attr('class',window.buf_star_5);
	}
	
	jQuery("#star_1").click(function(){
		save_star();
	});
	jQuery("#star_2").click(function(){
		save_star();
	});
	jQuery("#star_3").click(function(){
		save_star();
	});
	jQuery("#star_4").click(function(){
		save_star();
	});
	jQuery("#star_5").click(function(){
		save_star();
	});
	
	function save_star(){
		window.buf_star_1 = jQuery("#star_1").attr('class');
		window.buf_star_2 = jQuery("#star_2").attr('class');
		window.buf_star_3 = jQuery("#star_3").attr('class');
		window.buf_star_4 = jQuery("#star_4").attr('class');
		window.buf_star_5 = jQuery("#star_5").attr('class');
	}
	
	//--------------------------------------------------- faq
	
	jQuery('.faq-question a.active').toggle(function(){
		jQuery(this).parent().next().slideDown();
	},function(){
		jQuery(this).parent().next().slideUp();
	});
	
	//--------------------------------------------------- Vote
	
	/*
	jQuery('#answer_vote').click(function() {	
			var id = jQuery("input[name=vote]").filter(":checked").val();
			var parent = jQuery("input[name=vote_parent]").val();
			var other = jQuery("input[name=writein_choice]").val();
			
			if(jQuery.cookie("vote")){
				arr = eval('(' + jQuery.cookie("vote") + ')');
			}		
			else arr = new Array();
			if (in_array(parent, arr))
				alert('Р’С‹ СѓР¶Рµ РѕСЃС‚Р°РІР»СЏР»Рё СЃРІРѕР№ РіРѕР»РѕСЃ РІ СЌС‚РѕРј РІРѕРїСЂРѕСЃРµ');
			else if((id == undefined) && (other == '')){
				alert('Choose to');
			}else{
				var url = "/ajax/vote.php";
				jQuery.ajax({
					async : false,
					url: url,
					type: "POST",
					data:
						"id="+id+'&parent='+parent+'&other='+other,
					dataType: "json",
					success: function(json){
						
						// добавляем id в куки
						var arr = new Array();
						if(jQuery.cookie("vote")){
							arr = eval('(' + jQuery.cookie("vote") + ')');
						}
						if (!in_array(json.id, arr))
						{
							arr[arr.length]=json.id;
							var jarr = jQuery.toJSON(arr);
							jQuery.cookie("vote",jarr,{expires: 360});
						}
					
						jQuery("#block_vote").html(json.text)
					}
				});
			}
			
			return false;	
	});*/
	
	jQuery('#answer_vote').click(function() {	
			
			var id = jQuery("input[name=vote]").filter(":checked").val();
			var parent = jQuery("input[name=vote_parent]").val();
			var other = jQuery("input[name=writein_choice]").val();
			
			var arr = new Array();
			if(jQuery.cookie("vote")){
				arr = eval('(' + jQuery.cookie("vote") + ')');
			}
			
			if (in_array(parent, arr)){
				alert($('#isvote').val());
			}else if((id == undefined) && (other == '')){
				alert('Choose to');
			}else{
				var url = "/ajax/vote.php";
				jQuery.ajax({
					async : false,
					url: url,
					type: "POST",
					data:
						"id="+id+'&parent='+parent+'&other='+other,
					dataType: "json",
					success: function(json){
						
						// добавляем id в куки
						var arr = new Array();
						if(jQuery.cookie("vote")){
							arr = eval('(' + jQuery.cookie("vote") + ')');
						}
						arr[arr.length]=json.id;
						var jarr = jQuery.toJSON(arr);
						jQuery.cookie("vote",jarr,{expires:360,path:"/"});
					
						jQuery("#block_vote").html(json.text);
					}
				});
			}
			
			return false;	
	});
	
	
	//----------------------------------------------------- Subscribe
	
	jQuery('#subscribe2').click(function(){
		var flag = jQuery(this).filter(':checked').val();
		jQuery.post('/ajax/subscribe.php','flag='+flag);
	});
	
	
	jQuery('select[name=cat_sel]').change(function(){
		jQuery('select.group').hide();
		var id = $(this).val().split(';');
		jQuery('#group_'+id[1]).show();
		//$("select[name=group_sel]").val($("select[name=group_sel] option:first").val());
	});
	
	
	//------------------------------------------------------
	
	jQuery('.morepic').click(function(){
		/*if($(this).val().length == 3) jQuery('#phone2').focus();*/
		jQuery(this).parent().hide();
		return false;
	});
	
	jQuery('#phone1').keyup(function(){
		if($(this).val().length == 3) jQuery('#phone2').focus();
	});
	jQuery('#phone2').keyup(function(){
		if($(this).val().length == 3) jQuery('#phone3').focus();
	});
	
	//---------------------------------------------------------
	
	
	
});

function open_auth(move){
	jQuery('#move').val(move);
	jQuery.fancybox({
		'padding' : 0,
		'speedOut' : 100,
		'overlayColor' : '#333',
		'href'	: '#auth'
	});
}
function open_reg(){
	jQuery.fancybox({
		'padding' : 0,
		'speedOut' : 100,
		'overlayColor' : '#333',
		'href'	: '#registration'
	});
}
function open_forgot(){
	jQuery.fancybox({
		'padding' : 0,
		'speedOut' : 100,
		'overlayColor' : '#333',
		'href'	: '#forgot'
	});
}



function in_array(needle, haystack, strict) {	// Checks if a value exists in an array
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var found = false, key, strict = !!strict;

	for (key in haystack) {
		if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
			found = true;
			break;
		}
	}
	return found;
}

function login(lang){
	jQuery.post('/ajax/login.php','login='+jQuery('input[name=u_login]').val()+'&pass='+jQuery('input[name=u_pwd]').val()+'&license='+jQuery('input[name=license]:checked').val(),function(result){
		if(result){
			jQuery('#auth').html(result);
		}else{
			location.href = '/'+lang+'/'+jQuery('#move').val()+'.htm';
		}
	});
}
function gotoplogin(){
	//jQuery('#fancybox-wrap').css('top','40px');
	jQuery('#license_text').slideDown();
}

function forgot(){
	jQuery.ajax({
		url: '/ajax/forgot.php'
		,async: false
		,data: 'op=1&email='+jQuery('input[name=email]').val()
		,type: 'post'
		,success: function(result){
			if(result){
				jQuery('#forgot').html(result);
				/*setTimeout(function(){
					jQuery('#forgot').hide();
					jQuery('#registration').hide();
					jQuery('#auth').show();
					
					jQuery.post('/ajax/forgot.php','',function(result){
						if(result){
							jQuery('#forgot').html(result);
						}
					});
				},1000);*/
			}
		}
	});
	
}
function reg(){
	
	if(jQuery('input[name=subscribe]:checked').val() == undefined){
		var subscribe = 0;
	}else{
		var subscribe = 1;
	}
	
	jQuery.post('/ajax/reg.php','email2='+jQuery('input[name=email2]').val()+'&pwd='+jQuery('input[name=pwd]').val()+'&pwd2='+jQuery('input[name=pwd2]').val()+'&subscribe='+subscribe,function(result){
		if(result){
			jQuery('#registration').html(result);
		}
	});
}

function add_comm(module,id){

	var comment_subj = jQuery('input[name=your_name]').val();
	var comment_text = jQuery('textarea[name=comment_text]').val();
	
	jQuery('input[name=your_name]').attr('disabled','disabled');
	jQuery('textarea[name=comment_text]').attr('disabled','disabled');
	
	jQuery.post('/ajax/addComment.php','id='+id+'&module='+module+'&comment_subj='+comment_subj+'&comment_text='+comment_text,function(result){
		jQuery('#body_comm').html(result);
		jQuery('input[name=your_name]').val('');
		jQuery('textarea[name=comment_text]').val('');
		jQuery('input[name=your_name]').attr('disabled','');
		jQuery('textarea[name=comment_text]').attr('disabled','');
	});
}

function edit_comm(id){

	var comment_subj = jQuery('input[name=subject2_'+id+']').val();
	if (comment_subj == undefined){
		var comment_subj = '';
	}
	var comment_text = jQuery('textarea[name=comment2_'+id+']').val();
	
	
	
	jQuery.post('/ajax/editComment.php','id='+id+'&comment_subj='+comment_subj+'&comment_text='+comment_text,function(result){
	
	
		jQuery('#body_edit_'+id).html('<font color="blue">'+result+'</font>');
	});
}

function set_star(id,vote)
{	
	jQuery.post('/ajax/setStar.php','id='+id+'&setvote='+vote,function(result){
		jQuery('#status_vote').html(result);
	});

	var buf = document.getElementById('hidevote');
	buf.style.display = "";
}

function add_faq(){

	var ask = jQuery('input[name=ask]').val();
	var more = jQuery('textarea[name=more]').val();
	
	if (ask.length){
		jQuery.post('/ajax/addFaq.php','ask='+ask+'&more='+more,function(result){
			jQuery('#faq_add_ok').html('<font color="blue">'+result+'</font>');
			jQuery('input[name=ask]').val('');
			jQuery('textarea[name=more]').val('');
		});
	}else{
		jQuery('input[name=ask]').css('border','1px dashed #DC0000');
		jQuery('#faq_add_ok').html('');
	}
}
	
function get_forgot(){
		jQuery('#blogin').hide();
		jQuery('#bforgot').fadeIn();
}
function get_reg(){
		jQuery('#blogin').hide();
		jQuery('#breg').fadeIn();
}

function photo_comment(id){
		var len = $(id).val().length + ' симв. (60 макс.)';
		$(id).next().text(len);
}
function del_photo(id){

	jQuery.post('/ajax/delphoto.php','id='+id,function(result){
		jQuery('#photos').html(result);
	});
}
function set_section(id){
		jQuery('.section2').hide();
		jQuery('#section_'+id).show();
}
function set_period(id){
	var period = jQuery('select[name=week_'+id+']').val();
	jQuery.post('/ajax/basket.php','id='+id+'&period='+period,function(result){
		jQuery('#tbody_body').html(result);
		update_datepicker();
	});
}
function set_period_ext(id){
	var period = jQuery('select[name=week_'+id+']').val();
	jQuery.post('/ajax/basket_extend.php','id='+id+'&period='+period,function(result){
		jQuery('#tbody_body').html(result);
		//update_datepicker();
	});
}
function update_datepicker(){
		jQuery('.datepicker').datepicker({
			duration: ''
			,minDate: ''
			,onSelect: function(dateText, inst){
				var id = $(this).prev().val();
				jQuery.post('/ajax/basket.php','id='+id+'&date='+inst.selectedYear + '-' + (inst.selectedMonth+1) + '-' + inst.selectedDay,function(result){
					jQuery('#tbody_body').html(result);
					update_datepicker();
				});
			}
		});
}

function add_othercity(id){
	var city = $('#states').val();
	jQuery.post('/ajax/editOtherCity.php','id='+id+'&city='+city+'&op=add',function(result){
		jQuery('#othercity').html(result);
	});
}
function add_othercity2(id){
	var city = $('#states').val();
	jQuery.post('/ajax/editOtherCity2.php','id='+id+'&city='+city+'&op=add',function(result){
		jQuery('#othercity').html(result);
	});
}
function sub_othercity(id){
	var city = $('#states').val();
	jQuery.post('/ajax/editOtherCity.php','id='+id+'&city='+city+'&op=sub',function(result){
		jQuery('#othercity').html(result);
	});
}
function sub_othercity2(id){
	var city = $('#states').val();
	jQuery.post('/ajax/editOtherCity2.php','id='+id+'&city='+city+'&op=sub',function(result){
		jQuery('#othercity').html(result);
	});
}
function addall_othercity(id){
	var flag = 1;
	if($('#add_othercity_all:checked').val() == undefined){
		flag = 0;
	}
	jQuery.post('/ajax/editOtherCity.php','id='+id+'&op=addall&flag='+flag,function(result){
		jQuery('#othercity').html(result);
	});
}
function addall_othercity2(id){
	var flag = 1;
	if($('#add_othercity_all:checked').val() == undefined){
		flag = 0;
	}
	jQuery.post('/ajax/editOtherCity2.php','id='+id+'&op=addall&flag='+flag,function(result){
		jQuery('#othercity').html(result);
	});
}

function show_photos(id){
	$('#morepic_'+id).css('top','5%');
	$('#morepic_'+id).show();
}


