resizeImage = function(theSelector,origSizeW,origSizeH, borderVt, borderHz, maxWidth) {
	
	//console.log(theSelector, origSizeW,origSizeH);
	
	if ($(theSelector).size() > 0)
		{

		   //var borderVt=0; //value based on css style. bottom bar + padding of photoContain
		    //var borderHz=0; //value based on css style photoContain padding
		
		    $(theSelector).css("width", "auto").css("height", "auto"); // Remove existing CSS
		    $(theSelector).removeAttr("width").removeAttr("height"); // Remove HTML attributes   
		
		    //var origSizeW = 1000; //$(theSelector).width();
		    //var origSizeH = 625; //$(theSelector).height();
		    var ratioVt=(origSizeW/origSizeH);
		    var ratioHz=(origSizeH/origSizeW);
		    var winW = $(window).width();
		    var winH = $(window).height();
		    var screenSizeW=Math.round(winW-borderHz);
		    var screenSizeH=Math.round(winH-borderVt);
		    
		    if (maxWidth != 0 && screenSizeW > maxWidth)
		    {
		    	screenSizeW = maxWidth;
		    }
		    
		    if (origSizeW>=origSizeH){
		     var newHeight = Math.round(screenSizeW*ratioHz);
		     if (newHeight <= screenSizeH){
		      $(theSelector).css("width", screenSizeW); // Set new width
		      $(theSelector).css("height", newHeight);
		      }
		     else{
		    	 $(theSelector).css("height", screenSizeH);
		      }
		
		    }
		    else{
		    	$(theSelector).css("height", screenSizeH); // Set new height
		    }
		}
  };

// End of a function
  
resetColorbox = function() {
	// Start of colorbox stuff.
	//alert($('a[rel=gallerypic]').size());
	$('a[rel=gallerypic],a[rel=MMPic]').colorbox({
		  title:"Alli Battaglia Gallery   (Click to go to next pic, Hit esc or click outside picture to exit.)",
		  initialWidth:'400px',
		  initialHeight:'300px',
		  width:'800px',
		  height:'600px',
		  background_color:'black',
		  transition: 'elastic',
		  speed: 500,
		  current: "{current} of {total} photos"
		});
		
		
	// End of colorbox stuff.
};

// Declare a send function.

function send(datastr) {
	$.ajax( 
		{ 
			type: "POST", 
			url: "php/sendMail.php", 
			data: datastr, 
			cache: false, 
			success: function(html) 
				{ 
					$('#response').css('color', 'white');
					$('#response').fadeIn('slow');
					$('#response').html(html);
					setTimeout('$("#response").fadeOut("slow")',2000);
				}
		});
};


 
$(document).ready(function() {

	resetColorbox();	
	// Make sure cover page image fits without distortion.
	
	resizeImage('#coverImage',1000, 665,0,0,0);
	resizeImage('#contactImage', 1022,494,290,0,0);
	
	function doDelayed() {
		resizeImage('#coverImage',800, 665,0,0,0);
	};

	var resizeTimer;
	$(window).resize(function() {
	    clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(doDelayed, 200);
	});

	
	// resizeImage('#musicImage',2000, 1331); // We can't do this here because this page may not be loaded. We must call this in the callback of load for ajax
	
	$(window).resize(function() {
		resizeImage('#musicImage', 2000, 1331,290,0,500);
	});
	
	$(window).resize(function() {
		resizeImage('#contactImage', 1022,494,270,0,0); // Normally 290
	});
	
	
	$(window).resize(function() {
		resizeImage('#newsImage', 860, 447,290,0,0);
	});
	
	// Open a music window.
	
	
	//$.cookie("music", "yes"); 
	//if ($.cookie("music") === null)
	//	{
		//	$.cookie("music", "yes"); 
	//myWinRef = window.open('playsongs.html','alliMusicWin',
	//'left=20,top=20,width=200,height=50,toolbar=0,resizable=0');

			//window.open('playsongs.html');
	//	}
		
	//window.open('playsongs.html');
	
	$('#musicLink').removeClass('hiddenItem');
	
	//$('#coverNav ul li a').corner();
	
		
	
});
