jQuery.noConflict();
   jQuery(document).ready(function() {

jQuery("img.whereis_zoom").hover(function() {
jQuery(this).css({'z-index' : '10'});
jQuery(this).find('img').addClass("hover").stop()
.animate({
marginTop: '-110px',
marginLeft: '-110px',
top: '50%',
left: '50%',
width: '174px',
height: '174px',
padding: '20px'
}, 200);

} , function() {
jQuery(this).css({'z-index' : '0'});
jQuery(this).find('img').removeClass("hover").stop()
.animate({
marginTop: '0',
marginLeft: '0',
top: '0',
left: '0',
width: '100px',
height: '100px',
padding: '5px'
}, 400);
});

jQuery('a.ratings_stars').hover(
 // Handles the mouseover  
 function() {  
     jQuery(this).prevAll("a").andSelf().addClass('ratings_over');  
     jQuery(this).nextAll("a").removeClass('ratings_vote');  
 },  
 // Handles the mouseout  
 function() {  
     jQuery(this).prevAll("a").andSelf().removeClass('ratings_over');  
     set_votes(jQuery(this).parent());  
 }  
); 


       jQuery(".trigger").click(function() {
          jQuery(".panel").toggle("fast");
          jQuery(this).toggleClass("active");
          return false;
       });

	function sm_reload()
	{   show_mask();
        function onAjaxSuccess(data)
		{   jQuery(".ajax").unbind('click');
			jQuery("div[class=b_1]").html(data);
			jQuery(".ajax").bind('click', sm_reload);
			jQuery(".to_basket").bind('click', basket_io);
            jQuery("#send_help").bind('click', send_help);
            jQuery("#send_msg").bind('click', send_mail);
            //START RATING
            jQuery('.star_' + jQuery("#rate_num").attr("class")).prevAll("a").andSelf().addClass('ratings_vote');  
	    jQuery('.star_' + jQuery("#rate_num").attr("class")).nextAll("a").removeClass('ratings_vote'); 
	    jQuery(".star").bind("click", set_rate); 
            jQuery('a.ratings_stars').hover(function() {
		     jQuery(this).prevAll("a").andSelf().addClass('ratings_over');
		     jQuery(this).nextAll("a").removeClass('ratings_vote');
		     jQuery("#rate_num").html(jQuery(this).attr("id"));
		 },
		 // Handles the mouseout  
		 function() {
		     jQuery(this).prevAll("a").andSelf().removeClass('ratings_over');
		     jQuery("#rate_num").html(jQuery("#rate_num").attr("class"));
		     set_votes(jQuery(this).parent());
		 }
	     );
	     //END RATING 
/**/
	    jQuery("#send_cert").bind('click', send_cert);
            jQuery('#send_order').bind('click', send_order);
            var preload = new Array();
            jQuery('.whereis_zoom').each(function() {
                s = jQuery(this).attr('href');
                jQuery('<img />').attr('src', s);
            });
            jQuery('.whereis_zoom').hover(function(){
                    jQuery(this).css({'z-index' : '99'});
                    jQuery(this).css({'position' : 'absolute'});
                    var temp = jQuery(this).attr('src')
                    jQuery(this).attr('src', jQuery(this).attr('href'));
                    jQuery(this).attr('href', temp);
                	jQuery(this).addClass("hover").stop()
            		.animate({}, 200);

            	} , function() {
                	jQuery(this).css({'z-index' : '0'});
                    jQuery(this).css({'position' : 'relative'});
                    var temp = jQuery(this).attr('src')
                    jQuery(this).attr('src', jQuery(this).attr('href'));
                    jQuery(this).attr('href', temp);
                	jQuery(this).removeClass("hover").stop()
            		.animate({


        	    	}, 400);
                }
            );
            jQuery('.diplom_zoom').lightBox({
            fixedNavigation: true
            });
            
            //jQuery('.diplom_zoom').bind('click', function(){alert('gf'), return false;});
            jQuery(".panel").hide("fast");
            jQuery(".trigger").removeClass("active");
            jQuery(".nobind").unbind('click');
            jQuery("#register11").bind('click', function(){if(jQuery('.b_1').validationEngine({returnIsValid:true})){show_mask();
              jQuery.ajax({
       			type: "POST",
       			url: "./classes/user_aj.php",
       			data: "action=register"+
    	        "&username="+jQuery('#mail').val()+
                "&pass1="+jQuery('#pass1').val()+
            	"&pass2="+jQuery('#pass2').val()+
            	"&fname="+jQuery('#fname').val()+
            	"&sname="+jQuery('#sname').val()+
            	"&phone="+jQuery('#phone').val()+
            	"&mail="+jQuery('#mail').val()+
                "&address="+jQuery('#address').val()+
                "&comment="+jQuery('#opt').val()+
            	"&post_index="+jQuery('#post_index').val()+
            	"&smail="+jQuery('#smail').val(),
    			dataType: "json",
       			success: function(data){
                    alert(data.msg);
                    if(data.result=="ok"){
                    jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess);}
                    else if(data.result=="hm"){hide_mask();}

    			    }

 	    	    });
                }
            });
           hide_mask();
		}

		jQuery.post(jQuery(this).attr("href")+"&mode=ajax&rnd="+Math.random(),{type: Math.random()},onAjaxSuccess);
	return false;
	}
    jQuery(".ajax").bind('click', sm_reload);
    jQuery(".to_basket").bind('click', basket_io);
    jQuery(".logout").bind('click', logout);

    jQuery(".nobind").unbind('click');



function basket_io(){
  var curr_id=jQuery(this).attr("id");
	jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=add_tobasket&id="+curr_id,
		dataType: "json",
		success: function(data){
			jQuery(".c_count").empty();
			jQuery(".c_count").append(data.pr_count);
			if(data.action=="add"){
				jQuery.ajax({
					type: "POST",
					url: "classes/user_aj.php",
					data: "action=get_b_img&id="+data.id,
					dataType: "html",
					success: function(html){
						jQuery(".panel").append(html);
						jQuery("a#"+curr_id).bind('click', basket_io);

					}
				});
			}
			else{
			jQuery("#basket_"+data.id).remove();
            jQuery("a#"+data.id).parent().parent("tr").remove();
			if(data.pr_count=="0"){
				jQuery(".panel").hide("fast");
          			jQuery(".trigger").removeClass("active");
			jQuery(".b_4_1 > #"+data.id).attr("checked", "");
			}
			}
		}
	});
}

