$(function(){

	var screenWidth = $(window).width();
	var screenHeight = $(window).height();

	var setModalPostion = function(w, h){
		if(screenWidth <= 700){
			$('.detail-modal').css({
				"left": 0,
				"top": 0
			});
		}else{
			$('.detail-modal').css({
				"left": ( ( screenWidth / 2) - (w / 2) ),
				"top": ( (screenHeight / 2) - (h / 2) )
			});
		}
	};

	var setModalSize = function(w, h){
		if(screenWidth <= 700){
			$('.detail-modal').css({
				"width": "100%",
				"height": "100%"
			});
		}else{
			$('.detail-modal').css({
				"width": w,
				"height": h
			});
		}
	};

	var setBodyOff = function(){
		$('body').css("overflow", "hidden");
	};

	var setBodyOn = function(){
		$('body').css("overflow", "auto");	
	};

	var closeModal = function(ev){
		ev.preventDefault();
		$('.detail-modal').remove();
		$('.detail-modal-mascara').remove();
		setBodyOn();
	};

	var showFrameModal = function(u,w,h){
		var frame = '<div class="detail-modal-mascara"></div><div class="detail-modal"><iframe src="' + u + '" border="0" frameborder="0"></iframe><a href="#" class="close-detail-modal"><i class="fa fa-times"></i></a></div>';
		$('body').append(frame);
		setModalSize(w, h);
		setModalPostion(w, h);
		setBodyOff();
		$('.detail-modal').show();
	};

	$(document).delegate('.detail-modal-mascara', 'click', closeModal);
	$(document).delegate('.close-detail-modal', 'click', closeModal);

	$('.detalhes').click(function(event) {
		event.preventDefault();
		var url = $(this).attr('href');
		var Width = $(this).attr('data-width') ? $(this).attr('data-width') : 500;
		var Height = $(this).attr('data-height') ? $(this).attr('data-height') : 400;
		showFrameModal(url, Width, Height);
	});

});