jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '50%', 
            zIndex:        '99'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

function toggle_right_menu(obj){
	$(".select").hide();
	$(obj).next("div").slideToggle('normal',function(){$(".select").show(); });
	if($(obj).attr("class")=="right_menu_over"){
		//alert('sad');
		$(obj).addClass("right_menu_down");
		$(obj).removeClass("right_menu_over");		
	}else{
		if($(obj).attr("class")=="right_menu_down"){
			//alert('sad');
			$(obj).addClass("right_menu_over");
			$(obj).removeClass("right_menu_down");		
		}
	}
}
function after_send(){
	setTimeout("$('#form_rent')[0].reset(); $('#rent').trigger('click'); $('.select').html(select_val); $('#rent').attr('class','right_menu');",3000);
	
}

function submit_rent_form(){ if(jQuery('#form_rent').validationEngine('validate')) { serializes_form=jQuery('#form_rent').serialize(); $("#status").load("jax/rent.jax.php?"+serializes_form, {}); }}

function submit_newsletter_form(){ if(jQuery('#form_rent').validationEngine('validate')) { serializes_form=jQuery('#form_rent').serialize(); $("#status").load("jax/rent.jax.php?"+serializes_form, {}); }}
$(document).ready(function(){
		$("#top_news").hover(
		  function () {
			 //alert( $(this).children(".top_news_content").css("width"));
			if($(this).children(".top_news_content").css("width")=='0px'){
				//alert('asd');
				$(".top_news_content").animate({
					"margin-left": '-194',
					"width": '194'
				});
			}
		  }, 
		  function () {
				$(".top_news_content").animate({
					"margin-left": '0',
					"width": '0'
				});
			  //$(".top_news_content").hide("slide", { direction: "right" }, 1000);
			//$(this).find("span:last").remove();
		  }
		);		

		browser='other';
		if(navigator.userAgent.indexOf('MSIE')!=-1) { browser="ie"; height_difference=8;}
		if(navigator.userAgent.indexOf('Firefox')!=-1) { browser="ff"; height_difference=6;}
		if(navigator.userAgent.indexOf('Chrome')!=-1) { browser="chrome"; height_difference=8;}

		/***footer to bottom***/
		//console.dir(navigator);	
		
		footer_to_bottom();		
		shadow_load();
		$(window).bind("resize", function(){
			footer_to_bottom();
			shadow_load();
		})
		/***END footer to bottom***/

	
		
		jQuery('#form_rent').validationEngine();
		from_date=$( "#From_date" ).datepicker({dateFormat : 'dd.mm.yy', onSelect: function(){jQuery('#form_rent').validationEngine('validateField', '#From_date'); }});
		to_date=$( "#To_date" ).datepicker( {dateFormat : 'dd.mm.yy',onSelect: function(){jQuery('#form_rent').validationEngine('validateField', '#To_date'); }});
		$("a.lightbox").fancybox({'titlePosition': 'over'});
		$("#load_data_address").fancybox({'titlePosition': 'over',onCleanup: function(){ $('#form_Vacation').validationEngine('hideAll');}});
		$("#load_data_address_home").fancybox({'titlePosition': 'over',onCleanup: function(){ $('#form_Home').validationEngine('hideAll');}});
		$(".yellow_menu_bottom").each(
			function(){
				tmp=($(this).width()+9)/2;
				
				$(this).parent().parent().children('.parent_for_width').children(".yellow_menu_top").width(tmp+1);
			}
		);
		$(".right_menu").hover(
		  function () {
		  	if($(this).attr("class")!="right_menu_down"){
				$(this).addClass("right_menu_over");
				$(this).removeClass("right_menu");
			}
		  },
		  function () {
			  //alert($(this).attr("class"));
			if($(this).attr("class")!="right_menu_down"){
				$(this).addClass("right_menu");
				$(this).removeClass("right_menu_over");
			}
		  }
		);
		$(".green_menu_c").hover(
		  function () {
			$(this).children(".green_submenus").show();
		  },
		  function () {
			$(".green_submenus").hide();
		  }
		);	
	
		$(".green_menu").hover(
		  function () {
		  	$(this).parent().parent().next("td.green_menu_separator").addClass("green_menu_separator_over");
		  	$(this).parent().parent().prev("td.green_menu_separator").addClass("green_menu_separator_over");
		  	$(this).parent().parent().next("td.green_menu_separator").removeClass("green_menu_separator");
		  	$(this).parent().parent().prev("td.green_menu_separator").removeClass("green_menu_separator");
		  },
		  function () {
			$(".green_menu_separator_over").addClass("green_menu_separator");
			$(".green_menu_separator_over").removeClass("green_menu_separator_over");
		  }
		);	
			
		$(".yellow_menu").hover(
		  function () {
			$(this).children().children(".yellow_submenus").show();
			$(this).addClass("yellow_menu_over");
			$(this).removeClass("yellow_menu");
		  	$(this).prev("div").children(".yellow_menu_separator").addClass("yellow_menu_separator_over")
		  	$(this).prev("div").children(".yellow_menu_separator").removeClass("yellow_menu_separator")
		  },
		  function () {
			$(this).addClass("yellow_menu");
			$(this).removeClass("yellow_menu_over");
			$(".yellow_menu_separator_over").addClass("yellow_menu_separator");
			$(".yellow_menu_separator_over").removeClass("yellow_menu_separator_over");
			$(".yellow_submenus").hide();
		  }
		);	
		$(".yellow_menu_selected").hover(
		  function () {
			$(this).children().children(".yellow_submenus").show();
		  },
		  function () {
			$(".yellow_submenus").hide();
		  }
		);	
	$("#slideshow").carouFredSel({
	        items               : 1,
			width				: 960,
			height				: 357,
	        direction           : "left",
			prev				: "#ss_arrow_left",
			next				: "#ss_arrow_right",
	        scroll : {
	            items           : 1,
	            effect          : "easeOutBounce",
	            duration        : 1000,                        
	            pauseOnHover    : true
	        }                  
    });	
	sum_width=0;
	$(".set_width").each(function(){
			$(this).width($(this).children().children(".sponsors_img").width()+40);
			sum_width+=$(this).children().children(".sponsors_img").width()+40;
		}
	)
	$("#sponsors").width(1500);
	$("#sponsors").height(70);

});	
/**
* Position footer at the bottom of the page
*/
function load_sponsors(){
	//alert('sa');
	sum_width=0;
	$(".set_width").each(function(){
			$(this).width($(this).children().children(".sponsors_img").width()+40);
			sum_width+=$(this).children().children(".sponsors_img").width()+40;
		}
	)
	//$(".set_width").width($(this).children().children(".sponsors_img").width()+40);
	$("#sponsors").carouFredSel({
	        items               : {
				width:"variable",
				minimum:"4"
			},
			width				: 832,			
			height				: 70,
			align				: "center",
	        direction           : "left",
			prev				: ".sponsors_left",
			next				: ".sponsors_right",
	        scroll : {
	            items           : 1,
	            duration        : 1000,                        
	            pauseOnHover    : true
	        }                  
    });	
	$("#sponsors").width(1500);
	$("#sponsors").height(70);
}
function sponsors_center(){
if(sum_width<832){
	//alert(sum_width)
	$("#sponsors").css("padding-left" , (832-sum_width)/2 );
}
}
function footer_to_bottom(){
	var winheight = $(window).height();	
	main_container_height=$("#main_container").height();
	footer_height=$("#footer_main_container").height();
	if ((main_container_height+footer_height)<winheight) $("#empty_container").height(winheight-main_container_height-footer_height-height_difference);
}
preload_images();
function shadow_load(){
		body_height=$("#body").height();
		//alert(body_height);
		shadow_left_inner_height=590;
		shadow_middle_height=0;
		if(body_height>1180) {shadow_middle_height=body_height-1180;
		}else{
			shadow_left_inner_height=shadow_left_inner_height-(1180-body_height)/2-1;
			shadow_left_inner_height=Math.round(shadow_left_inner_height);
		}
		$(".shadow_left_top").height(shadow_left_inner_height);
		$(".shadow_left_bottom").height(shadow_left_inner_height);
		$(".shadow_right_top").height(shadow_left_inner_height);
		$(".shadow_right_bottom").height(shadow_left_inner_height);
		$(".shadow_left").height(shadow_middle_height);
		$(".shadow_right").height(shadow_middle_height);

}
function preload_images(){
	pic1= new Image(1,39); 
	pic1.src="images/yellow_menu_bottom_over.png"; 
	pic2= new Image(31,25); 
	pic2.src="images/yellow_menu_incision_over.png"; 
	pic3= new Image(2,64); 
	pic3.src="images/yellow_menu_separator_over.png"; 
	pic4= new Image(1,25); 
	pic4.src="images/yellow_menu_top_over.png"; 
	pic5= new Image(240,34); 
	pic5.src="images/right_menu_over.png"; 
	pic5= new Image(240,34); 
	pic5.src="images/right_menu_down.png"; 
	pic5= new Image(1,36); 
	pic5.src="images/menu_bg_over.jpg"; 
}


