$(document).ready(function(){
	
	//var obj = $(".tabs-wrapper").attr("class");
	//if (obj)var select = parseInt(obj.replace(/[^\d]/g, ''))-1;
	
	//if(select)$(".tab:eq("+select+")").addClass("active");
	//else $(".tab:first").addClass("active");
	
	var num = 1;	
	$(".tab:first").addClass("first");
	$(".tab:last").addClass("last");
	$(".first > div.left").css("background-position","0px 0");
	$(".last > div.right").css("background-position","-30px 0");
	
	if(window.location.hash!==""){
		var openTab = parseInt(window.location.hash.slice(1,2))-1;
		$(".tab:eq("+openTab+")").addClass("active");
		//console.log(typeof openTab + " = "+ (openTab+1));
		$(".ul"+(openTab+1)).fadeIn();	
			if(openTab!==0)$(".first > div.left").css("background-position","-24px 0");
			if(openTab==4)$(".last > div.right").css("background-position","-36px 0");
	}else{
		$(".tab:first").addClass("active");
		$(".ul1").fadeIn();	
	}	

	
	
	$(".tab").click(function(){
		 $("#bundle-result").fadeOut();
		if(!$(this).hasClass("active")){
			  num = $(this).index()+1;
			  $(".content-wrapper ul.ul-tab").hide();
			  $(".ul"+num).fadeIn();	
		}
		$(".tab").removeClass("active");
		$(this).addClass("active");
		if($(".first").hasClass("active")){
			$(".first > div.left").css("background-position","0 0");
		}else {$(".first > div.left").css("background-position","-24px 0");}
		if($(".last").hasClass("active")){
			$(".last > div.right").css("background-position","-36px 0");
		}else {$(".last > div.right").css("background-position","-30px 0");}			
	});
	
	$(".content-wrapper ul.ul-tab > li > a").click(function(){
		$("#bundle-result").hide();

		var type = $(this).parents("ul").attr("id");
		var num = $(this).parent().index();
		var url = "http://www.cft.ru/sitePages/bundle/"+type+(num+1)+".aspx";
		
		$.ajax({
		  url: url,
		  context: document.body,
		  success: function(data){
		    $("#bundle-result").html(data);
		  }
		});
		$("#bundle-result").fadeIn();

				
		return false;
		
	});

	
});
