
$(window).load(function(){
	imageRotator(true);
	window.toggle = 1;
	setInterval("imageRotator(false)",9000);
	
});

function imageRotator(firstRun){
	
	var currentPhoto = $("#myslider div.slider-current");
	var nextPhoto = currentPhoto.next();
	if (nextPhoto.length == 0){
		nextPhoto = $("#myslider div:first")
	}
	currentPhoto.addClass('slider-previous').removeClass('slider-current');
	if(firstRun == true){
		$('div.slider-loading img').remove();
	}
	
	
	if(window.toggle == 0){
		currentPhoto.children("p.slider-right-side").css({opacity:0.0, top:100, left:50}).animate({opacity:1.0, top:100}),5000;
		currentPhoto.children("p.slider-left-side").css({opacity:0.0, top:100, left:650}).animate({opacity:1.0, top:100}),5000;
		nextPhoto.children("p.slider-right-side").css({opacity:0.0});
		nextPhoto.children("p.slider-left-side").css({opacity:0.0});
		nextPhoto.css({opacity:0.0, top:50}).delay(2000).addClass('slider-current').animate({opacity:1.0, top: -50},7000,function(){
		currentPhoto.removeClass('slider-previous').css({top:-50});
		currentPhoto.children("p.slider-left-side").css({opacity:0.0, left:9999});
		currentPhoto.children("p.slider-right-side").css({opacity:0.0, left:9999});
		if(firstRun == true){
			$('div.slider-loading').remove();
		}
		
	});
	
	} else {
		currentPhoto.children("p.slider-right-side").css({opacity:0.0, top:100, left:50}).animate({opacity:1.0, top:100}),3000;
		currentPhoto.children("p.slider-left-side").css({opacity:0.0, top:100, left:650}).animate({opacity:1.0, top:100}),3000;
		nextPhoto.children("p.slider-right-side").css({opacity:0.0});
		nextPhoto.children("p.slider-left-side").css({opacity:0.0});
		nextPhoto.css({opacity:0.0, top:-50}).delay(2000).addClass('slider-current').animate({opacity:1.0, top: 50},7000,function(){
		currentPhoto.removeClass('slider-previous').css({top:-50});
		currentPhoto.children("p.slider-left-side").css({opacity:0.0, left:9999});
		currentPhoto.children("p.slider-right-side").css({opacity:0.0, left:9999});
		if(firstRun == true){
			$('div.slider-loading').remove();
		}
		
	});
	
	}
	/*if (window.toggle == 0){
		window.toggle = 1;
	} else {
		window.toggle = 0;
	}*/
}


