$(document).ready(function() {
		
		function toggleObject()
		{
			$('object').toggle();
			$('.object').toggle();
		}

		$jScroller.add("#scroller_container","#scroller","left",1);

  // Start Autoscroller
  $jScroller.start();
		
		if ( !$.browser.msie ) {
		$(".img-corner, .img-rounded").imgr({size:"0px",color:"#dedee2",radius:"12px 12px 12px 12px"});
		}  
		$('#hello').flash({
			src: 'hello.swf',
			width: 320,
			height: 240
		});
					
		
		$(".fancybox").fancybox({
			'callbackOnShow': toggleObject,
			'callbackOnClose': toggleObject
		});
		
		$(".fancy-ajax").fancybox({
			'frameWidth':		950, 
			'frameHeight':		485, 
			'hideOnContentClick':		false, 
			
		});
		
		$("a#inline").fancybox({
			'hideOnContentClick': true
		});

		$("a.group").fancybox({
			'zoomSpeedIn':		200, 
			'zoomSpeedOut':		200, 
			'overlayShow':		true,
			'overlayColor': '#000',
			'hideOnContentClick':		false,
			 pause: 1,
			'callbackOnShow': toggleObject,
			'callbackOnClose': toggleObject
		}).css('z-index',1000); 
		
	

		//$('#nav a img[class!=selected]').imghover({suffix: '-hover'});
				
	
			// fix for target='_blank'
			$("a[href][rel*=external]").click(function(){
			window.open($(this).attr('href'));
			return false;
			});

		
			$('#top-banner').cycle({
				fx:    'fade',
				pause:  2, 
				timeout:  6000 
			});
			
		
			
			$('#partners').cycle({
				fx:    'fade',
				pause:  3, 
				timeout:  7000 
			});
			$('.rounded, .corner').corner();

});




jQuery.fn.repeat = function(times, string) {  
    //For each item matched  
    this.each(function(){  
        var buff = string;  
        for(var i=1; i < times; i++){  
            buff += string;  
        }  
        jQuery(this).append(buff);  
    });  
    return this;  
} 

function repeat(str, i) {
   if (isNaN(i) || i <= 0) return "";
   return str + repeat(str, i-1);
}

$(function(){
		$('.font-size').click(function(){
			var ourText = $('.lido,.content, #page-content');
			var currFontSize = ourText.css('fontSize');
            var currLineHeight = ourText.css('lineHeight');
			var finalNum = parseFloat(currFontSize, 10);
			var finalLineHeight = parseFloat(currLineHeight, 10);
			var stringEnding = currFontSize.slice(-2);
            
			if(this.className.search('larger') == 10  ) {
				finalNum *= 1.2;
                finalLineHeight *= 1.2;
			}
			else if (this.className.search('smaller')){
				finalNum *=0.8;
                finalLineHeight *= 0.8;
			}
           
			ourText.css('fontSize', finalNum + stringEnding);
			ourText.css('lineHeight', finalLineHeight + stringEnding);
		});
	});


function add_comment(url_base, module_id, module_row_id)
{
	$('#comment-msg').text('');
	$('#comment-container').block({ message:"Proszę czekać", border: "1px solid #ffce24"});
	
	$.post(url_base+"misc/add_comment/"+module_id+"/"+module_row_id, { 
	username: $('#comment-username').val(),
	email: $('#comment-email').val(),
	description: $('#comment-description').val()
	},
   function(data){
		$('#comment-container').unblock();
		if(data != 1)
			$('#comment-msg').append("Blędy formularza: <br/>"+data);
		else
			$('#comment-msg').append("Komentarz zostal dodany <br/>"+data);
			
   });
   
   return false;
}


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 32;
		yOffset = 22;	
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip' style='z-index:99'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


function popup(url, width, height)
{
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}
