﻿jQuery.fn.ie6fix = function() {
	return this.each(function() {
		var method = (jQuery(this).css("background-repeat") == "no-repeat") ? "imgage" : "scale",
			bgIMG = jQuery(this).css("background-image");
		if (bgIMG.search(".png") > -1) {
			var iebg = bgIMG.split('url("')[1].split('")')[0];
			jQuery(this).css({ "background-image": "none" });
			jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='" + method + "')";
		}
	});
};
jQuery.fn.POD = function(options) {
	var options = jQuery.extend({
		speed: 400,
		text: "кликните, чтобы закрыть. Нажмите и удерживайте для перемещения.",
		src: "map.png",
		width: "600px",
		height: "600px"
	}, options);
	return this.each(function() {

		var html = '<div id="PlanOfDriving">';
		html += '<div id="PlanOfDriving_TL"></div>';
		html += '<div id="PlanOfDriving_T"></div>';
		html += '<div id="PlanOfDriving_TR"></div>';
		html += '<div id="PlanOfDriving_L"></div>';
		html += '<span id="PlanOfDriving_Close">&nbsp;</span>';
		html += '<a title=\"'+options.text+'\"><img alt="" src=\"' + options.src + '\" width=\"' + options.width + '\" height=\"' + options.height + '\" /></a>';
		html += '<div id="PlanOfDriving_R"></div>';
		html += '<div id="PlanOfDriving_BL"></div>';
		html += '<div id="PlanOfDriving_B"></div>';
		html += '<div id="PlanOfDriving_BR"></div>';
		html += '</div>';
		jQuery(this).click(function() {
			jQuery(html).appendTo(jQuery("body"));
			jQuery("#PlanOfDriving_T,#PlanOfDriving_B").css({ width: options.width });
			jQuery("#PlanOfDriving_L,#PlanOfDriving_R").css({ height: options.height });
			if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
				jQuery("#PlanOfDriving div").ie6fix();
			}
			var _top = (jQuery(window).height() > parseInt(options.height) + parseInt(jQuery("#PlanOfDriving_T").css("height")) + parseInt(jQuery("#PlanOfDriving_B").css("height"))) ? (jQuery(window).height() - (parseInt(options.height) + parseInt(jQuery("#PlanOfDriving_T").css("height")) + parseInt(jQuery("#PlanOfDriving_B").css("height")))) / 2 : 0,
				_left = (jQuery(window).width() > parseInt(options.width) + parseInt(jQuery("#PlanOfDriving_L").css("width")) + parseInt(jQuery("#PlanOfDriving_R").css("width"))) ? (jQuery(window).width() - (parseInt(options.width) + parseInt(jQuery("#PlanOfDriving_L").css("width")) + parseInt(jQuery("#PlanOfDriving_R").css("width")))) / 2 : 0;
			jQuery("#PlanOfDriving").css({ top: _top + jQuery(document).scrollTop() + "px", left: _left + "px" });
			jQuery("#PlanOfDriving").draggable();
			var t=-10000,l=-10000;
			jQuery("#PlanOfDriving img").mousedown(function(){
					t = jQuery("#PlanOfDriving").offset().top; 
					l = jQuery("#PlanOfDriving").offset().left;
			}).mouseup(function(){
				if(t == jQuery("#PlanOfDriving").offset().top && l == jQuery("#PlanOfDriving").offset().left)
					jQuery("#PlanOfDriving").slideUp(options.speed, function() {jQuery(this).remove();});
			});
			jQuery("#PlanOfDriving_Close").click( function (){jQuery("#PlanOfDriving").fadeOut(options.speed, function() {jQuery(this).remove();});});
			jQuery("#PlanOfDriving").slideDown(options.speed);
			return false;
		});
	});
};
