// JavaScript Document
$(document).ready(function(){
	
	
	//-------------------------------------------------------
	// Adjust right swirly bg on window resize or load
	//-------------------------------------------------------
	
	var $win = $(window);
	var $right_bg = $("#page_right_");
	var $left_bg = $("#page_left_");
	
	$move_right_bg();
	
	$scroll_bg();
	
	
	$(window).resize(function(){
		$move_right_bg();
	});
	
	function $move_right_bg(){
		var $win_wid = $(window).width();
		if($win_wid < 1030){
			$margin_move = 0 - (1030 - $win_wid);
			$right_bg.css({right: $margin_move});
		} else {
			$right_bg.css({right: 0});
		}
	}
	
	$win.scroll(function(){
		$scroll_bg();
	});
	
	function $scroll_bg(){
		$winTop = 0 - ($win.scrollTop()) / 24;
		$right_bg.css({top: $winTop});
		$left_bg.css({top: $winTop});
		$("body").css({backgroundPosition: '500px '+$winTop+'px' })
	}
	
	
	
	//-------------------------------------------------------
	// Lightbox verticle
	//-------------------------------------------------------
	/*
	$(window).resize(function(){
		//lightbox_verticle();
	});
	$(window).scroll(function(){
		if($(window).height() > $("#cboxLoadedContent").height()){
			lightbox_verticle();
		}
	});
	
	function lightbox_verticle(){
		$LB_top = $(window).scrollTop() + ( $(window).height() - $("#cboxLoadedContent").height() ) / 2;
		
		
		$("#colorbox").css({top: $LB_top});
		
	}
	*/
	
	
	
	/* random shit
	$('.home #content .post').css({opacity: 0.3});
	
	$('.home #content .post').hover(
		function () {
		    $(this).css({opacity: 1});
		},
		function () {
		    $(this).css({opacity: 0.3});
		}
	); 
	*/
	
	
    //-------------------------------------------------------
	// Execute the slideShow
	//-------------------------------------------------------
 
   //$home_slideShow(5000);
	$home_slideShowZ(5000);
 	

});

//-------------------------------------------------------
// slideShow
//-------------------------------------------------------
/*
function $home_slideShow($home_gallery_speed) {
	// Set the opacity of all images to 0, first to 1
	$('ul.wGallery li').css({opacity: 0.0});
	$('ul.wGallery li:first').css({opacity: 1.0}).addClass('show');
	
	// start timer
	var $home_gallery_timer = setInterval( "$roll_home_gallery()", $home_gallery_speed );
	
	// pause the slideshow on mouse over
	$('ul.wGallery').hover(
		function () {
			clearInterval($home_gallery_timer);
		},  
		function () {
			$home_gallery_timer = setInterval( "$roll_home_gallery()", $home_gallery_speed);         
		}
	); 
}
function $roll_home_gallery() {
	//if no IMGs have the show class, grab the first image
	var current = ($('ul.wGallery li.show')?  $('ul.wGallery li.show') : $('ul.wGallery li:first'));
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {
 
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.wGallery li:first') :current.next()) : $('ul.wGallery li:first'));
			  
		//Set the fade in effect for the next image, show class has higher z-index
		current.removeClass('show');
		next.css({opacity: 0.0}).addClass('show').animate({
			opacity: 1.0
		},800, function $hide_prev_home_gallery(){
			current.css({opacity: 0.0});
		});
	}
}

*/
//-------------------------------------------------------
// slideShow 2
//-------------------------------------------------------
function $home_slideShowZ($home_gallery_speed) {
	// Set the opacity of all images to 0, first to 1
	$('.rsgallery a').css({opacity: 0.0});
	$('.rsgallery a:first').css({opacity: 1.0}).addClass('show');
	
	// start timer
	var $home_gallery_timer = setInterval( "$roll_home_galleryZ()", $home_gallery_speed );
	
	// pause the slideshow on mouse over
	/*
	$('ul.wGallery').hover(
		function () {
			clearInterval($home_gallery_timer);
		},  
		function () {
			$home_gallery_timer = setInterval( "$roll_home_gallery()", $home_gallery_speed);         
		}
	); 
	*/
}
function $roll_home_galleryZ() {
	//if no IMGs have the show class, grab the first image
	var current = ($('.rsgallery a.show')?  $('.rsgallery a.show') : $('.rsgallery a li:first'));
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {
 
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('.rsgallery a:first') :current.next()) : $('.rsgallery a:first'));
			  
		//Set the fade in effect for the next image, show class has higher z-index
		current.removeClass('show');
		next.css({opacity: 0.0}).addClass('show').animate({
			opacity: 1.0
		},800, function $hide_prev_home_gallery(){
			current.css({opacity: 0.0});
		});
	}
}


