$(function()
{
	
	$("#menupane a.menu_head").click(function()
    {
	
		$(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
       	
	});
	$("#menupane a.menu_head_link").click(function()
    {
		$(this).siblings("div.menu_body").slideUp("slow");
       	
	});
	
	$(window).bind('resize',function(e){
	changeBgImageDim();
						
					});
	getImageDim				= function($i){
	
					var $img     = new Image();
					$img.src     = $i.attr('src');
							
					var w_w	= $(window).width();
					var w_h	= $(window).height();
					//alert("called 2--"+w_h);
					var r_w	= w_h / w_w;
					var i_w	= $img.width;
					var i_h	= $img.height;
					var r_i	= i_h / i_w;
					var new_w,new_h,new_left,new_top;
							
					if(r_w > r_i){
						new_h	= w_h;
						new_w	= w_h / r_i;
					}
					else{
						new_h	= w_w * r_i;
						new_w	= w_w;
					}
							
					return {
						width	: new_w,
						height	: new_h,
						left	: (w_w - new_w) / 2,
						top		: (w_h - new_h) / 2
					};
							
				}
	var changeBgImageDim	= function() {
	//alert("called 1");
	$bg_image = $("#imageBG");
	
					var dim	= getImageDim($bg_image);
					//set the returned values and show the image
					$bg_image.css({
						width	: dim.width + 'px',
						height	: dim.height + 'px',
						left	: dim.left + 'px',
						top		: dim.top + 'px'
					});
					
				}
				//changeBgImageDim();
	var preloadImage = function(){
	$bg_image = $("#imageBG");
	var img = new Image();
        $(img).load(function () {
		
		   $bg_image.css({
		   display:'block'
		   });
		   
		   $("#bg1").css({
		   display:'none'
		   });
			changeBgImageDim();
			$("#myLoader").removeClass('loader');
			
        }).error(function () {
            // notify the user that the image could not be loaded
        }).attr('src', $bg_image.attr('src'));
	}
	preloadImage();
	
});
