jQuery(document).ready(function() {

	var maskHeight = jQuery(document).height();
	var maskWidth = jQuery(document).width();
        var maskWidth = '100%';

	jQuery('#maskModal').css({
		'width' : '100%',
		'height' : maskHeight
	});

	var url = document.URL.split('=')[1];
	//alert(url);
	if (url != '' && url != undefined) {

	    if (jQuery('#maskModal').is(':visible')) {
			jQuery('#maskModal').hide();
		}

		var id = '#contentModal';
		var sizes = '820|780';

		newSizes = sizes.split('|');

		jQuery(id).css('width', newSizes[0]);
		jQuery(id).css('height', newSizes[1]);

		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(document).width();

		jQuery('#maskModal').css({
			'width' : '100%',
			'height' : maskHeight
		});

		isIE8 = IsIE8Browser();
		if (isIE8) {
			DD_roundies.addRule('#contentModal', '10px', false);
		}

		jQuery('#maskModal').fadeIn(200);		

		var winH = jQuery(window).height();
		var winW = jQuery(window).width();                                                                

		jQuery(id).css('margin-top',0);

		posTop = winH / 2 - jQuery(id).height() / 2;

		posScrollTop = document.documentElement.scrollTop;

		if(posScrollTop > 0){
			posicaoNaTela = document.documentElement.scrollTop -(jQuery(id).height() / 2);                
			jQuery(id).css('margin-top', posScrollTop);
		}

		if(posTop < 0)
			jQuery(id).css('top', '15px');
		else
			jQuery(id).css('top', winH / 2 - jQuery(id).height() / 2);

		jQuery(id).css('left', winW / 2 - jQuery(id).width() / 2);                                
                
		jQuery(id).fadeIn(200);

	    return false;
	}

	jQuery('a[name=modal]').live('click', function(e) {

		if (jQuery('#maskModal').is(':visible')) {
			jQuery('#maskModal').hide();
		}

		e.preventDefault();

		var id = jQuery(this).attr('href');
		var sizes = jQuery(this).attr('rel');

		newSizes = sizes.split('|');

		jQuery(id).css('width', newSizes[0]);
		jQuery(id).css('height', newSizes[1]);

		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(document).width();

		jQuery('#maskModal').css({
			'width' : '100%',
			'height' : maskHeight
		});

		isIE8 = IsIE8Browser();
		if (isIE8) {
			DD_roundies.addRule('#contentModal', '10px', false);
		}

		jQuery('#maskModal').fadeIn(200);		

		var winH = jQuery(window).height();
		var winW = jQuery(window).width();                                                                

		jQuery(id).css('margin-top',0);

		posTop = winH / 2 - jQuery(id).height() / 2;

		posScrollTop = document.documentElement.scrollTop;

		if(posScrollTop > 0){
			posicaoNaTela = document.documentElement.scrollTop -(jQuery(id).height() / 2);                
			jQuery(id).css('margin-top', posScrollTop);
		}

		if(posTop < 0)
			jQuery(id).css('top', '15px');
		else
			jQuery(id).css('top', winH / 2 - jQuery(id).height() / 2);

		jQuery(id).css('left', winW / 2 - jQuery(id).width() / 2);                                
                
		jQuery(id).fadeIn(200);

        return false;
                
	});

	// Botao fechar / voltar
	jQuery('.close').live('click', function() {
		jQuery('#maskModal, #contentModal').fadeOut('slow');
		return false;
	});

	jQuery('.back').live('click', function() {
		history.go(-1);
		return false;
	});

});

function GB_getPageScrollTop(){
    var h;
    if(self.pageYOffset){
        h = self.pageYoffset;
    }
    else {
        if(window.documentElement && window.documentElement.scrollTop || window.documentElement.scrollLeft){
            h = window.documentElement.scrollTop;
        }
        else {
            if(window.body){
                h = window.body.scrollTop;
            }
        }
    }
    
    return h;
}
