var current_frame = 1;
var step = 502;
var current_prod = 1;

$(document).ready(function(){	
	$(".life_part_main .head").click(function(){
		var div_ac = $(this).parent("div");
		var div_cont = div_ac.find(".container");
		if(div_cont.is(":visible")){
			div_ac.removeClass("activ").addClass("no_activ");
		}
		else{
			div_ac.removeClass("no_activ").addClass("activ");
		}
		return false;
	});
	
	
	var num_slide = parseInt($("#num_slide").html());
	if(num_slide){
		start_y_menu(num_slide);
	}
	var num_prod = parseInt($("#num_prod").html());
	if(num_prod){
		start_prod_menu(num_prod);
	}
	
	$(".hide_answer").hide();
	$(".down_box").hide();
	var all_time = 200;
	var time_out;
	var timer2;
	var timer3;
	var timer4;
	var life_timer;
	var mouse_is_inside = false;	
	
	$(".right_slide_m").click(function(){
		current_frame += 1;
		$(".left_slide_m").show();
		if(current_frame == num_slide){
			$(".right_slide_m").hide();			
		}
		$(".m_table").animate({"marginLeft": "-=502px"}, 500);
		return false;
	});
	
	$(".left_slide_m").click(function(){
		current_frame -= 1;
		if(num_slide > 1 && current_frame != num_slide){
			$(".right_slide_m").show();
		}
		if(current_prod == 1){
			$(".right_slide_m").show();
			$(".left_slide_m").hide();
		}
		$(".m_table").animate({"marginLeft": "+=502px"}, 500);
		return false;
	});
	
	
	/**************************/
	
	
	//prod
	$(".top_slide_prod").click(function(){
		current_prod -= 1;		
		$(".bottom_slide_prod").css("display", "block").show("fast");
		if( current_prod == 1){
			$(".top_slide_prod").hide();
			$(".bottom_slide_prod").show();			
		}
		$(".prod_menu").animate({"marginTop": "+=165px"}, 700);
		return false;
	});
	
	$(".bottom_slide_prod").click(function(){
		current_prod += 1;	
		$(".top_slide_prod").show();	
		if(current_prod == num_prod){
			$(".bottom_slide_prod").hide();
		}
		
		$(".prod_menu").animate({"marginTop": "-=165px"}, 700);
		return false;
	});
	//end prod
	
	$("#show_map").click(function(){
		if($("#map_canvas").is(":visible")){$("#map_canvas").hide();}
		else{$("#map_canvas").show();}
		return false;
	});
	
	/*show and hide nav panel*/
	
	$('.bottom_main_table').hover(function(){ 
        mouse_is_inside=true; 		
    }, function(){ 
        mouse_is_inside=false;		
    });	
	$("body").click(function(){ 
        if(! mouse_is_inside){
			close_menu();
		}
    });
	/*end show and hide nav panel*/	
	
	//life_partners
	$(".lp_discount").unbind('mouseenter').bind('mouseenter',show_info).unbind('mouseleave').bind('mouseleave',hide_info);	
	function show_info(){
		var popup = $(this).children(".popup_info");
		
		$(".popup_info").hide();				
		clearTimeout(life_timer);
		popup.show();
		
		var popup_height = parseInt(popup.css("height"));
		offset = popup.offset();
		var popup_star_margin = parseInt(offset.top);		
		var win_height = parseInt($(window).height());
		var scrollTop = parseInt($(window).scrollTop());
		
		
		var marginTop_limit =  popup_height + popup_star_margin;
		var scroll_limit = scrollTop + win_height;
		
		//alert(scroll_limit+" - "+marginTop_limit)
		if(scroll_limit < marginTop_limit){
			marginTop =  - (popup_height + 50);
			popup.css("marginTop", marginTop)
		}
		else{
			popup.css("marginTop", 0)
		}
		//aler	
	}	
	function hide_info(){
		clearTimeout(life_timer);
		$this = $(this);
		life_timer = setTimeout(function(){
			$(".popup_info").hide().css("marginTop", 0);		
		},all_time)
	}	
	
	
	/*top menu*/
	//level 1
	$(".over").unbind('mouseenter').bind('mouseenter',show_menu).unbind('mouseleave').bind('mouseleave',hide_top_menu);	
	function show_menu(){
		$(".top_menu").hide();
		$(".over").children("a").removeClass("activ");		
		clearTimeout(timer2);
		$(this).children("a").addClass("activ");
		$(this).find(".top_menu").show();	
			
	}	
	function hide_top_menu(){
		clearTimeout(timer2);
		$this = $(this);
		timer2 = setTimeout(function(){
			$this.children("a").removeClass("activ");			
			$this.find(".top_menu").hide();	
		},all_time)
	}	
	
	//show sert
	$(".show_down").unbind('mouseenter').bind('mouseenter',show_down).unbind('mouseleave').bind('mouseleave',hide_down);
	function show_down(){
		clearTimeout(timer4);
		$(".down_box").hide();	
		$(this).find("div").show();		
	}
	
	function hide_down(){
		clearTimeout(timer4);
				
		timer4 = setTimeout(function(){
			$(".down_box").hide();	
		},all_time)
	}
	//end sert
	
	//level 2
	$(".but_arrow").unbind('mouseenter').bind('mouseenter',show_menu_level_2).unbind('mouseleave').bind('mouseleave',hide_menu_level_2);
	
	function show_menu_level_2(){
		var height_marg = $(this).css("height") ;
		clearTimeout(timer3);
		$(".but_arrow").children("a").removeClass("arrow").removeClass("arrow_but").addClass("arrow");
		$(this).children("a").removeClass("arrow").removeClass("arrow_but").addClass("arrow_but");
		$(".top_sub_menu").hide();		
		$(this).find(".top_sub_menu").show();		
	}
	
	function hide_menu_level_2(){
		clearTimeout(timer3);
		$this = $(this);
		$this2 = $(this);
		
		timer3 = setTimeout(function(){
			$(".but_arrow").children("a").removeClass("arrow").removeClass("arrow_but").addClass("arrow");
			$this.find(".top_sub_menu").hide();	
		},all_time)
	}	
			
	/*end top menu*/	
		
	
	
	$(".opros_link_open").click(function(){
		var margin = parseInt($(".slide_opros").css("marginLeft"));
		
		if(margin == 300){
			$(this).find("img").addClass("activ");			
			$(".slide_opros").animate({"marginLeft": "0", "marginRight": "0"});
			$(".all_page_opros").css("zIndex", 100);
		}
		else{
			$(this).find("img").removeClass("activ");
			$(".slide_opros").animate({"marginLeft": "300px", "marginRight": "-300px"}, function(){$(".all_page_opros").css("zIndex", 10);});
			
		}
		return false;
	});
	
	
	
	$(".unhide_answer").click( function(){
		var clicked = $(this).parent("td");
		if (clicked.find("span").is(":visible")) {
			clicked.find("span").hide();
		}
		else{
			clicked.find("span").show();
		}
		return false;
	});
	
	//sign
	$("#sign_in").click(function(){
		$(this).hide();
		$("#sg_tb").fadeIn("fast");
		return false;
	});
	
	$("#subm").click(function(){
		$("#sign_in").hide();
		$("#sg_tb").hide();
		$("#alarm_table").fadeIn("fast");
		return false;
	});
	
	$("#alarm_but").click(function(){
		$("#sign_in").hide();
		$("#alarm_table").hide();
		$("#sg_tb").fadeIn("fast");
		return false;
	});
	
	
	
	var menu_time;
	var menu_time2;
	var menu_time3;
	var timer = 200;
	var menu_time_full;
	var menu_time_full_1;	
	var menu_time_full_2;	
	var menu_time_full_3;	
	var slide_speed_full = 400;
	
	
	//all			
	$("#all_all_table").unbind('mouseenter')
					  .bind('mouseenter',m_enter_full)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave_full)					  
					  
				
				function m_enter_full(){clearTimeout(menu_time_full);}
				
				function m_leave_full(){					
					clearTimeout(menu_time_full);
					menu_time_full 	= setTimeout(function(){
					//for_start_position();
					},600);								
				}
	
	
	//full slider
	$("#club_full").unbind('mouseenter')
					  .bind('mouseenter',m_enter_full_1)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave_full_1)					  
					  
				
				function m_enter_full_1(){
					$("#lich_div_full").hide();
					$("#corp_div_full").hide();
					$("#l_t").stop().animate({"marginLeft": "-432px"},slide_speed_full, function(){$("#club_div_full").fadeIn("fast");});
					$("#l_b").stop().animate({"marginTop": "0px"},slide_speed_full);
					$("#c_t").stop().animate({"marginTop": "-432px"},slide_speed_full);
					$("#c_b").stop().animate({"marginLeft": "0px"},slide_speed_full);
					$("#c_b_l").stop().animate({"marginLeft": "0px"},slide_speed_full);
					$("#r_t").stop().animate({"marginLeft": "-432px"},slide_speed_full);
					$("#r_b").stop().animate({"marginTop": "0px"},slide_speed_full);					
				}
				
				function m_leave_full_1(){clearTimeout(menu_time_full_1);}
				
				//lich
				$("#lich_show_full").unbind('mouseenter')
				                    .bind('mouseenter',m_enter_full_2)
									.unbind('mouseleave')
									.bind('mouseleave',m_leave_full_2);
									
				function m_enter_full_2(){
					$("#club_div_full").hide();
					$("#corp_div_full").hide();
					$("#l_t").stop().animate({"marginLeft": "-216px"},slide_speed_full);
					$("#l_b").stop().animate({"marginTop": "-216px"},slide_speed_full);
					$("#c_t").stop().animate({"marginTop": "-216px"},slide_speed_full, function(){$("#lich_div_full").fadeIn("fast");});
					$("#c_b").stop().animate({"marginLeft": "-324px"},slide_speed_full);
					$("#c_b_l").stop().animate({"marginLeft": "-215px"},slide_speed_full);
					$("#r_t").stop().animate({"marginLeft": "-216px"},slide_speed_full);
					$("#r_b").stop().animate({"marginTop": "-432px"},slide_speed_full);					
				}
				
				function m_leave_full_2(){clearTimeout(menu_time_full_2);}
				
				
	//corp			
	$("#corp_show_full").unbind('mouseenter')
					  .bind('mouseenter',m_enter_full_3)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave_full_3)					  
					  
				
				function m_enter_full_3(){					
					
						$("#club_div_full").hide();
						$("#lich_div_full").hide();						
						$("#l_t").stop().animate({"marginLeft": "0px"},slide_speed_full);
						$("#left_slide_bottom span").stop().animate({"marginTop": "-432px"},slide_speed_full);
						$("#center_slide_top span").stop().animate({"marginTop": "0px"},slide_speed_full);
						$("#center_slide_bottom span").stop().animate({"marginLeft": "-648px"},slide_speed_full);
						$("#c_b_l").stop().animate({"marginLeft": "-430px"},slide_speed_full);
						$("#r_t").stop().animate({"marginLeft": "0px"},slide_speed_full, function(){$("#corp_div_full").fadeIn("fast");});
						$("#right_slide_bottom span").stop().animate({"marginTop": "-216px"},slide_speed_full);					
					
					
					
					
				}
				
				function m_leave_full_3(){					
					clearTimeout(menu_time_full_3);
					}
				
				function for_start_position(){
					$("#club_div_full").hide();
					$("#lich_div_full").hide();
					$("#corp_div_full").hide();
					$("#l_t").stop().css("marginLeft", "-432px").animate({"marginLeft": "-648px"},slide_speed_full);
					$("#left_slide_bottom span").stop().animate({"marginTop": "0px"},slide_speed_full);
					$("#center_slide_top span").stop().animate({"marginTop": "-432px"},slide_speed_full);
					$("#center_slide_bottom span").stop().animate({"marginLeft": "0px"},slide_speed_full);
					$("#r_t").stop().animate({"marginLeft": "-432px"},slide_speed_full);
					$("#r_b").stop().animate({"marginTop": "0px"},slide_speed_full);
					
				}
	
	
	//////////////////////////////
	//small slider
	$("#lich_show").unbind('mouseenter')
					  .bind('mouseenter',m_enter)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave)					  
					  
				
				function m_enter(){
					//var $this 	= $(this);
					
					clearTimeout(menu_time);
					$("#corp_div").fadeOut("fast");
					menu_time 	= setTimeout(function(){
					$("#lich_div").fadeIn("fast");
					},timer);
					
					
				}
				
				function m_leave(){					
					clearTimeout(menu_time);
					menu_time 	= setTimeout(function(){
					$("#lich_div").fadeOut("fast");
					},timer);								
				}
	
	$("#corp_show").unbind('mouseenter')
					  .bind('mouseenter',m_enter2)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave2)					  
					  
				
				function m_enter2(){
					//var $this 	= $(this);
					
					clearTimeout(menu_time2);
					menu_time2 	= setTimeout(function(){
					$("#corp_div").fadeIn("fast");
					$("#lich_div").fadeOut("fast");
					},timer);
					
				}
				
				function m_leave2(){					
					clearTimeout(menu_time2);
					menu_time2 	= setTimeout(function(){
					$("#corp_div").fadeOut("fast");
					},timer);								
				}
				
	$("#club").unbind('mouseenter')
					  .bind('mouseenter',m_enter3)
				      .unbind('mouseleave')
					  .bind('mouseleave',m_leave3)					  
					  
				
				function m_enter3(){
					//var $this 	= $(this);
					
					clearTimeout(menu_time3);
					menu_time3 	= setTimeout(function(){
					$("#club_div").fadeIn("fast");
					$("#corp_div").fadeOut("fast");
					$("#lich_div").fadeOut("fast");
					},timer);
					
				}
				
				function m_leave3(){					
					clearTimeout(menu_time3);
					menu_time3 	= setTimeout(function(){
					$("#club_div").fadeOut("fast");
					},timer);								
				}
	
	
	
	
	
});

