/**
 * jQuery.fullBg
 * Version 1.0
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/
(function($){
		  $.fn.fullBg=function(){
			  var bgImg=$(this);
			  bgImg.addClass('fullBg');
			  function resizeImg(){
				  var imgwidth=bgImg.width();
				  var imgheight=bgImg.height();
				
				var uniwin = {
					width: window.innerWidth || document.documentElement.clientWidth
						|| document.body.offsetWidth,
					height: window.innerHeight || document.documentElement.clientHeight
						|| document.body.offsetHeight
				};
					
					
				 if(uniwin.width>= 1008) {
				  		var winwidth=uniwin.width;
				 }else{
					  	var winwidth=1008;
				  }
				  
				  if(uniwin.height>= 599) {
						var winheight=uniwin.height;  
				  }else{
					    var winheight=599;
				  }
				 
				  document.getElementById("ac_background").style.width=winwidth+'px';
				  document.getElementById("ac_background").style.height=winheight+'px';
				//  document.getElementById("tienisfondo").style.overflow='hidden';
				// document.getElementById("tienisfondo2").style.width=winwidth+'px';
				//  document.getElementById("tienisfondo2").style.height=winheight+'px';
				//  document.getElementById("tienisfondo2").style.overflow='hidden';
				  
			
				  var widthratio=winwidth/imgwidth;
				  var heightratio=winheight/imgheight;
				  var widthdiff=parseInt(heightratio*imgwidth);
				  var heightdiff=parseInt(widthratio*imgheight);
				  
				var realwidth;
				var realheight;
				  
				  if(heightdiff>winheight){
					  bgImg.css({width:winwidth+'px',height:heightdiff+'px'});
					  realwidth= winwidth;
						realheight= heightdiff;
					  //alert("Aimg size: " +winwidth+"px - " + heightdiff+"px");
					  // document.getElementById("debugger").innerHTML="widthratio: " +widthratio+"<br> heightratio:" + heightratio+"<br> widthdiff:" + widthdiff +"<br> heightdiff:" + heightdiff +"<br> winwidth:" + winwidth +"<br> winheight:" + winheight +" - "+ uniwin.height +"<br> imgwidth:" + imgwidth +"<br> imgheight:" + imgheight+"<br>A<br> realwidth:" + winwidth +"<br> realheight:" + heightdiff;
				  }else{
					  if(widthdiff<winwidth){
						
						 bgImg.css({width:widthdiff+'px',height:winheight+'px'});
						 realwidth= widthdiff;
						realheight= winheight;
						//alert("Cimg size: " +widthdiff+"px - " + winheight+"px");
						//document.getElementById("debugger").innerHTML="widthratio: " +widthratio+"<br> heightratio:" + heightratio+"<br> widthdiff:" + widthdiff +"<br> heightdiff:" + heightdiff +"<br> winwidth:" + winwidth +"<br> winheight:" + winheight +" - "+ uniwin.height +"<br> imgwidth:" + imgwidth +"<br> imgheight:" + imgheight+"<br>B<br> realwidth:" + widthdiff +"<br> realheight:" + winheight;
					  }
					  else
					  {
					  	bgImg.css({width:widthdiff+'px',height:winheight+'px'});  
						realwidth= widthdiff;
						realheight= winheight;
						 //alert("Bimg size: " +winwidth+"px - " + winheight+"px");
						 //document.getElementById("debugger").innerHTML="widthratio: " +widthratio+"<br> heightratio:" + heightratio+"<br> widthdiff:" + widthdiff +"<br> heightdiff:" + heightdiff +"<br> winwidth:" + winwidth +"<br> winheight:" + winheight +" - "+ uniwin.height +"<br> imgwidth:" + imgwidth +"<br> imgheight:" + imgheight+"<br>C<br> realwidth:" + widthdiff +"<br> realheight:" + winheight;
					  }
					 
				  }
				  var topA = (winheight / 2) - (realheight / 2);
				  var leftA = (winwidth / 2) - (realwidth / 2) ;
				  
				  bgImg.css({top:topA+'px',left:leftA+'px'});
				 
			   }
			 resizeImg();
			$(window).resize(function(){
				  resizeImg();
		    });
		};
})
(jQuery)