//});


});

function set_rate(){
var rate = jQuery(this).attr("id");
var id = jQuery(".story_text").attr("id");
   jQuery.ajax({
        type: "POST",
        url: "classes/user_aj.php",
        data: "action=rate_story&id="+id+"&rate="+rate,
        dataType: "json",
        success: function(data){
        alert(data.msg);
        jQuery("#rate_num").attr("class", data.rate);
        jQuery("#rate_num").html(data.rate);
        jQuery('.star_' + jQuery("#rate_num").attr("class")).prevAll("a").andSelf().addClass('ratings_vote');
        jQuery('.star_' + jQuery("#rate_num").attr("class")).nextAll("a").removeClass('ratings_vote');
        }
   });
    
}

function hover_zoom(){
     jQuery(this).animate({width:"600px",height:"600px"}, 400);
}

function whereis_zoom(){


}


function map_hover(region_id){
    jQuery(".map_reg").hide();
    jQuery("#"+region_id).show();
}

function map_click(region_id){
    jQuery(".map_info").attr("style", "display: none;");
    jQuery(".map_"+region_id).show();
}

function checkbox_click(){
    jQuery("#"+jQuery(this).attr('class')).attr('checked', '');
    jQuery(this).attr('checked', 'checked');
}

function onAjaxSuccess(data)
		{ hide_mask();
			jQuery("div[class=b_1]").html(data);
			jQuery(".ajax").bind('click', sm_reload);
			jQuery(".to_basket").bind('click', basket_io);
            jQuery("#send_help").bind('click', send_help);
            jQuery("#send_msg").bind('click', send_mail);
	    jQuery('#send_order').bind('click', send_order);
            jQuery('.diplom_zoom').lightBox();
            jQuery(".panel").hide("fast");
/*                        //START RATING
            jQuery('.star_' + jQuery("#rate_num").attr("class")).prevAll("a").andSelf().addClass('ratings_vote');  
	    jQuery('.star_' + jQuery("#rate_num").attr("class")).nextAll("a").removeClass('ratings_vote'); 
	    jQuery(".star").bind("click", set_rate); 
            jQuery('a.ratings_stars').hover(  

		 function() {  
		     jQuery(this).prevAll("a").andSelf().addClass('ratings_over');  
		     jQuery(this).nextAll("a").removeClass('ratings_vote');
		     jQuery("#rate_num").html(jQuery(this).attr("id"));
		 },  
		 // Handles the mouseout  
		 function() {  
		     jQuery(this).prevAll("a").andSelf().removeClass('ratings_over');  
		     jQuery("#rate_num").html(jQuery("#rate_num").attr("class"));
		     set_votes(jQuery(this).parent());  
		 }  
	     );
	     //END RATING 
*/
            jQuery(".nobind").unbind('click');
            jQuery("#register11").bind('click', function(){
              jQuery.ajax({
       			type: "POST",
       			url: "./classes/user_aj.php",
       			data: "action=register"+
    	        "&username="+jQuery('#username').val()+
                "&pass1="+jQuery('#pass1').val()+
            	"&pass2="+jQuery('#pass2').val()+
            	"&fname="+jQuery('#fname').val()+
            	"&sname="+jQuery('#sname').val()+
            	"&phone="+jQuery('#phone').val()+
            	"&mail="+jQuery('#mail').val()+
                "&address="+jQuery('#address').val()+
                "&comment="+jQuery('#comment').val()+
            	"&post_index="+jQuery('#post_index').val()+
            	"&smail="+jQuery('#smail').val(),
    			dataType: "json",
       			success: function(data){
                    alert(data.msg);
                    jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess);
    			    }
 	    	    });
            });

		}