function show_photo(photo_name){	
	photo = "<img src='image/soc/big/"+ photo_name +"'/>";
	$("#big_photo").html(photo);
	return false;
}

function move_left_photo(){	
	var margin = parseInt($("#photo_container").css("marginLeft"));	
	var new_margin = margin + 114;	
	    if (new_margin <= 0) {
			$("#photo_container").css("marginLeft", new_margin + "px");
		}
}

function move_right_photo(num_photo){
	var margin = parseInt($("#photo_container").css("marginLeft"));
	var new_margin = margin - 114;
	var full_margin = -((114 * num_photo) - 342);
	if (new_margin > full_margin) {
		$("#photo_container").css("marginLeft", new_margin + "px");
	}
}

function clear_input(id, value){
	var source_value = $("#" + id).val();
	if(source_value == value){$("#" + id).val("");}
	if(source_value == ""){$("#" + id).val(value);}
}

function show_added_menu(show_id, button_id){
	var selector = $("#"+show_id);
	var button = $("#"+button_id);
	if(!selector.is(":visible")){
		close_menu();	
		selector.show();
		button.removeClass("bottom_link_close").removeClass("bottom_link").addClass("bottom_link_close")
	}
	else{
		close_menu();
	}
}

function close_menu(){
	for(var i=0; i< selector_id.length; i++){
		var selector_close = $("#"+selector_id[i]);
		var button_close = $("#"+button_id[i]);
		selector_close.hide();
		button_close.removeClass("bottom_link_close").removeClass("bottom_link").addClass("bottom_link")
		
	}
}

