(function($){
	
	$.fn.resizeImg = function ()
	{
				
				var t = $(this).parent();
				var i = $(this);
				
				return t.each(function() {
					
					var ratio =i.height() / i.width(); 
				
					var browserwidth = t.width();
					var browserheight = t.height();
		
					if ((browserheight/browserwidth) > ratio){
						i.css({width: (browserheight/ratio)+'px' , height: browserheight+'px'});
					} else {
						i.css({width: browserwidth+'px', height: (browserwidth*ratio)+'px'});
					}
						
					i.css('left', ((browserwidth - i.width())/2)+'px');
					i.css('top', ((browserheight - i.height())/2)+'px');

					return false;
				});
	};	
	
	$.fn.vertSlider = function(options) {
		
		var options = $.extend(options);
		var imgln = options.images.length;
		var winwidth = $(window).width();
		var winheight = $(window).height();
		var $menu = options.element;
		var index = 0;
		
		var t = $(this);
		
		$("<div class='scroll'></div>").appendTo(t).css({ width: '100%', height: 'auto', position: 'relative', top: 0, left:0});

  		for (i = 0; i < imgln; i++)
		{
			cont = $("<div class='conteiner'><div class='loader' style='top:50%;left:50%;'></div></div>").appendTo('.scroll').css({ width: winwidth, height: winheight, position: 'static', overflow: 'hidden'});
			img  = $('<img/>').css({position: 'relative', display: 'none'}).appendTo(cont).load(function(){$('.loader').hide(); $(this).resizeImg(); $(this).show(); }).attr('src', options.images[i].image);
  		} 

		$(window).bind('resize', function(){
				  winwidth = $(document).width();
				  winheight = $(document).height();
				  $(".conteiner").css({width: winwidth, height: winheight}).children('img').resizeImg();
				  $(".scroll").animate({ top: index * -winheight}, 100);
		});
		
		$(options.element).each(function() {
			$(this).find('a').bind('mouseover', function() {
				index = $(this).index('a');
				if (index>=0 && index<=8) $('.scroll').stop().animate({ top: index * -winheight}, 1000);
			});
		});

	};

})(jQuery);
