// JavaScript Document

//Resize image automatically
function ResizeImage(img, mWidth, mHeight){
    var image=new Image();
    image.src=img.src;
   
  var oldW = image.width;
  var oldH = image.height;
 
    
    if(image.width > 0 && image.height > 0){
        if(image.width/image.height >= mWidth/mHeight){
            if(image.width > mWidth){ 
        
                img.width = mWidth;
                img.height = (image.height * mWidth)/image.width;
            }else{
       
                img.width=image.width; 
                img.height=image.height;
            }
        }else{
            if(image.height>mHeight){
          
                img.height = mHeight;
                img.width = (image.width * mHeight)/image.height; 
            }else{
         
                img.width=image.width; 
                img.height = image.height;
            }
        }
    }
}

//fix height affected by css:absolute
/*$(document).ready(function(){
	var childElements = $("#content > *");
	var maxHeight=0;
	for (var i = 0; i < childElements.length; i++) {
		var j = $(childElements[i]).height();
		if (j > maxHeight)
		{
			maxHeight = j;
		}
	}
	$("#content").height(maxHeight);
});*/

//popup login dialog
$(document).ready(function(){
	$(".popup_login").fancybox({
		'frameWidth':450,
		'frameHeight':270,
		'hideOnContentClick': false,
		'overlayOpacity':0.6
	});
});

/*(function ($) {
	// VERTICALLY ALIGN FUNCTION
	$.fn.vAlign = function() {
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = (ph - ah) / 2;
			$(this).css('margin-top', mh);
		});
	};
})(jQuery);*/

//$(document).ready(function() {
//	$(".ad_img").vAlign();
//});