$(document).ready(function() {
    
    //$('#dPopUp, #iPopUp').fadeIn(1000);
    $('#dPopUp, #iPopUp').hide();
    $('#onlinetakvim').click(function() { 	
		// Modal Background
		var box = document.createElement("div");
		$(box).css({
			position: "fixed",
			left: '0px',
			right: '0px',
			top: '0px',
			bottom: '0px',
			backgroundColor: '#000000',
			opacity: 0.7,
			zIndex: 10000,
			cursor: "pointer"
		})
		.attr({ id: 'dPopUp', title: "Kapatmak için tıklayınız" });


		// Image
		var img = document.createElement("img");
		$(img).css({
			position: 'fixed',
			//        top: ((height - parseInt(img_h)) / 2 + 'px'),
			//        left: ((width - parseInt(img_w)) / 2 + 'px'),
			//        height: img_h,
			//        width: img_w,
			zIndex: 10001,
			cursor: 'pointer'
		})
			.attr({
				id: 'iPopUp',
				title: "Kapatmak için tıklayınız" //,
				//src: (screen.width <= 1024) ? '/resources/images/KPopup_k.jpg' : '/resources/images/KPopup.jpg'
			});
		

		var height = $(window).height();
		var width = $(document.body).width();

		if (screen.width <= 1024) {
			var height = $(window).height();

			var ih = 600;
			var iw = 500;

			if (height < ih) {
				ih = height - 40;
				iw = Math.round(ih * 500 / 600.0);
			}

			$(img)
				.attr('src', '/resources/images/KPopup_k.jpg')
				.css({
					top: ((height - ih) / 2 + 'px'),
					left: ((width - iw) / 2 + 'px'),
					height: ih + 'px',
					width: iw + 'px'
				});
		}
		else {
			$(img)
				.attr('src', '/resources/images/KPopup.jpg')
				.css({
					top: ((height - 700) / 2 + 'px'),
					left: ((width - 600) / 2 + 'px'),
					height: '700px',
					width: '600px'
				});
		}


		$(document.body).append(box).append(img);
		//document.body.appendChild(box);
		//document.body.appendChild(img);
		$('#dPopUp, #iPopUp').click(function() { $('#dPopUp, #iPopUp').fadeOut(1000, function(){ $('#dPopUp, #iPopUp').remove(); }); });
		
		//$('#dPopUp, #iPopUp').css({position: "fixed"}).fadeIn(1000); 
		return false;
	});
    //$('#dPopUp').animate({opacity: 0.7 }, 1000, 'linear', function(){$('#iPopUp').animate({opacity: 1}, 500, 'linear');});
});
