// JavaScript Document
var isCollapse = false;
$(function(){
	moveSky();
	$(".paging").show();
	$(".paging a:first").addClass("active");

   	$('#collapsibleBar').click(collapseBar);
	$('#collapsibleBar').mouseover(collapseBar);
	
	var imageWidth = $('.window').width();
	var imageSum = $('.image_reel img').size();
	var image_reelWidth = imageWidth * imageSum + 100;
	//alert('imageWidth: ' + imageWidth + ', imageSum: ' + imageSum + ', image_reelWidth: ' + image_reelWidth);
	$('.image_reel').css({'width' : image_reelWidth});
	
	rotate = function(){
		var triggerID = $active.attr('rel') - 1;
		var image_reelPosition = triggerID * imageWidth;
		$('.paging a').removeClass('active');
		$active.addClass('active');
		$('.image_reel').animate({ left: -image_reelPosition}, 500);
	}
	
	rotateSwitch = function(){
		play = setInterval(function(){
			$active = $('.paging a.active').next();
			if($active.length == 0){
				$active = $('.paging a:first');
			}
			rotate();
		}, 5000);
	}
	
	rotateSwitch();
	
	$('.image_reel a').hover(
		function(){
			clearInterval(play);
		},
		function(){
			rotateSwitch();
		}
	);
	//$('.paging a').focus(function(){this.blur();});
	
	$('.paging a').click(function(){
		this.blur();
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		
		return false;
	});
	

});

function moveSky() {
        $('.sky').animate({ top: -580 }, 40000, 'linear', function () {
            $('.sky').animate({ top: 0 }, 40000, 'linear', moveSky());
        });
}
function showBar(){
	
	if (isCollapse==true){
	  $('#collapsibleContent').animate({height: 100, opacity : 1.0},300, 'linear');
	  $('#collapsibleContent').css({'display' : 'block'});
	  isCollapse = false;
	}else{
		collapseBar();
	}
	
}

function collapseBar(){
	
	if (isCollapse==false){
	   $('#collapsibleContent').animate({height: 0, opacity : 0.0},300, 'linear', function(){
			$('#collapsibleContent').css({'display' : 'none'});
		});
	   
	   isCollapse=true;
	}else{
		showBar();
	}
}
