$.extend ($.expr[':'], {
	links  : function (a) { return !a.href.match(/#.*?/); },
	anchors: function (a) { return a.href.match(/#.*?/); },
	inline : function (a) { return $(a).css('display') === 'inline'; },
	external: function (a,i,m) {
		if (!a.href) { return false; }
		return a.hostname && a.hostname !== window.location.hostname;
	},
	// Check whether element is currently within the viewport:
	inView: function (a) {
		var st = (document.documentElement.scrollTop || document.body.scrollTop),
		ot = $(a).offset().top,
		wh = (window.innerHeight && window.innerHeight < $(window).height()) ? window.innerHeight : $(window).height();
		return ot > st && ($(a).height() + ot) < (st + wh);
	}
});

/**
 * main
 * @package macem page
*/

/**
 * function init js on load
*/
$(document).ready (function () {


	$(document.body).addClass ('js');
	
	// if href = img src then enlarge
	$('a img').attr ('title', 'enlarge').parent().prepend ('<span class="zoom"/>');


	$('div.statusbar').prepend ('<a href="#close" class="statusbar-close">[close]</a>');
	$('a.statusbar-close').live ('click', function() {
		$(this).parent().remove();
		return false;
	});

        $('.links .welcome a').click (function() {
            var self = $(this);
		// SHOULD be loaded before for initialize img
		$('<div/>').addClass('loader').css({
			top : this.offsetTop + this.offsetHeight,
			left: this.offsetLeft
		}).insertAfter(this).append('<p>loading...</p>');
            
	    $.get ('/plain/action.module/form_login.action', function(data) {
                var form = $(data).find ('form');
        
        	var _window = $('<div class="window window_login"/>');
		_window.html (form).appendTo (document.body);
        	
                /*var _window = widget.window.create('window_login', '', d.body, form.parent().html(), null); 
                $('a.cancel', _window).click (function() {
                	$(_window).animate({top:'-200px'});
                	return false;
                });*/
                
                var top = (self.offset().top + self.height());           
                var left = self.offset().left - 10;
                
                $(_window).css({left:left,top:-$(_window).height()+'px'}).animate({top:top}, 200);
                $('input[type=text]:first', _window).focus();
                
                $('div.loader').remove();
                
            });
            return false;
        });
        
        $('button.submit').click (function() {
		$('<div/>').addClass('loader').css({
			top : this.offsetTop + this.offsetHeight,
			left: this.offsetLeft
		}).insertAfter(this).append('<p>loading...</p>');
		//return false;
	});

        if ($.browser.msie) $('input, textarea, select').focus (function() {
            $(this).addClass ('focus');
        });
        if ($.browser.msie) $('input, textarea, select').blur (function() {
            $(this).removeClass ('focus');
        });  
        
        $('div.sidebar form.search input:first').focus();

	$('form.form').mtab();
	
	$('div.image-slide').textSlider({
		elements : '> img', 
		mousewheel : false, 
		breadcrumbTitle : 'fota ', 
		animate : 'resize',
		next : { text: 'następna fota »' },
		previous : { text: '« poprzednia fora' }
	});
	
	/*$('form.form').preview ({
		title: 'Article preview',
		templateUrl: '/js/plugins/templates/article.htm',
		from : {
			title: '#article_title',
			content: '#article_content'
		}
	});*/
	
	//$('div.sidebar').collapse();
  });
