$(document).ready(function(){
	
	// if content so much to hide VK widget
	if ($("#leftCol").height()<1300) $("#vk_groups_wrapper").hide();

	// при щелчке на форму скрывается ее значение
    $(".event-account").bind("focus", function() {
		if (this.value == this.title) this.value = "";
    }).bind("blur",	function() {
        if (this.value == "") this.value = this.title;
    }).blur();	
	
	
	////сообщение об ошибке  
	$("#errorMessage .close").click(function(){
		$(this).parent().fadeOut(500);
	});
	
	/* обработка событий меню */
	$("#nav li ul,#nav li li").mouseover(function(){
		$(this).parent().find(".parent").addClass("currentParent");
	}).mouseout(function(){
		$("#nav li .parent").each(function(){
			$(this).removeClass("currentParent");
		})
	});
	
	$("#nav li ul").each(function(){
	   $(this).find("li:last").css("border-bottom","0");
	})
	
	/* обработка меню разделов главной страницы */ 
    $('.navigate a').live('click', function() {
    	var wi = $(this).parent().parent().parent().parent().find(".wrapped_zone").width();
    	var he = $(this).parent().parent().parent().find(".wrapped_zone").height();
    	$(this).parent().parent().parent().find(".overlay").css({"height":he+"px","width":wi+"px"});
    	
    	$(this).parent().find("a").each(function(){
    		$(this).removeClass("current");
    	});
    	$(this).addClass("current");
	});	
	
	// галлереи galParserKadr
	if($(".galParserKadr").length>0) {
		$(".galParserKadr").each(function(){
			var original_width  = $(this).parent().find(".original img").width();		
			var count_photos  = $(this).find(".kadr_element").size();	
			var elem_width = original_width/count_photos;
			$(this).find(".kadr_element").each(function(i){
				if (!i) 
				{
					$(this).css("width", elem_width+"px");
				} 
			else 
				{	
					// выполним пересчет ширины последнией фотографии
					if (i+1==count_photos) {
						elem_width_tmp = original_width - $(this).prev().css("left").replace("px","") - elem_width;
						$(this).css("width", 1+elem_width_tmp+"px");
						$(this).css("left", parseInt(elem_width)*i+"px");
					} else {
						$(this).css("width", elem_width+"px");
						$(this).css("left", parseInt(elem_width)*i+"px");
					}
				} 				
			});
		});
	}
	$(".kadr_element").mouseover(function(){
		$(this).parent().find(".original img").attr("src", $(this).find("img").attr("src"));
		$(this).addClass("top");
	}).mouseout(function(){
		$(this).removeClass("top");
	});	
});


/*обрботка меню*/
jsHover = function() {
    var hEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0, len=hEls.length; i<len; i++) {
			hEls[i].onmouseover=function() { this.className+=" jshover";}
			hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
		}
}
if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) {window.attachEvent("onload", jsHover);}

