// Resize iframe plugin
// http://designsandbox.abasoft.co.uk/demos/iframes.asp
(function($) {
    $.fn.extend({
        resize: function(fixedheight)	{
            return this.each(function() {
                id = $(this).attr('id');
                el = $(document.getElementById(id).contentWindow.document.body);
                height = $(el).height();
				try	{
					height += parseInt($(el).css('margin-top').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('margin-bottom').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('padding-top').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('padding-bottom').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).find(':first-child').css('padding-top').replace(/(px)|(auto)/gi, ""));
					height += parseInt($(el).find(':first-child').css('margin-top').replace(/(px)|(auto)/gi, "")) + 3;
					height += parseInt($(el).find(':last-child').css('padding-bottom').replace(/(px)|(auto)/gi, ""));
					height += parseInt($(el).find(':last-child').css('margin-bottom').replace(/(px)|(auto)/gi, "")) + 3;
				}catch(e){}
				fixedheight ? $(this).css('height', fixedheight) : $(this).css('height', height);
            });
        },
        resizeOnLoad: function(onComplete) {
            return this.each(function() {
                $(this).load(function()	{
                    $(this).resize();
					if($.isFunction(onComplete))	onComplete();
                });
            });
        },
        getIframeHeight: function()	{
            maxheight = 0;
            this.each(function()	{
                id = $(this).attr('id');
                el = $(document.getElementById(id).contentWindow.document.body);
                height = $(el).height();
				try	{
					height += parseInt($(el).css('margin-top').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('margin-bottom').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('padding-top').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).css('padding-bottom').replace(/(px)|(auto)/gi, "") || 0);
					height += parseInt($(el).find(':first-child').css('padding-top').replace(/(px)|(auto)/gi, ""));
					height += parseInt($(el).find(':first-child').css('margin-top').replace(/(px)|(auto)/gi, "")) + 3;
					height += parseInt($(el).find(':last-child').css('padding-bottom').replace(/(px)|(auto)/gi, ""));
					height += parseInt($(el).find(':last-child').css('margin-bottom').replace(/(px)|(auto)/gi, "")) + 3;
				}catch(e){}
                if(height > maxheight)	maxheight = height;
            });
            return maxheight;	
        }
    });
})(jQuery);

function resizeIframes(filter)	{
	$(filter || 'iframe').resize();
}

function resizeRegisterPanel()	{
	var iframeheight = $('#register_iframe').getIframeHeight();
	$('#my_account_register').css('border-bottom-width', iframeheight+ 40);
	$('.my_account_register_content').css('height', iframeheight+ 30);
	$('#register_iframe').css('height', iframeheight+ 15);
}

function resizeRegisterThickbox()	{
	var iframeheight = $('#TB_iframeContent').getIframeHeight();
	$('#TB_iframeContent').css('height', iframeheight + 25);
	$('#TB_window').css('height', iframeheight + 45);
	var margin = parseInt((iframeheight / 2), 10);
	margin = -margin;
	$("#TB_window").css('margin-top', margin);
}

function resizeLoginPanel()	{
	var iframeheight = $('#login_iframe').getIframeHeight();
	if(iframeheight > 1000)	iframeheight = 147;
	$('#my_account_login').css('border-bottom-width', iframeheight+ 40);
	$('.my_account_login_content').css('height', iframeheight+ 30);
	$('#login_iframe').css('height', iframeheight+ 15);
}
