/*
 * Tworzy rogi
 * wymaga: jquery
 * 
 */

function generate_rog(cnt,classname,sprite) {
	if (cnt == 0) {
		classname += 'top-left';
		kier = "left top";
	}
	if (cnt == 1) {
		classname += 'top-right';
		kier = "right top";
	}
	if (cnt == 2) {
		classname += 'bottom-right';
		kier = "right bottom";
	}
	if (cnt == 3) {
		classname += 'bottom-left';
		kier = "left bottom";
	}
	return "<span class='jquery-rog "+classname+"' style='background:  url("+sprite+") "+kier+" no-repeat'></span>";
	
}



(function($){
	
	
	
	$.fn.extend({
		
	append_rog: function(cnt,options) {
	
		var defaults = {
			sprite: '',
			margin: [0,0,0,0],
			enabled: [true,true,true,true],
			width: 10,
			height: 10,
			classname:'jquery-rog-',
			html: ''
		};	
		
		options =  $.extend(defaults, options);
		$(this).each(function() {
			
		
			//$(this).append(generate_rog(cnt,options.classname,options.sprite));
			$(this).append(generate_rog(cnt,options.classname,options.sprite));
			
			$(this).children('.jquery-rog:last').each(function() {
			$(this).html(options.html);
			$(this).css('width',options.width);
			$(this).css('height',options.height);
			$(this).css('display','block');
			$(this).css('position','absolute');
			/*
			pos = $(this).parent().position();
			pw = $(this).parent().width();
			ph = $(this).parent().height();
			if (cnt == 0) {
				pl = (pos.left-options.margin[3]);
				pt = (pos.top-options.margin[0]);
			}
			if (cnt == 1) {
				pl = (pos.left+options.margin[1]+pw);
				pt = (pos.top-options.margin[0]);
			}
			if (cnt == 2) {
				pl = (pos.left+options.margin[1]+pw);
				pt = (pos.top+options.margin[2]+ph);
			}
			if (cnt == 3) {
				pl = (pos.left-options.margin[3]);
				pt = (pos.top+options.margin[2]+ph);
			}
			$(this).css('left',pl+'px');
			$(this).css('top',pt+'px');
			*/
			pos = new Object;
			pw = $(this).parent().width();
			ph = $(this).parent().height();
			pos.left = 0;
			pos.top = 0;
			if (cnt == 0) {
				pl = (pos.left-options.margin[3]);
				pt = (pos.top-options.margin[0]);
			}
			if (cnt == 1) {
				pl = (pos.left+options.margin[1]+pw-options.width);
				pt = (pos.top-options.margin[0]);
			}
			if (cnt == 2) {
				pl = (pos.left+options.margin[1]+pw-options.width);
				pt = (pos.top+options.margin[2]+ph-options.height);
			}
			if (cnt == 3) {
				pl = (pos.left-options.margin[3]);
				pt = (pos.top+options.margin[2]+ph-options.height);
			}
			
			$(this).css('margin-left',pl+'px');
			$(this).css('margin-top',pt-ph+'px');
			
		});	
		});	
			
		
		return $(this);
			
			
		},
		
	
	rogi: function(options) {
	
		var defaults = {
			sprite: '',
			margin: [0,0,0,0],
			enabled: [true,true,true,true],
			width: 10,
			height: 10,
			classname:'jquery-rog-',
			html: '',
			disableOnIe6: true
		};	
		
		options =  $.extend(defaults, options);
		
		if ((!(($.browser.msie) && (parseInt($.browser.version)==6) && (options.disableOnIe6)))) {
		$(this).each(function () {
			if (options.enabled[0]) {
				$(this).append_rog(0,options);
			}
			if (options.enabled[1]) {
				$(this).append_rog(1,options);
			}
			if (options.enabled[2]) {
				$(this).append_rog(2,options);
			}
			if (options.enabled[3]) {
				$(this).append_rog(3,options);
			}
		});
		
			
			
		}
		}

	

});

})(jQuery);

