// JavaScript Document

$(document).ready(function(){ 
	
	if($('#bcia h2').length){
		var request_h2 = $('h2').get(-1);
		$(request_h2.tagName).addClass("request-quote");
	}
	
	$('.do-expand').click(function(){  
	  var num = initPagination();
	  
	  if($("#active").is(":hidden")) {
			$("#block-"+num+" .slider-title").addClass('green');
			$("#active").slideDown('slow');	
			$(this).children().toggleClass('up');
			//$('.blog').css({'position' : 'relative', 'bottom' : '0', 'right' : '0'});
	   } else { 
			$("#active").slideUp('slow', function(){
				$("#block-"+num+" .slider-title").removeClass('green',2000);
				$("#block-"+num).addClass('slide');
			});
			$(this).children().removeClass('up');
			//$('.blog').css({'position' : 'fixed', 'bottom' : '75px', 'right' : '208px'});
	  }
	});
	 
	$('.navigation-right').click(function(){ 
		var class_name = $(this).attr('id');
		if($("#content").hasClass("slider-bg-1")){ 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-1");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		 $("#content").addClass("slider-bg-2");
		 $("#content").fadeIn('slow', function(){
		   $(".slider").fadeIn(); 
		   $(".blog").fadeIn(); 
		 });
		} 
		else { 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-2");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		  $("#content").addClass("slider-bg-1"); 
		 $("#content").fadeIn('slow', function(){
			$(".slider").fadeIn();
			$(".blog").fadeIn(); 
		 });
		}    
	   initPagination('R');
		
	});
				
	$('.navigation-left').click(function(){ 
		var id = $(this).attr('id');  
		if($("#content").hasClass("slider-bg-1")){ 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-1");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		 $("#content").addClass("slider-bg-2");
		 $("#content").fadeIn('slow', function(){
		   $(".slider").fadeIn();
		   $(".blog").fadeIn(); 
		 });
		} 
		else { 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-2");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		  $("#content").addClass("slider-bg-1"); 
		 $("#content").fadeIn('slow', function(){
			$(".slider").fadeIn();
			$(".blog").fadeIn(); 
		 });
		}    
	  initPagination('L');
	});
	
});

function navigation(id)
{
  var current = initPagination('S');
  var next_pos, temp;
  var len = jQuery('.block div.slide').length;
  
  if(id < current)
   { 
     temp = current - id;
	 next_pos = current - temp;
     
   }
  else if(id > current)
  {
    temp = id - current;
    next_pos = current + temp;
  }
  else if(id == current) 
    return false;
	
	$('a#'+current).removeClass('nav active').addClass('nav');
	$('a#'+next_pos).removeClass('nav').addClass('nav active'); 
	
   if(next_pos !=0)
   {
	 $('#block-'+current).children(".collapse").removeAttr('id');
	 $('#block-'+current).hide();
	 $('.collapse').hide();
	 if($('#block-'+current+' .slider-title').hasClass('green')) 
	   {
		$('#block-'+current+' .slider-title').removeClass('green');
	   }
	 $('#block-'+next_pos).attr('style','display:block');
	 $('#block-'+next_pos).children(".collapse").attr('id', 'active'); 
	
		if($("#content").hasClass("slider-bg-1")){ 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-1");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		 $("#content").addClass("slider-bg-2");
		 $("#content").fadeIn('slow', function(){
		   $(".slider").fadeIn(); 
		   $(".blog").fadeIn(); 
		 });
		} 
		else { 
		 $("#content").fadeOut('slow', function(){
		   $("#content").removeClass("slider-bg-2");
		   $(".slider").hide();
		   $(".blog").hide();
		 });
		  $("#content").addClass("slider-bg-1"); 
		 $("#content").fadeIn('slow', function(){
			$(".slider").fadeIn();
			$(".blog").fadeIn(); 
		 });
		}
	
   }		
   
}
