$(document).ready(function(){
    
    $(".remove").remove();
    
    $(".region_cat").click(function(){
        elem_num = $(this).index() / 2;
        $(".regionInn").each(function(e){
            if(e != elem_num){
                //alert(e);
                $(this).hide(500);
            }
            else {
                $(this).toggle(500);
            }
        });
        return false;
    });

$(".city").click(function(){
    $(".city").removeClass("activeCity");
    $(this).addClass("activeCity");
   
});

flag = $("#categ");
if(flag.length > 0 && $("#categ").val() !=''){
    $("#cat_" + $("#categ").val()).show();
$(".parent_" + $("#elem").val()).addClass("activeCity");
var city = $(".cityName_" + $("#elem").val()).text();
$("#points .center h2").text(city);
}
else{
    $("#points").hide();
}


if($(".tovElem2").length){

$(".tovElem2 a[rel^='prettyPhoto']").prettyPhoto({
animation_speed: 'fast',
slideshow: false,
autoplay_slideshow: false,
opacity: 0.80,
show_title: true,
allow_resize: false,
counter_separator_label: '/',
theme: 'facebook',
hideflash: false,
wmode: 'opaque',
autoplay: false,
modal: false,
overlay_gallery: false,
keyboard_shortcuts: true
});

}

if($(".picCont").length){

$(".picCont a[rel^='prettyPhoto']").prettyPhoto({
animation_speed: 'fast',
slideshow: false,
autoplay_slideshow: false,
opacity: 0.80,
show_title: true,
allow_resize: false,
counter_separator_label: '/',
theme: 'facebook',
hideflash: false,
wmode: 'opaque',
autoplay: false,
modal: false,
overlay_gallery: false,
keyboard_shortcuts: true
});

}

     //corners    
    $("#formSend").corner("5px");
    $(".newsContInn").corner("12px");

$(".subMenu").each(function(e){
    if(e == 0){
        $(this).corner("tr br bl 12px");
    } else {
        $(".subMenu:eq(" + e + ")").corner("12px");
    }
});
    
    var selectedElem = '-1';

        $(".mainMenu li").each(function(i){
            if($(this).hasClass('active')){
                selectedElem = i;
            }
        });
    
    $(".mainMenu ul li").mouseover(function(){
        elem_num = $(this).find('a').attr('rel');
        
        $(".subMenu").hide();
        $("#elem_" + elem_num).show();
        
        $(".mainMenu ul li").removeClass('active');
    });
    
$(".mainMenu").mouseleave(function(){
        if(selectedElem != '-1'){
            $(".mainMenu li:eq("+ selectedElem + ")").addClass('active');
        }
});
    
    $(".subMenu").mouseover(function(){
        $(".mainMenu ul li").removeClass('active');
    
        elem_num = $(this).attr('id').split('_')[1];
        
        $("a[rel='" + elem_num + "']").parent().addClass('hover');
    });
    
$(".subMenu").mouseleave(function(){
        $(".subMenu").hide();
        $(".mainMenu ul li").removeClass('hover');
        
        if(selectedElem != '-1'){
            $(".mainMenu li:eq("+ selectedElem + ")").addClass('active');
        }
});

    $("#header, .picMain, .mainMenuLineLeft, .mainMenuLineRight").mouseover(function(){
        $(".subMenu").hide();
        if(selectedElem != '-1'){
            $(".mainMenu li:eq("+ selectedElem + ")").addClass('active');
        }    
    });
    
    $(".withSub").mouseover(function(){
        $(".withSub").removeClass('hover');
        $(this).addClass('hover');
    });
    $(".withSub").mouseleave(function(){
        $(this).removeClass('hover');
    });
    
    $("#srchCont input").click(function(){
        $(this).val('');
    });
    $("#srchCont input").blur(function(){
        if($(this).val() == ''){
            $(this).val('Поиск');
        }
    });
    

    /*catalogue first item*/
    $(".mainMenuRight ul li:first-child").addClass("first");

function titleClose(){
    $("#cboxTitle").remove();
}

$(".new_pass, .registr, .auth_entry, .authLink2, .chgData").colorbox({
    iframe:true,
    width:"440px",
    height:"200%",
    returnFocus:false,
    onOpen:titleClose(),
    overlayClose:false,
    scrolling:false

});


$("#formSend").click(function(){
    $("#where_form").submit();
    return false;
});

});
function max(a,b,c){
m=a;
if(b>m) m=b;
if(c>m) m=c;
return m;
}

$(window).load(function(){
var nam=$('.tov');
var n=nam.size();

for(i=0;i<=(n-n%3)/3;i++)
{
	m=max($(nam[i*3]).height(),$(nam[i*3+1]).height(),$(nam[i*3+2]).height());
	$(nam[i*3]).height(m);
	$(nam[i*3+1]).height(m);
	$(nam[i*3+2]).height(m);
}
});