function navigation_menu(top_link_name, top_link, page_id, lang, num_link, num_id, link, try_page_id){
	var num_select_navigation = parseInt($("#num_select_navigation").html());
	if (num_select_navigation != page_id) {
		var start_height = $("#include_table").height();
		$("#nav_content").css("height",start_height)
		$("#main_link_head").removeClass("main_link_head").removeClass("main_link_head_nobord").addClass("main_link_head_nobord");
		$("#progress_bar").show().animate({"width":"977px"}, 1000);
		$.post("modul/bottom/nav_block.php", {top_link_name: top_link_name,top_link: top_link,page_id: page_id,lang: lang,link: link,try_page_id: try_page_id}, function(data){
			//top link decorate
			$("#progress_bar").stop().hide().css("width",0);
			$("#main_link_head").removeClass("main_link_head").removeClass("main_link_head_nobord").addClass("main_link_head");
			for (var i = 0; i <= num_link; i++) {
				$("#f_l_" + i).removeClass("activ");
				if (i == num_id) {$("#f_l_" + i).addClass("activ");}
			}			
			$("#num_select_navigation").html(page_id)
			$("#nav_content").html(data);
			var finish_height = $("#include_table").height();
			
			$("#include_table").hide();
			$("#nav_content").animate({"height": finish_height}, 300, function(){$("#include_table").show();});
		});
	}
}

function start_y_menu(num_s){	
	var step_m = 0;	
	if(num_s > 1){
		$(".right_slide_m").show();
	}
	for(i = 0; i < num_s; i++){
		var elem = $("#m_t_" + i);
		elem.css("marginLeft", step_m + "px");
		step_m += step;
	}
}

function start_prod_menu(num_s){	
	var step_p = 10;	
	var step = 165;
	if(num_s > 1){
		$(".bottom_slide_prod").show();
	}
	for(i = 0; i < num_s; i++){		
		var elem = $("#pn_" + i);
		elem.css("marginTop", step_p + "px");
		step_p += step;
	}
}


