(function($) {
    
    $.fn.filestyle = function(options) {
                
        /* TODO: This should not override CSS. */
        var settings = {
            width : 250
        };
                
        if(options) {
            $.extend(settings, options);
        };
                        
        return this.each(function() {
            
            var self = this;
            var wrapper = $("<div>")
                            .css({
                                "width": settings.imagewidth + "px",
                                "height": settings.imageheight + "px",
                                "background": "url(" + settings.image + ") 0 0 no-repeat",
                                "background-position": "right",
                                "display": "inline",
                                "position": "absolute",
                                "overflow": "hidden"
                            });
                            
            var filename = $('<input class="file">')
                             .addClass($(self).attr("class"))
                             .css({
                                 "display": "inline",
                                 "width": settings.width + "px"
                             });

            $(self).before(filename);
            $(self).wrap(wrapper);

            $(self).css({
                        "position": "relative",
                        "height": settings.imageheight + "px",
                        "width": settings.width + "px",
                        "display": "inline",
                        "cursor": "pointer",
                        "opacity": "0.0"
                    });

            if ($.browser.mozilla) {
                if (/Win/.test(navigator.platform)) {
                    $(self).css("margin-left", "-142px");                    
                } else {
                    $(self).css("margin-left", "-168px");                    
                };
            } else {
                $(self).css("margin-left", settings.imagewidth - settings.width + "px");                
            };

            $(self).bind("change", function() {
                filename.val($(self).val());
            });
      
        });
        

    };
    
})(jQuery);





function drukuj() {
	window.open('?print=1','_blank','toolbar=yes, location=no, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=715, height=500')
}


function popup(url, width, height) {
	window.open(url,'_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+'')
}


function menu() {
	var flashvars = {
		xmlPath: CMS_URL + 'tpl/xml/menu_'+CMS_LANG+'.xml'
	};
	var params = {};
	var attributes = {};
		
	swfobject.embedSWF(CMS_URL + "tpl/swf/top_home.swf", "FlashNav", "100%", "379", "9.0.0", "", flashvars, params, attributes);
}

var params = {
	bgcolor: "#F76800",
	wmode:"transparent"
};
var attributes = {};	

$(document).ready(function() {
	//menu();
	$("input.file").filestyle({ 
		image: CMS_URL + "tpl/img/tlo_file.gif",
		imageheight : 23,
		imagewidth : 78,
		width : 139
	});
		
	submitNewsletter = function(){
		$('#newsletterResult').load('/' + CMS_LANG + '/newsletter-form?action=save1&grupaId=' + $('#grupaId').attr('value') + '&email=' + $('#sz').attr('value'));
		$('#newsletterResult').show();
//		$('#wyniki').show();
		$('#newsletter').hide();
		$('#newsletterZajawka').hide();
		setTimeout(function() {
			$('#newsletter').show();
			$('#newsletterZajawka').show();
			$('#newsletterResult').hide();
		}, 10000);
	return false;
	};
	
	$('form#newsletter').submit(submitNewsletter);
	
	$('#newsletter a').click(function() {
		return submitNewsletter();
	});

	if (!$.browser.msie || (!$.browser.version.charAt(0) == '6' && $.browser.msie)) {

	  if ($.browser.msie) {
		  $('.mbox_665').css('position', 'relative');
	  }

	  baseImgs = $('.rozki > img');

	  baseImgs.each(function(i) {
		left_ = this.offsetLeft-10
		top_ = this.offsetTop
		right_ = this.offsetLeft+parseInt($(this).attr('width'))-1-10
		bottom_ = this.offsetTop+parseInt($(this).attr('height'))-1

		img1 = $('<img/>').attr('src', '/tpl/img/rozek.gif');
		img1.css('position', 'absolute').css('left', left_).css('top', top_);
		$(this).after(img1);

		img2 = $('<img/>').attr('src', '/tpl/img/rozek.gif');
		img2.css('position', 'absolute').css('left', right_).css('top', top_);
		$(this).after(img2);

		img3 = $('<img/>').attr('src', '/tpl/img/rozek.gif');
		img3.css('position', 'absolute').css('left', left_).css('top', bottom_);
		$(this).after(img3);

		img4 = $('<img/>').attr('src', '/tpl/img/rozek.gif');
		img4.css('position', 'absolute').css('left', right_).css('top', bottom_);
		$(this).after(img4);

	  });

	}

});
