function resizeImg(img, w, h) {
	var imgw = img.width;
	var imgh = img.height;
	var ratio = imgw/w;
	
	if (h > imgh/ratio ){
		img.style.width  = 'auto';
		img.style.height  = h+'px';
	} else {
		img.style.width  = w + 'px';
		img.style.height  = 'auto';
	}
	
}

function resizeImage() {

    var image_width   = document.getElementById("watermarkImage").width;
    var image_height  = document.getElementById("watermarkImage").height;

    if (image_height > image_width) {
        document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
        document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
    } else {
        document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
        document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
    }

}

function resizeImage() {

    var WIDTH_NORMAL = "550px";
    var HEIGHT_NORMAL = "366px";

	var image_width   = document.getElementById("watermarkImage").width;
	var image_height  = document.getElementById("watermarkImage").height;

	if (image_height > image_width )
	{

	  if(image_height < 400){
	    document.getElementById("watermarkImage").style.width  = "auto";
	    document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
	  }
	  else
	  {
	    document.getElementById("watermarkImage").style.width  = "auto";
	    document.getElementById("watermarkImage").style.height = WIDTH_NORMAL;
	  }

	}
	else
	{

	 if(image_width < 600){
	   document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
	   document.getElementById("watermarkImage").style.height = "auto";
	 }
     else
     {
       document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
	   document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
     }
	}
}

function resizeImage300() {

    var WIDTH_NORMAL = "300px";
    var HEIGHT_NORMAL = "165px";

	var image_width   = document.getElementById("watermarkImage").width;
	var image_height  = document.getElementById("watermarkImage").height;

	if (image_height > image_width )
	{

	  if(image_height < 165){
	    document.getElementById("watermarkImage").style.width  = "auto";
	    document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
	  }
	  else
	  {
	    document.getElementById("watermarkImage").style.width  = "auto";
	    document.getElementById("watermarkImage").style.height = WIDTH_NORMAL;
	  }

	}
	else
	{

	 if(image_width < 300){
	   document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
	   document.getElementById("watermarkImage").style.height = "auto";
	 }
     else
     {
       document.getElementById("watermarkImage").style.width  = WIDTH_NORMAL;
	   document.getElementById("watermarkImage").style.height = HEIGHT_NORMAL;
     }
	}
}

function resizeImageSmall(image)
{

	var image_width   = image.width;
	var image_height  = image.height;

	if (image_height > image_width )
	{
		
	  if(image_height < 135){
		  image.style.width  = "180px";
		  image.style.height = "auto";
	  }
	  else
	  {
		  image.style.width  = "180px";
		  image.style.height = "auto";
	  }	  
		
	  }
	else
	{
		
	 if(image_width < 180){
		 image.style.width  = "180px";
		 image.style.height = "auto";
	 }
	 else if(image_width == 180){
		 image.style.width  = "180px";
		 image.style.height = "auto";
	 }
     else
     {
    	 if(image_width/image_height > 1.34){
    		 image.style.width  = "auto";
        	 image.style.height = "135px";
    	 }
    	 if(image_width/image_height < 1.34){
    	     image.style.width  = "180px";
    	     image.style.height = "auto";
    	 }
      }
	}
}

function resizeImageSmaller(image)
{
    /* 120 x 90  */
	var image_width   = image.width;
	var image_height  = image.height;

	if (image_height > image_width )
	{
		
	  if(image_height < 90){
		  image.style.width  = "120px";
		  image.style.height = "auto";
	  }
	  else
	  {
		  image.style.width  = "120px";
		  image.style.height = "auto";
	  }	  
		
	}
	else
	{
		
	 if(image_width < 120){
		 image.style.width  = "120px";
		 image.style.height = "auto";
	 }
     else
     {
    	 if(image_width/image_height > 1.34){
    		 image.style.width  = "auto";
        	 image.style.height = "90px";
    	 }
    	 if(image_width/image_height < 1.34){
    	     image.style.width  = "120px";
    	     image.style.height = "auto";
    	 }
     }
	}
}


function resizePhotoOfTheDay()
{
    /* 210 x 157  */
	var image_width   = document.getElementById("imagephotoOfTheDay").width;
	var image_height  = document.getElementById("imagephotoOfTheDay").height;

	if (image_height > image_width )
	{
		
	  if(image_height < 135){
	    document.getElementById("imagephotoOfTheDay").style.width  = "180px";
	    document.getElementById("imagephotoOfTheDay").style.height = "auto";
	  }
	  else
	  {
	    document.getElementById("imagephotoOfTheDay").style.width  = "180px";
	    document.getElementById("imagephotoOfTheDay").style.height = "auto";
	  }	  
		
	}
	else
	{
		
	 if(image_width < 180){
	   document.getElementById("imagephotoOfTheDay").style.width  = "180px";
	   document.getElementById("imagephotoOfTheDay").style.height = "auto";
	 }
     else
     {
    	 if(image_width/image_height > 1.34){
    		 document.getElementById("imagephotoOfTheDay").style.width  = "auto";
    		 document.getElementById("imagephotoOfTheDay").style.height = "135px";
    	 }
    	 if(image_width/image_height < 1.34){
    		 document.getElementById("imagephotoOfTheDay").style.width  = "180px";
    		 document.getElementById("imagephotoOfTheDay").style.height = "auto";
    	 }
      
     }
	}
}

function resizeImageThumbnail(image)
{

	var image_width   = image.width;
	var image_height  = image.height;

	if (image_height > image_width )
	{
		
	  if(image_height < 45){
		  image.style.width  = "60px";
		  image.style.height = "auto";
	  }
	  else
	  {
		  image.style.width  = "60px";
		  image.style.height = "auto";
	  }	  
		
	  }
	else
	{
		
	 if(image_width < 60){
		 image.style.width  = "60px";
		 image.style.height = "auto";
	 }
     else
     {
    	 image.style.width  = "60px";
    	 image.style.height = "45px";
      }
	}
}
function resizeImageCustom(image, newWidth, newHeight)
{
	var w = newWidth;
	var h = newHeight;
	var d = (w/h);
	var r = roundNumber(d, 1);
	
	var image_width   = image.width;
	var image_height  = image.height;

	if (image_height > image_width )
	{
		
	  if(image_height < newHeight){
		  image.style.width  = newWidth+"px";
		  image.style.height = "auto";
	  }
	  else
	  {
		  image.style.width  = newWidth+"px";
		  image.style.height = "auto";
	  }	  
		
	  }
	else
	{
		
	 if(image_width < newWidth){
		 image.style.width  = newWidth+"px";
		 image.style.height = "auto";
	 }
	 else if(image_width == newWidth){
		 image.style.width  = newWidth+"px";
		 image.style.height = "auto";
	 }
     else
     {
    	 if(image_width/image_height > r){
    		 image.style.width  = "auto";
        	 image.style.height = newHeight+"px";
    	 }
    	 if(image_width/image_height < r){
    	     image.style.width  = newWidth+"px";
    	     image.style.height = "auto";
    	 }
      }
	}
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
	  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	  return newnumber; 
	}