﻿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: "Двойной щелчок, чтобы закрыть. Нажмите и удерживайте для перемещения.",
		width: "600px",
		height: "600px"
	}, options);
	return this.each(function() {
		
		var insertHTML = function(src,title,w,h){
			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=\"' + title + '\"><img alt="" src=\"' + src + '\" width=\"' + parseInt(w) + '\" height=\"' + parseInt(h) + '\" /></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>';
			return html;
		}
		
		jQuery(this).click(function() {
			var html = insertHTML(jQuery(this).attr("href"),options.text,options.width,options.height);
			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();
			jQuery("#PlanOfDriving").dblclick( function(){jQuery("#PlanOfDriving").fadeOut(options.speed, function() {jQuery(this).remove();});});
			jQuery("#PlanOfDriving_Close").click( function (){jQuery("#PlanOfDriving").fadeOut(options.speed, function() {jQuery(this).remove();});});
			jQuery("#PlanOfDriving").fadeIn(options.speed);
			return false;
		});
	});
};
