/**
 * @author Arturas Paleicikas <arturas.paleicikas@metasite.net>
 */

var BaseData	= {
	init: function(){
		this.initTopSearchForm();
		this.initCSS();
        this.initPopups($('a.__callPopup'));
	},
	
	initCSS: function(){
		$('table.tableTdBorder td, table.tableBorders td')
			.parent()
			.hover(
				function(){$(this).addClass('TableRowSelected');}, 
				function(){$(this).removeClass('TableRowSelected')}
			);
	},

	initTopSearchForm: function(){
        var $input = $('#search input[type=text]')
                    .click(function(){$input.val('')});
	},

    initPopups: function($items){
        var self = this;

        $items
            .each(function(i,n){
                var $obj = $(n)
                    .click(function(){
                        var src      =  ($obj.attr('popup') || $obj.attr('href'));
                        var width    = ($obj.attr('width') || 300);
                        var height   = ($obj.attr('height') || 300);
                        var position = ($obj.attr('position') || 'fixed');
                        var popup   = '<div id="popup">' 
                                            + '<a href="javascript:;" onclick="$.unblockUI();"><img src="images/common/close.gif" alt="" /></a>'
                                            + '<iframe width="' 
                                            + width +'" height="' 
                                            + height + '" frameborder="0" scrolling="no" src="' 
                                            + src + '"></iframe>'
                                        + '</div>'
                                        + '<table class="popup-bottom" cellpadding="0" cellspacing="0"><tr><td class="bottom">&nbsp;</td><td class="corner"></td></tr></table>';
                        $.blockUI({
                            width: width, 
                            height: height, 
                            message: popup,
                            centerX: false,
                            centerY: false,
                            css: { 
                                border: 0,
                                top:  100 + 'px', 
                                left: ($(window).width() - width) /2 + 'px', 
                                width: width + 'px',
                                position: position                                
                                }
                        });

                        return false;
                    });
            });
    }
};

$(document).ready(function(){ window.BaseData.init();});