function send_order(){
if(jQuery('.b_1').validationEngine({returnIsValid:true})){
    show_mask();
    var item_count="";
    var items=0;
    jQuery(".art_count").each(function(){
               ++items;
         item_count=item_count+"&art"+items+"="+jQuery(this).attr('id')+"&count"+items+"="+jQuery(this).val();

    });
    tosend="action=buy_out"+
      	"&fname="+jQuery('#fname').val()+
      	"&sname="+jQuery('#sname').val()+
      	"&phone="+jQuery('#phone').val()+
      	"&mail="+jQuery('#mail').val()+
        "&comment="+jQuery('#comment').val()+"&items="+items+item_count;
    jQuery.ajax({
    type: "POST",
    url: "./classes/user_aj.php",
    data: tosend,
        dataType: "json",
       	success: function(data){
            if(data.result=="ok"){
             jQuery.post("http://oniksda.com?page=buy_done&mode=ajax",{type: Math.random()},onAjaxSuccess);
            setTimeout('jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess)', 5000);
			}
    	}
 	});}

	return false;
}

function send_help(){show_mask();
      jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=send_help&mail="+jQuery("#mail").val()+
        "&name="+jQuery("#name").val()+
        "&o1="+jQuery("#o1").attr('checked')+
        "&o2="+jQuery("#o2").attr('checked')+
        "&o3="+jQuery("#o3").attr('checked')+
        "&o4="+jQuery("#o4").attr('checked')+
        "&o5="+jQuery("#o5").attr('checked')+
        "&o6="+jQuery("#o6").attr('checked')+
        "&o7="+jQuery("#o7").attr('checked')+
        "&o8="+jQuery("#o8").attr('checked')+
        "&p1="+jQuery("#p1").attr('checked')+
        "&p2="+jQuery("#p2").attr('checked')+
        "&p3="+jQuery("#p3").attr('checked')+
        "&p4="+jQuery("#p4").attr('checked')+
        "&r_type="+jQuery("#r_type option:selected").text()+
        "&size="+jQuery("#size option:selected").text()+
        "&metal="+jQuery("#metal option:selected").text(),
		dataType: "json",
		success: function(data){
			if(data.remind=="ok"){  jQuery.post("http://oniksda.com?page=msg_sent&mode=ajax",{type: Math.random()},onAjaxSuccess);
            setTimeout('jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess)', 5000);
					}
        }
    });
}

