(function($){

	//Resize image on ready or resize
	$.fn.supersized = function() {
		$.paused = false;
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		
		$(window).bind("load", function(){
			$('#loading').hide();
			$('#supersize').show();
			$('#content').show();
			$("#text_download").hide(); $("#text_problems").hide();
			if ($('#slideshow .activeslide').length == 0) $('#supersize a:first').addClass('activeslide');
			$('#slidecaption').html($('#supersize .activeslide').find('img').attr('title'));
			//for hovering - much betterto define class just for that
			$('#navHome').click(function(){pickslide('id1'); $("#text_download").hide(); $("#text_problems").hide(); $("#text").show();});
			$('#navDownload').click(function(){pickslide('id2'); $("#text").hide(); $("#text_problems").hide(); $("#text_download").show();});
			$('#navAbout').click(function(){pickslide('id3'); $("#text_download").hide(); $("#text").hide(); $("#text_problems").show();});
			$('#navEng').click(function(){document.location = "/"});
			$('#navRus').click(function(){document.location = "/index.ru.php"});
			//$('.navlinks').hover(function(){$(this).css('background-color','#FFFF00')},function(){$(this).css('background-color','#000000')}).attr('href','javascript:void(0)');
			$('.navlinks').attr('href','javascript:void(0)');
			$('#feedback_form').attr('action','/submit_feedback.php');

		});
				
		$(document).ready(function() {	$('#supersize').resizenow(); });
		
		$(window).bind("resize", function(){ $('#supersize').resizenow(); });
		
		$('#supersize').hide();
		$('#content').hide();
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	  	return this.each(function() {
	  		
			//Define image ratio
			var ratio = options.startheight/options.startwidth;
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			var offset;

			//Resize image to proper ratio
			if ((browserheight/browserwidth) > ratio){
			    $(this).height(browserheight);
			    $(this).width(browserheight / ratio);
			    $(this).children().height(browserheight);
			    $(this).children().width(browserheight / ratio);
			} else {
			    $(this).width(browserwidth);
			    $(this).height(browserwidth * ratio);
			    $(this).children().width(browserwidth);
			    $(this).children().height(browserwidth * ratio);
			}
			if (options.vertical_center == 1){
				$(this).children().css('left', (browserwidth - $(this).width())/2);
				$(this).children().css('top', (browserheight - $(this).height())/2);
			}
			return false;
		});
	};
	
	$.fn.supersized.defaults = { 
			startwidth: 4,  
			startheight: 3,
			vertical_center: 1,
			startwidth: 640,  
			startheight: 480
	};
	
})(jQuery);



	function pickslide(slide) {
	    var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	    var currentslide = $('#supersize .activeslide');
	    currentslide.removeClass('activeslide');

		$('.prevslide').removeClass('prevslide');
            currentslide.addClass('prevslide');

		
	    nextslide = $('#supersize #'+slide);
	
            //Captions require img in <a>
	    $('#slidecaption').html($(nextslide).find('img').attr('title'));
	    nextslide.addClass('activeslide')
	    nextslide.show();
	    	
	    //$('#supersize').resizenow();//Fix for resize mid-transition
	    
	}


