// JavaScript Document
jQuery(function()
{
	
	 
	 //for cookie stuffs
	  
		
		var shownAlready = getCookie('shownAlready');
		//alert(shownAlready);
		if(shownAlready=='no' || shownAlready=='')
		{   // alert('inside');
			
			 $('#jeremypopup').fadeIn(600);
				//setCookie('shownAlready','yes',30);
			
			//setCookie('shownAlready','yes',30);
			
		}
		
		
    
	$('#askjeremypopup,#askjeremypopup_two,#askjeremypopup_three,#askjeremypopup_four,#askjeremypopup_five').click(function(){
		$('#jeremypopup').fadeIn(600);
		//$('#contactwrapper').animate({marginTop: "0px"}, 600 );
		//setCookie('shownAlready','yes',30);
		return false;
	});
	
	$('#popupclose').click(function(){
		$('#jeremypopup').fadeOut(600);
		setCookie('shownAlready','yes',30);
		return false;
	});
	
	
});
//safari and chrome can't get height of image wihout loading it so 
$(window).load(bgInit);

//initiate the background 
function bgInit()
{
	jQuery('#background img').each(function()
	{
		iw = jQuery(this).width();			// image width
		ih = jQuery(this).height();			// image height
		var pw = jQuery(window).width();	// page width
		var ph = jQuery(window).height();	// page height
		//alert(jQuery('#background img:first').width());
		resizeBg(iw, ih, pw, ph,jQuery(this));
	});
}
// resize on window resize
jQuery(window).resize(function() {
  bgInit();
});
//resize background image
function resizeBg(iw, ih, pw, ph,img) { //args: image width, image height, page width, page height */
  //alert(iw+' '+ih+' '+pw+' '+ph);
  if (ih > ph && iw < pw) {
    img.css('width', pw+'px');
    img.css('height', ((ih*pw)/iw)+'px');
  } else if (ih < ph && iw > pw) {
    img.css('height', ph+'px');
    img.css('width', ((ph*iw)/ih)+'px');
  } else if (ih > ph && iw > pw) {
    if (((ih*pw)/iw) >= ph) {
      img.css('width', pw+'px');
      img.css('height', ((ih*pw)/iw)+'px');
    } else {
      img.css('height', ph+'px');
      img.css('width', ((ph*iw)/ih)+'px');
    }
  } else if (ih < ph && iw < pw) {
    if (((ih*pw)/iw) >= ph) {
      img.css('width', pw+'px');
      img.css('height', ((ih*pw)/iw)+'px');
    } else {
      //alert((ph*iw));
	  img.css('height', ph+'px');
      img.css('width', ((ph*iw)/ih)+'px');
    }
  }
}

function setCookie(c_name,value,expiredays)
		{
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
		}
		
		function getCookie(c_name)
		{
			if (document.cookie.length>0)
			  {
			  c_start=document.cookie.indexOf(c_name + "=");
			  if (c_start!=-1)
				{
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
				}
			  }
			return "";
		}