function send_cert(){show_mask();
      jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=send_cert&mail="+jQuery("#mail").val()+
        "&cert_price="+jQuery("#cert_price").val()+
        "&phone="+jQuery("#phone").val()+
        "&cert_count="+jQuery("#cert_count").val()+
        "&contact="+jQuery("#contact").val(),
		dataType: "json",
        success: function(data){
            if(data.result=="ok"){
             jQuery.post("http://oniksda.com?page=buy_done&mode=ajax",{type: Math.random()},onAjaxSuccess);
            setTimeout('jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess)', 5000);
			}
//"&cert_price="+jQuery("#cert_price option:selected").text()+
            	}
    });
}

function send_mail(){ show_mask();
      jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=send_msg&mail="+jQuery("#mail").val()+
        "&name="+jQuery("#name").val()+
        "&msg="+jQuery("#msg").val()+
        "&theme="+jQuery("#theme option:selected").text()+
        "&val="+jQuery("#theme option:selected").val()+
        "&secode="+jQuery("#secode").val(),
        dataType: "json",
		success: function(data){
			if(data.result=="ok"){jQuery.post("http://oniksda.com?page=msg_sent&mode=ajax",{type: Math.random()},onAjaxSuccess);
                    setTimeout('jQuery.post("http://oniksda.com?page=index&mode=ajax",{type: Math.random()},onAjaxSuccess)', 5000);
			} else {
				if(data.result=="bs"){
					hide_mask();
					alert("Неверный проверочный код");
				}
			}
		}
    });
}
function login(page){
      if(jQuery("#name").val()!=""){show_mask();
      jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=login&name="+jQuery("#name").val()+
        "&pass="+jQuery("#pass11").val(),
        dataType: "json",
		success: function(data){
		   if(data.result=="ok"){window.location.href="http://oniksda.com?page="+page;}
		   if(data.login=="fail"){alert("Вы ввели неправильный пароль"); hide_mask(); }
        }
    });
           }
}

function logout(){
      jQuery.ajax({
		type: "POST",
		url: "classes/user_aj.php",
		data: "action=logout",
        dataType: "json",
		success: function(data){
		   if(data.logout=="ok"){window.location.href="http://oniksda.com?page=index";}
        }
    });
}

function show_map(){
jQuery('.route_map').toggle();
//alert('dsds');
}

function show_mask(){
	jQuery('#mask').fadeTo("fast",0.8);}
//	var winH = $(window).height();
//	var winW = $(window).width();
 /*	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);
	$(id).fadeIn(2000);
}    */

function hide_mask(){
	jQuery('#mask').hide();
//	jQuery('.window').hide();
//	NoHideModal();
}

function pass_reminder(){
var mail=prompt('Введите e-mail указанный при регистрации');
      jQuery.ajax({
      type: "POST",
      url: "classes/user_aj.php",
      data: "action=rem_pass&mail="+mail,
        dataType: "json",
        success: function(data){
        alert(data.reply);
        }
    });
 }
/*function hide_map(){
jQuery('.route_map').hide();
//alert('ew');
}
  */


