/*Karl Swedberg Smooth Scroll plugin - see http://github.com/kswedberg/jquery-smooth-scroll/blob/master/jquery.smooth-scroll.js*/
;(function($){$.fn.smoothScroll=function(options){var opts=$.extend({},$.fn.smoothScroll.defaults,options),locationPath=filterPath(location.pathname),scrollElem=scrollableElement('html','body');this.each(function(){var link=this,$link=$(this),hostMatch=((location.hostname===link.hostname)||!link.hostname),pathMatch=(filterPath(link.pathname)||locationPath)===locationPath,thisHash=link.hash&&link.hash.replace('#',''),scrollTargetExists=thisHash&&!!$('#'+thisHash).length;if(hostMatch&&pathMatch&&scrollTargetExists){var include=true,exclude=opts.exclude,elCounter=0,el=exclude.length,excludeWithin=opts.excludeWithin,ewlCounter=0,ewl=excludeWithin.length;while(include&&elCounter<el){if($link.is(exclude[elCounter++])){include=false;}}
while(include&&ewlCounter<ewl){if($link.parents(excludeWithin[ewlCounter++]+':first').length){include=false;}}
if(include){$link.data('scrollTarget','#'+thisHash);}}});this.die('click.smoothscroll').live('click.smoothscroll',function(event){var scrollTargetId=$(this).data('scrollTarget');if(scrollTargetId){event.preventDefault();var scrollTargetOffset=$(scrollTargetId).offset().top;$(scrollElem).animate({scrollTop:scrollTargetOffset+opts.offset},400,function(){});}});return this;function scrollableElement(els){for(var i=0,argLength=arguments.length;i<argLength;i++){var el=arguments[i],$scrollElement=$(el);if($scrollElement.scrollTop()>0){return el;}else{$scrollElement.scrollTop(1);var isScrollable=$scrollElement.scrollTop()>0;$scrollElement.scrollTop(0);if(isScrollable){return el;}}}
return[];}
function filterPath(string){return string.replace(/^\//,'').replace(/(index|default).[a-zA-Z]{3,4}$/,'').replace(/\/$/,'');}
function debug($obj){if(window.console&&window.console.log){window.console.log($obj);}}};$.fn.smoothScroll.defaults={exclude:[],excludeWithin:[],offset:0};})(jQuery);

        
function slideSwitch() {
	var $active = $('#banners a.active');
    if ( $active.length == 0 ) $active = $('#banners a:last');

	//randomizing the images - replace the next two lines
	//var $sibs  = $active.siblings();
	//var rndNum = Math.floor(Math.random() * $sibs.length );
	//var $next  = $( $sibs[ rndNum ] );

	var $next = $active.next().length ? $active.next() : $('#banners a:first');
	$active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 500, function() {$active.removeClass('active last-active');});
}

$(document).ready(function() {
    //Очищение текстовых полей
	$('input[type=text]').click(function() {if (this.value == this.defaultValue) {this.value = '';}});
	$('input[type=text]').blur(function() {if (this.value == '') {this.value = this.defaultValue;}});
	
	$('#sendlink').click(function() { 
			$('#message').fadeIn();
			$('#overlay').fadeIn();
			$('#name').focus();
 });
 
 	$('a[href^=#]').smoothScroll();
 	//$('#intro a[href=#content]').click(function() {this.text('ви-и-иии!!!');});

$('#overlay,#message-close').click(function() {
			$('#message').fadeOut();
			$("#overlay").fadeOut();
		 });
		 

});
	

setInterval( "slideSwitch()", 5000 );
