var jq = jQuery.noConflict();

jq(document).ready(function(){	
	started = true;

	//popupy
	var popupLinks = jq('.open-popup');
	if(popupLinks.length){
		popupLinks.popup({width:720,height:600});
	}
	
});

//open popup
(function($){ 
	$.fn.extend({ 
		popup: function(options){
			
			if($(this).size()<=0) return;
			
			//domyslne wartosci, moga byc nadpisane poprzez obiekt opcji w wywolaniu
			var defaults = {
				width: 830,
				height: 700,
				titlebar: true,
				status: true,
				resizable: true,
				toolbar: false,
				scrollbars: true,
				menubar: false
			};
			var options = jQuery.extend(defaults, options);
			
			Boolean.prototype.setProperty = function() {
				if (this == true) { return "yes"; } else { return "no"; }
			};
			
			jQuery(this).click( function() {
				var target = this.target;
				var url = this.href;
				
				//jezeli element poprzedzajacy link jest selectem, to value wybranej opcji bedzie urlem otwartego okna
				var select = $(this).prev();
				if($(select).size()>0){
					if(select.get(0).tagName.toLowerCase() == 'select'){
						url = select.find('option').get(select.get(0).selectedIndex).value;
					}
				}
				//var posY = (parseInt(screen.height/2)) - (parseInt(options.height/2));
				//var posX = (parseInt(screen.width/2)) - (parseInt(options.width/2));
				var posY = 20;
				var posX = 20;
				
				if($(this).attr('class').indexOf('popup-attr-')!=-1){
					var popupAttributes = $(this).attr('class').split('popup-attr-')[1].split(' ')[0].split('-');
					if(popupAttributes[0] != 0)
					options.width = popupAttributes[0];
					
					if(popupAttributes[1] != 0)
					options.height = popupAttributes[1];

					if(popupAttributes[2]) options.posX = popupAttributes[2];
					if(popupAttributes[3]) options.posY = popupAttributes[3];
				}
				
				var win = window.open(url, target, 'titlebar=' + options.titlebar.setProperty() + ', screenX='+ posX +', screenY='+ posY +', left='+ posX +', top='+ posY +', status=' + options.status.setProperty() + ', resizable=' + options.resizable.setProperty() + ', toolbar=' + options.toolbar.setProperty() + ', scrollbars=' + options.scrollbars.setProperty() + ', menubar=' + options.menubar.setProperty() + ', width='+ options.width +', height='+ options.height);
				win.focus();
				return false;
			});
			return this;
		}
	}); 
})(jQuery); 
