$(document).ready(function(){
    $('#showbank').hide();
    $('#showcollection').hide();
    $('#btnPaypal').hide();
    
    /*read attribute value for 3 payment methods*/
    if($('#prebanktransfer_id').attr('checked')===true) {
        $('#showbank').show();
    }

    if($('#payondelevary_id').attr('checked')===true) {
        $('#showcollection').show();
        $('#shipping_address').hide();
    }
    

    $('#copybilladd').change(function() {
        var user_addr     = $('#user_addr').attr('value');
        var user_city     = $('#user_city').attr('value');
        var user_state     = $('#user_state').attr('value');
        var user_country     = $('#user_country').attr('value');
        var user_postalcode     = $('#user_postalcode').attr('value');
    
        $('#buser_add1').val(user_addr);
        $('#buser_city').val(user_city);
        $('#buser_state').val(user_state);
        $('#buser_country').val(user_country);
        $('#buser_postalcode').val(user_postalcode);        
    });
    
    $('#prebanktransfer').change(function() {
        $('#showcollection').hide();
        $('#showbank').show();    
    });
    
    $('#payondelivery').change(function() {
        $('#showbank').hide();
        $('#showcollection').show();
        $('#shipping_address').hide();
    });
    
    $('#paypal').change(function() {
        $('#showbank').hide();
        $('#showcollection').hide();    
    });



    // CONTACT FORM 
	$(".cf-open").click(function(){
		$(".cf").fadeIn();
		return false;
	});
	$(".cf-close").click(function(){
		$(".cf").fadeOut();
		return false;
	});
	
	// TABLES
	$(".art-detail tr td:first-child").addClass("td1");
	$(".art-detail tr td:nth-child(2)").addClass("td2");
	
	// SQUARE
	$(".square:nth-child(3n+2)").addClass("square-middle");

     //FOR IMAGE PROFILE
     $('.profile img').each(function() {
        var maxWidth = 230; // Max width for the image
        var maxHeight = 500;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height

        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }

        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
	
});
