$(document).ready(function() {  
  jQuery('ul.tabs-navi a').each(function(){
	  jQuery(this).click(function(){
		  tab_content_id = jQuery(this).attr('href').replace('#','') ;
			
			jQuery('.tab-container').each(function(){
			  jQuery(this).hide();
			});
			jQuery('#' + tab_content_id).show() ; 
			
			jQuery('ul.tabs-navi li.selected').removeClass('selected');	  	    

			jQuery(this).parents('li').addClass('selected');      
		     
		  return false;
	  });
	});
	
	jQuery('#view_more_box').css('height', '0px').css('bottom', '-10px');
	jQuery('#view_more_box').css('visibility', 'hidden');
	jQuery('#view_more_box_content').css('display', 'none');
	
	jQuery('.view_more_link a').click(function(){
    if(jQuery('#view_more_box_content').css('display') == 'none'){
    	jQuery('#view_more_box').css('visibility', 'visible');
      jQuery('#view_more_box').animate({height: "55px",bottom:"-65px"}, 300, 'linear', function(){
      	jQuery('#view_more_box_content').show();
      });     
    }
    else{
    	jQuery('#view_more_box_content').hide();
    	 jQuery('#view_more_box').animate({height: "0px",bottom:"-10px"}, 300,'linear', function(){
    	 	 
    	   jQuery('#view_more_box').css('visibility', 'hidden');
    	 });     
    	 
    }
    return false;
  });
  
  jQuery('.little-bubble').click(function(){
    return false;
  });
  
  jQuery('.little-bubble').mouseover(function(){
    id = jQuery(this).attr('id').replace('little', '');
    jQuery('.little-bubble').removeClass('active');
    jQuery('.situation-bubble').removeClass('active');
    jQuery('.solution-bubble').removeClass('active');
    jQuery(this).addClass('active');
    jQuery('#situation' + id).addClass('active');
    jQuery('#solution' + id).addClass('active');
  });
  
  jQuery('#view_map').click(function(){
    jQuery('.gmap-container').css('top', '20px');
    jQuery(this).addClass('active');
    return false;	
  });
  
   
  function switchNews(direction, distance, size){
  	current_position = jQuery('#outside-news').css('left').replace('px', '');
  	max_position = jQuery('#outside-news').css('width').replace('px', '');
  	
    if(direction == 'right'){
    	if(Math.abs(parseInt(current_position)) < (parseInt(max_position) - distance)){
  	    new_left_position = parseInt(current_position) - distance;

  	    if(new_left_position % distance != 0){  	  		  	
  	    	new_left_position = Math.round(new_left_position/distance)*distance ;
  	    	if(Math.abs(new_left_position) > (parseInt(max_position) - distance)){
  	    		new_left_position = -parseInt(max_position) + distance ;
  	    	}
  	    }
        jQuery('#outside-news').animate({left: new_left_position + 'px'},300,'linear',function(){
        	tester = parseInt(jQuery('#outside-news').css('left').replace('px', ''));
        	if(Math.abs(tester)  > (parseInt(max_position) - size)){      		
  	    		fixe_pos = -parseInt(max_position) + (size) ;
  	    		jQuery('#outside-news').css('left', fixe_pos + 'px') ;
  	      }
          numNews = (Math.abs(parseInt(jQuery('#outside-news').css('left')))/size) + 1;  
  	      jQuery('#navigation_bottom li a').removeClass('active');
  	      jQuery('#news-'+numNews).addClass('active');
        });          
      }   
    }
    else{ 	
  	  if(parseInt(current_position) < 0){
  	    new_left_position = parseInt(current_position) + distance;
        if(new_left_position % distance != 0){  	
  	    	new_left_position = Math.round(new_left_position/distance)*distance ;
  	    	if(new_left_position > 0){
  	        new_left_position = 0;
  	      }
  	    }
        jQuery('#outside-news').animate({left: new_left_position + 'px'},300, 'linear', function(){
        	if(parseInt(jQuery('#outside-news').css('left').replace('px', '')) > 0){
  	        jQuery('#outside-news').css('left', 0 + 'px' )
  	      }    
  	      numNews = (Math.abs(parseInt(jQuery('#outside-news').css('left')))/distance) + 1;  	    
  	      jQuery('#navigation_bottom li a').removeClass('active');
  	      jQuery('#news-'+numNews).addClass('active');
        });    
      }
    }
  }
  
  
  jQuery('#news-box #next').click(function(){
    switchNews('right',275, 275);
    return false;	
  });
  jQuery('#news-box #previous').click(function(){
    switchNews('left',275,275);
    return false;	
  });
  
  
  jQuery('#news-box .num-link').click(function(){
  	jQuery('#navigation_bottom li').each(function(){
  	  if(jQuery(this).children('a').hasClass('active')){
  	  	active_id = jQuery(this).children('a').attr('id').replace('news-','');
  	  } 	  
  	});
  	current_id = jQuery(this).attr('id').replace('news-','');
  	distance =Math.abs( 275 * (parseInt(current_id) - parseInt(active_id))) ;
  	if(current_id > active_id){	
  		switchNews('right',distance,275); 
  	}
  	else if(current_id < active_id) {
  		switchNews('left',distance,275); 
  	}
    return false;	
  });
   

  if(isWebkit == 0){
    if(parseInt(jQuery('#left-column').height()) > (parseInt(jQuery('#right-column').height())+(parseInt(jQuery('#right-column').css('padding-top')) + parseInt(jQuery('#right-column').css('padding-bottom'))))){  	
    	jQuery('#right-column').height(parseInt(jQuery('#left-column').height())-(parseInt(jQuery('#right-column').css('padding-top')) + parseInt(jQuery('#right-column').css('padding-bottom'))));
    }
    else if(parseInt(jQuery('#left-column').height()) < (parseInt(jQuery('#right-column').height())+(parseInt(jQuery('#right-column').css('padding-top')) + parseInt(jQuery('#right-column').css('padding-bottom'))))){
  	  jQuery('#left-column').height(parseInt(jQuery('#right-column').height())+(parseInt(jQuery('#right-column').css('padding-top')) + parseInt(jQuery('#right-column').css('padding-bottom'))));
    }
  }

});
