/**
 * @author aprian
 */
jQuery.fn.center = function () {
    return this.each(function () {
        var t = jQuery(this);
		var tWidth = 0;
		
		t.parent().css({
			position: 'relative'
		});
		
		$.each(t.children('li'), function(){
			tWidth = tWidth + $(this).outerWidth();
		});
				
		t.css({
			position: 'absolute',
            zIndex: 100,
			left: '50%',
			marginLeft:    '-' + (tWidth / 2) + 'px'
        });
		
    });
};


/*
 * CLOSE BUTTON
 * Bind close function for element with ID btn_close (#btn_close)
 * ID : #btn_close
*/

function closePopup() {
	$("input#btn_close").each( function() {
		$(this).click(function() {
			self.close();
		});
	});
}

/*
 * POPUP WINDOW
 * Bind open new window function for element with ID openPopup (#openPopup)
 * Class: openPopup pop_[Width]x[Height]
 * To create popup 800x600, use class: popup_800x600
*/

function openPopup() {
	$("a[class^='popup']").each( function() {
		$(this).click(function() {
			
			var winpop;
			var xurl = $(this).attr('href');
			var xtarget = '_blank';
			var thisClass = $(this).attr('class').split(' ');
			var re = new RegExp('^(popup_)');
			for(i=0;i<thisClass.length;i++) {
				if(thisClass[i].match(re)) {
					popSizes = thisClass[i].split('_');
					popSize = popSizes[1].split('x');
					popWidth = popSize[0];
					popHeight = popSize[1];
				}
			}
			
			winpop = window.open(xurl, xtarget,'width=' + popWidth + ',height=' + popHeight + ',resizable=0,scrollbars=yes,menubar=no,status=no' );
			winpop.focus();
			return false;
		});
	});
}


$(document).ready( function(){
	openPopup();
});
