var ev = {}; //Global object for event array
var xhr = {};     

var cms_root = 'http://cms.afghanistan.asiasociety.org/'; 
var addy_year; 
var addy_period;   

var time_url = "http://afghanistan.asiasociety.org/timeline/#/";

//creating era array for prev/next navigation
var eraArr = new Array();  
eraArr.push('age-of-settlement', 'age-of-empire', 'afghanistan-in-the-world', 'afghanistan-today' );

 $(document).ready(function() {	
	
	
    createTicksArray();  
	checkAddress();
	moveTimeline();
    selectEra();  
	revealThemes();
    eventOnState();
    setUpFields();  

             
	// TRANSCRIPT/SOURCE BUTTONS 
	$("#transcript_btn").click(function(){
		$("#transcript").slideToggle("slow");
	});
	
	$("#source_btn").click(function(){
		$("#source").slideToggle("slow");
	});
	

	$('#event_title .next').mouseover(function(){   
		$(this).css({ backgroundPosition:"0px -27px"});
	}).mouseout(function(){
		$(this).css({ backgroundPosition:"0px 0px"});
	});
	
	$('#event_title .prev').mouseover(function(){  
		$(this).css({ backgroundPosition:"0px -27px"});
	}).mouseout(function(){
		$(this).css({ backgroundPosition:"0px 0px"});
	});	 
	
	

});


// TICKS ON  
function eventOnState(){
	$('#ticks').find('span').each(function(){
		
		$(this).click(function(){
		   $('#ticks span').removeClass('on');
			$('.rollover').fadeOut('fast');
		
			$(this).addClass('on');

		});
   });
}                           


function checkScrubberPos(){
	
	var position_scroll = $("#scrubber").position();
}
 

///MOTION


function moveTimeline(){	
	 
       $("#scrubber").draggable({ containment: '#slide', axis: 'x' });  
       
       $('#scrubber').mousemove(function (event){
			
			$('.rollover').fadeOut('fast');  //remove popup if scrolling 
	
 			position_scroll = $(this).position(); 
        
			placeTimeline(position_scroll);
		            
       });


}   

function placeTimeline(position_scroll){

	var xpos_scroll = position_scroll.left;
	eraOn(xpos_scroll);
	
 	if (position_scroll.left <= 95){            //conditional to calculate if date is in pre-history, needs to scroll slower
		var scroll_value = position_scroll.left;
    } 

	else{
	   	var scroll_value = (position_scroll.left - 95)  * 51.25;
	 
	}
   	$('div#timeline').animate({scrollLeft: scroll_value}, 10);     
}

function eraOn(xpos_scroll){
	
	$("div#eras").find("p.active").each( function(){
	  $(this).removeClass('active');
	  $(this).addClass('off');
	  
	});
	
	if (xpos_scroll >= 0 && xpos_scroll <= 508){
		 $('#age-of-settlement').removeClass('off'); 
		
		 $('div#eras p.off').find("span").animate({opacity: 0}, 200);
 		
 		 $('#age-of-settlement').addClass('active'); 
		 $('#age-of-settlement').find("span").stop()
		 $('#age-of-settlement').find("span:not(:animated)").animate({opacity: 1}, 200)
	} 

    else if (xpos_scroll >= 509 && xpos_scroll <= 911){ 
		 $('#age-of-empire').removeClass('off');
		 $('div#eras p.off').find("span").animate({opacity: 0}, 200);
		 
	
	    $('#age-of-empire').addClass('active'); 
		 $('#age-of-empire').find("span").stop()
		 $('#age-of-empire').find("span:not(:animated)").animate({opacity: 1}, 200)
    }      

    else if (xpos_scroll >= 912 && xpos_scroll <= 939){
	
		 $('#afghanistan-in-the-world').removeClass('off');
		 $('div#eras p.off').find("span").animate({opacity: 0}, 200);
	   	 
	     $('#afghanistan-in-the-world').addClass('active');   
		 $('#afghanistan-in-the-world').find("span").stop();
		 $('#afghanistan-in-the-world').find("span:not(:animated)").animate({opacity: 1}, 200);
    } 

    else if (xpos_scroll >= 940){
		 $('#afghanistan-today').removeClass('off');
		 $('div#eras p.off').find("span").animate({opacity: 0}, 200);
		  
	    $('#afghanistan-today').addClass('active');
		 $('#afghanistan-today').find("span").stop();
		 $('#afghanistan-today').find("span:not(:animated)").animate({opacity: 1}, 200);
    } 
       
} 



///////// ERAS  //////////////////////
function selectEra(){
		
   $('.single_era p').click(function (){
			
		$("div#eras").find("p.active").each( function(){
		  $(this).removeClass('active'); 
		  $(this).find("span:not(:animated)").animate({opacity: 0}, 200)
 			
		});  
		
	        var xpos = $(this).attr('id'); 
  			$(this).addClass('active');
   		    passXPos(xpos);	

			var current_era = $(this).attr('id').substr(0);
			
			location.pathname = '/timeline/era/'+current_era;
		}); 
	
} 

function revealEraSumm(era_title){
			
	switch (era_title){
		case 'age-of-settlement':
			era_id = 38 ;
			break;
		case 'age-of-empire':
			era_id = 39;
			break;
		case 'afghanistan-in-the-world':
			era_id = 41;
			break; 
		case 'afghanistan-today':
			era_id = 40;
			break; 
	}
	
	passXPos(era_title)
	
	 $('#'+era_title).removeClass('off');
	 $('#'+era_title).find("span").animate({opacity: 0}, 200);
	  
	 $('#'+era_title).addClass('active');
		  
	 $('#'+era_title).find("span").stop()
	 $('#'+era_title).find("span:not(:animated)").animate({opacity: 1}, 200)
}
 

function passXPos(era_pos){
	 		
	switch (era_pos){
		case 'age-of-settlement':
			s_pos = 0 ;
			break;
		case 'age-of-empire':
			s_pos = 508;
			break;
		case 'afghanistan-in-the-world':
			s_pos = 912;
			break; 
		case 'afghanistan-today':
			s_pos = 940;
			break; 
	}
	
    var change_scroll = (s_pos- 95) * 51.25;

    $('div#timeline').animate({scrollLeft: change_scroll}, 400, 'easeOutCirc');
	
    $('#scrubber').css({left:s_pos});
	 	
}   

 
////////// THEMES ///////////////
function revealThemes(){
	
    $("#theme_btn").click(function () {
	
	  if ($(this).hasClass('btn_close')){
		  $(this).removeClass('btn_close');
		}
	  else {
		  $(this).addClass('btn_close');
		}            
		
      $("#theme_wrapper").slideToggle("slow"); 
      $("#theme_summary p.on").slideToggle("slow");

	  return false;
    });
}  

function revealThemeDescription(){
	
		$('div#theme_titles p.btn').unbind('click'); //removes deeplinking action for themes
	 
	  	$('div#theme_titles. p.btn').click(function(){
					
				var theme_id = $(this).attr('id'); 
				
				revealTickThemes(theme_id);    //pass theme id to activate coorosponding ticks						
			    themeOff(); 
			
			    $(this).removeClass('off').addClass('on'); 
				
				themeDrawerActions(theme_id);
				
				//setAddress('');	  
		});

 }

function themeDrawerActions(theme_id){
	
	$('#theme_summary p').removeClass('on');
	$('#theme_summary p').fadeOut('normal'); 

    $('p#sum_'+theme_id).addClass('on');  

	$('#theme_summary p.on').fadeIn('normal');
	
	themeOff(); 
	$('div#theme_titles p#'+theme_id).removeClass('off').addClass('on');
}

function themeOff(){  
	
	  $("div#theme_titles").find("p.on").each( function(){
			
	  	$(this).removeClass('on').addClass('off');  

	  });
	   
}


//open theme drawer based on address
function openThemeDrawer(theme){
	
	switch (theme){
		case 'geography+destiny':
			theme_title = 'g-d' ;
			break;
		case 'identity+perception':
			theme_title = 'i-p' ;
			break;
		case 'tradition+modernization':
			theme_title = 't-m' ;
			break; 
		case 'traces+narratives':
			theme_title = 't-n' ;
			break; 
	}
	
	
	  if ($("#theme_btn").hasClass('btn_close')){
		
	  }else{
		  $("#theme_btn").addClass('btn_close');
		  $("#theme_wrapper").slideToggle("slow"); 
	    
	  }

	  $('p.btn ').removeClass('on');
	   
	  $('#theme_titles p#'+theme_title).removeClass('off');
	  $('#theme_titles p#'+theme_title).addClass('on');
	  
	  $('#theme_summary p').removeClass('on');
	  $('#theme_summary p').css('display', 'none');
	  
      
	  $('p#sum_'+theme_title).addClass('on');  
	  $('p#sum_'+theme_title).css('display', 'block'); 

   	   revealTickThemes(theme_title);    //pass theme id to activate coorosponding ticks

	   // return false;
	
}

function detailThemeReveal(){
	    
	  $('span.theme_list').find('p')
	    .each(function(){ 
		
			$(this).click(function(){			
		
			var detail_theme_id = $(this).attr('rel'); 
				
				$("#theme_btn").removeClass('btn_close');
		        $("#theme_wrapper").slideDown("slow");
				
				themeDrawerActions(detail_theme_id);
			})
		})
	
}

function revealTickThemes(id){ 
	
		$("#ticks").find("span.theme_on").each( function(){
		  $(this).css({backgroundPosition:"0px 0px"});   
		  $(this).removeClass('theme_on');   

		});  
	
	  	$('#ticks .tick_'+id).addClass('theme_on');   
           $('#ticks .tick_'+id).css({backgroundPosition:"0px -12px"});
}




// ///////// PREV/NEXT BUTTONS /////////////////    


//CREATE ARRAY OF TICK Y POS FOR PREV/NEXT FUNCTION
function createTicksArray(){
		 
		   var eventArr = new Array();

		   $('#ticks').find("p.inline span").each( function(){
			
				function sortNumbers(a,b) //sort asending based on number of ypos
					{
						return a - b;
					}
			
				var yearYPos =  $(this).css('left');
			 	var yearOrder = yearYPos.replace('px', '');

				eventArr.push(yearOrder);
				eventArr.sort(sortNumbers);

			}) 
			
			ev.eventOrder = eventArr; 

	}   
	
	
function setupPrevNext(y, p){  
	
            var eventIndex; // clear this value each time
			$('#ticks').find("p.inline span."+p).each( function(){   //avoid duplicate years in different periods
				  if ( $(this).is('#'+y) ){
					     current_tick = $(this);
				  }
				
			})
   
			//Find placement of event ticks to calculate prev next navigation
			var currentEventYPos =  current_tick.css('left');
	 		c = currentEventYPos.replace('px', '');

			var a = ev.eventOrder.length;
            
			    for(var i=0; i<a; i++){

					if( ev.eventOrder[i] == c){ 										
						eventIndex = i; 
					} 
				}   
				  
				return eventIndex;
}  
	
	
function gotoPrev(pe){

	    orderE = ev.eventOrder[pe]+'px';  

		$('#ticks p').find('span').each( function(){  
			 if ( $(this).css('left') ==  orderE ) {
				
					var id = $(this).parent().attr('id');
					var p = $(this).attr('rel');
					var y = $(this).parent().attr('rel').substr(0);
									
					location.pathname = '/timeline/'+id+'/'+p+'/'+y;
			}
		}) 

}

function gotoNext(ne){ 

	 $('#ticks').find("p span").each( function(){
		orderE = ev.eventOrder[ne]+'px';

			if ( $(this).css('left') == orderE){
				
				var id = $(this).parent().attr('id');
				var p = $(this).attr('rel');
				var y = $(this).parent().attr('rel').substr(0);
								
				location.pathname = '/timeline/'+id+'/'+p+'/'+y;
			}
	  })   
}


// Prev/Next Eras

function gotoPrevEra(pe){


}

function gotoNextEra(pe){

	    orderE = ev.eventOrder[pe]+'px';  

		$('#ticks p').find('span').each( function(){  
			 if ( $(this).css('left') ==  orderE ) {
				
					var id = $(this).parent().attr('id');
					var p = $(this).attr('rel');
					var y = $(this).parent().attr('rel').substr(0);
									
					location.pathname = '/timeline/'+id+'/'+p+'/'+y;
			}
		}) 

}

function setAddress(newAddress){
	   $.address.value(newAddress);
}

function setThemeAddress(){
	$('div#theme_titles p.btn').click(function(){

		var theme_id = $(this).attr('id');
		var theme_addy = $(this).attr('rel');      
		
		setAddress('theme/'+theme_addy);	  //pass atributes to address 
		revealThemeEvent();
	
	});  
}

function revealThemeEvent(){
	$('#theme_titles').find('p').each( function(){

		if( $(this).hasClass('on') ){
			var button_theme = $(this).attr('rel');

			switch (button_theme){ //set events to call for each theme by year and period
				case 'geography+destiny':
			 			p = 'BCE';
						y = '600';
						fb_url = button_theme;
						break; 
				case 'identity+perception':
			 			p = 'CE';
						y = '1736';
						fb_url = button_theme;
						break;
				case 'tradition+modernization':
			 			p = 'CE';
						y = '1818';
						fb_url = button_theme;
						break;
				case 'traces+narratives':
			 			p = 'BCE';
						y = '2000';
						fb_url = button_theme;
						break;
			}
			
			//revealField(p,y);
			sendAjaxThemeEvent(p,y,fb_url);
			
		}


	})
}

			
//REVEAL FIELDS BASED ON URL
function checkAddress(){   
		
	   var path = location.pathname.split( '/' );;  //break apart path 
		
	   addy_id = path[2]; 
	   addy_period = path[3];  
  	   addy_year = path[4];	

		if(addy_id == 'era'){ 			
			revealEraSumm(addy_period);
			revealThemeDescription();
			
			  $('.single_era').find("p").each( function (){
				if ($(this).hasClass("active")){
					var era_id = $(this).attr('id');
					var i = 0; 
					for (i=0; i<4; i++){
						if (eraArr[i] == era_id){
							var p = i - 1;
							eraPrev = eraArr[p];
							var n = i + 1;
							eraNext = eraArr[n];
							
							$('#event_title .prev').click(function(){  
								if(eraPrev == undefined){
								}else{
									location.pathname = '/timeline/era/'+eraPrev;
								}
							});             

							$('#event_title .next').click(function(){  
								if(eraNext == undefined){
								}else{ 
								location.pathname = '/timeline/era/'+eraNext;
								}
							});

						}
					}

				}
			})
			// PREV/NEXT BUTTONS

		}
		
		else if ((addy_period == 'BCE') || (addy_period == 'CE')){ 
		    revealThemeDescription();
		    revealField(addy_period, addy_year);
		
		    // PREV/NEXT BUTTONS
			$('#event_title .prev').click(function(){  
				prevEvent = setupPrevNext(addy_year, addy_period) - 1;
				gotoPrev(prevEvent);
			});             

			$('#event_title .next').click(function(){   
				nextEvent = setupPrevNext(addy_year, addy_period) + 1;
				gotoNext(nextEvent);

			});
		}
		
		else if(addy_period == null){
			
			$.address.change(function() { 
				handleAddressChange(); 
			});  //address for theme urls.

		}
	
}

//REVEAL FIELDS BASED ON URL
function handleAddressChange(){   
		
	   var path = $.address.pathNames();  //break apart path 
	
	   theme = path[0];  
  	   addy_period = path[1];

	   if(theme == 'theme'){
			
			setThemeAddress();
			openThemeDrawer(addy_period);
			revealThemeEvent();
		}
		
}   



 
// SET UP DEEP LINKING FOR TICK CLICKS
function setUpFields(){
	 $('#ticks').find("p").each( function(){
	 	   	     $(this).click(function() { 
		
						var click_p = $(this).find("span").attr('rel');
						var click_y = $(this).attr('rel').substr(0);
						var id = $(this).attr('id');
						
						location.pathname = '/timeline/'+id+'/'+click_p+'/'+click_y;
										
						
	 					$('#source').css('display', 'none');
	 					$('#transcript').css('display', 'none');
	
					})
	 })   
	
	detailThemeReveal(); // call here so json is in place first
	
}
	
	
//// JSON AND TIMELINE HOOKUP ///////////////////   

function revealField(p, y){ 
	
	    var eventArr = new Array();  
		
		$('#timeline_main .node').css('display', 'block');
		
	
		$('#era_summ').find('div').each( function(){
			$(this).css('display', 'none');				
		})
	 
        $('#ticks span').removeClass('on');
		$('#ticks #'+y).addClass('on'); 		 
		
		 if(p == 'BCE'){ 
			
			if( y <2500) {
				var pos_scrubber = 575 - (y*.188);
	
			}
			else{
				var pos_scrubber = (100 - (y/1000));
			}
			
			 moveScrubber(pos_scrubber);
		   	 eraOn(pos_scrubber);
           	
		}else if (p == 'CE'){
			var pos_scrubber = 575 + (y*.184); 
			moveScrubber(pos_scrubber);
			eraOn(pos_scrubber);
		}
		
		function moveScrubber(pos_scrubber){

			$('#scrubber').animate({
									left: pos_scrubber+"px"
									}, 
									{
										duration: 1000, 
										easeing: 'easout',
										step: function(currentLeft){
										var scroll_value = (currentLeft - 95)  * 51.25;
										$('div#timeline').scrollLeft(scroll_value);   
										}
									}
									);
		}
		
} 

function sendAjaxThemeEvent(p, y, fb_url){
		
	$('#ticks').find("p").each( function(){ 
				
      if (($(this).attr('rel') == y) && ($(this).find('span').attr('rel') == p)) { //use the year and period to get correct id
			
		 	var id =  $(this).attr('id'); 
		  	var jsonUrl = '../inc/event-json.php?Nid='
			callAjaxThemeEvent(id, jsonUrl, fb_url);
			 
			}   //end conditional
				
		});
}


function callSocial(year, period, fb_url){ // for themes

		$('#fb_counter').load('../inc/social.php?fburl='+fb_url, function() {

		});
		
}

function setMeta(title, description){
			$("meta[name='og:title']").attr("content", title);
			$("meta[name='ogdescription']").attr("content", description);
}

function callAjaxThemeEvent(id, jsonUrl, fb_url){
		
		var xhr = $.ajax({
			url : jsonUrl+id,
			dataType: 'json',
			success: function(data){ 
				
				//EVENTS /////////
				
					
					
					var currentid 		 = data.nodes[0].node.Nid;
					var title 			 = data.nodes[0].node.Title;
					var year 	   		 = data.nodes[0].node.Year;  
					var period	   		 = data.nodes[0].node.Period;   
					var mediaType  	     = data.nodes[0].node.MediaType; 
					var videoUrl		 = data.nodes[0].node.VideoURL; 

					var videoTranscript  = data.nodes[0].node.VideoTranscript;

					var videoThumb       = data.nodes[0].node.VideoThumbnail;

					var imagePath        = data.nodes[0].node.ImagePath; 
					var themes           = data.nodes[0].node.Allterms; 
					var source           = data.nodes[0].node.Source;     
					var description      = data.nodes[0].node.description;

					var material1        = data.nodes[0].node.RelatedTitle1; 
					var material2        = data.nodes[0].node.RelatedTitle2; 
					var material3        = data.nodes[0].node.RelatedTitle3; 
					var material4        = data.nodes[0].node.RelatedTitle4; 

					var materialsArr = new Array(material1, material2, material3, material4); //place related materials in array
					
					callSocial(year, period, fb_url);
					
					
					$("#event_title .right_pos").css('margin-left', '140px')
	
					$("#event_title #thumb_title").html('<img id="title_img" src="'+cms_root+imagePath+'" />') ; 
				
			    	$("#event_title h1").html(title+' '); 
					$("#event_title").attr('title', title);
			
					Cufon.replace('h1');
				
			   		$("#event_yr").html('CIRCA '+year+' '+period) 
			
					$("#event_themes").css('height', '12px');
					$("#event_themes").empty(); //remove previous event themes
					
				
					$("#event_themes").html('<span class="red">THEMES: </span>'); 
				
					var themeArr = themes.split(", "); // seperate themes at comma bc they are all contained in one field
				
				
					$.each( themeArr, function(i, theme_item){
						
					
							switch (theme_item){
							
								case 'Geography & Destiny':
									theme_title = 'g-d' ;
									break;
								case 'Identity & Perception':								
									theme_title = 'i-p' ;									
									break;
								case 'Tradition & Modernization':
									theme_title = 't-m' ;
									break; 
								case 'Traces & Narratives':
									theme_title = 't-n' ;
									break; 
							}										
						
						   $("#event_themes").append('<span class="theme_list"><p rel="'+theme_title+'">'+theme_item+'</p> </span>'); 
						
					}) 
					
					
					detailThemeReveal(); // call here so json is in place first
				
					$("#event_themes").css('display', 'block');
					Cufon.replace('#event_themes', {
						hover: true,
						hover: { color: '#fff'},
						hoverables: { p: true}
						})
						
					Cufon.replace('span')

					if(mediaType == 'Video'){ 
						
						  $('#lft_col').html('<div id="media" class="field"></div>');
						

					       var so = new SWFObject('../jwplayer/Player_5.0.swf','mpl','640','388','9');
					       so.addParam('allowfullscreen','true');
					       so.addParam('allowscriptaccess','always');
					       so.addParam('wmode','opaque');
				           so.addParam('bgcolor', '#292322');  
						    so.addParam('flashvars','skin=../jwplayer/style.zip&dock=false&controlbar.position=bottom&image='+cms_root+videoThumb+'&viral.functions=embed,link&file='+videoUrl); 
					       
					       so.addVariable('plugins', 'gapro-1', 'viral-2');
					       so.addVariable('gapro.accountid','UA-3032279-1');
					       so.addVariable('gapro.trackstarts','true');
					       so.addVariable('gapro.trackpercentage','true');
					       so.addVariable('gapro.tracktime','true');
				    
					      so.write('media');   
						// 
						// $("#transcript").empty();
						// $("#transcript").html(videoTranscript);
						

					}   
					else if(data.nodes[0].node.MediaType == 'Image'){
						$("#media").html("Image: "+imagePath+"<br>");
					}  

				$('#source_btn').remove();

				if(source){
					
				$('#lft_col').append('<div id="source_btn"><img src="../img/timeline/source_btn.gif" width="642" height="26" alt="Reveal Source"></div>	<div id="source" class="field source_off"> <p>'+source+'</p></div>');  
				}
				
				$("#source_btn").click(function(){
					$("#source").slideToggle("slow");
				});
				
				$('#transcript_btn').remove();	
				
				if(videoTranscript){					
				$('#lft_col').append('<div id="transcript_btn"><img src="../img/timeline/transcript_btn.gif" width="642" height="26" alt="Reveal Transcript"></div><div id="transcript" class="field transcript_off">'+videoTranscript+'</div>')     
				}
				
				$("#transcript_btn").click(function(){
					$("#transcript").slideToggle("slow");
				});


				$('#related_material').remove();
				if (material1){
				   $('#rt_col').prepend('<div id="related_material" class="field"></div');
				}
				
				$('#description').remove();
				if(description){
				   $('#rt_col').prepend("<div id='description'> <p>"+description+"</p></div>");  					
				}

			
		       $("#facebook").empty();
			   $("#facebook").html('<meta name="description" content="'+description+'" /><link rel="image_src" href="'+videoThumb+'" />');
			
			   $("#related_material").html(data.nodes[0].node.RelatedTitle4+"<br>"); 
			   $("#related_material").empty();  //empty div first to remove previous elements appended   
			   $("#related_material").css({'background-color': '#1c1714' , 'padding' : '10px' });
			   $("#related_material").append("<h2><img src='../img/timeline/materials_title.gif'/></h2>");    
			
				
			                      
				$.each( materialsArr, function(i, item){
				   if(item != ''){
						closeHref = item.indexOf("\">"); //find index of closing href
						relatedID = item.slice(15, closeHref);	//get id number from node id in href									
						
						$.ajax({  //pass a new json node id of related material
				
							url : "../inc/event-json.php?Nid="+ relatedID,
							dataType: 'json', 
							success: function(relatedData){  
								var r_id = relatedData.nodes[0].node.Nid;
								var r_title = relatedData.nodes[0].node.Title;
								var r_period = relatedData.nodes[0].node.Period;
								var r_year = relatedData.nodes[0].node.Year; 
								var r_thumb = relatedData.nodes[0].node.ImagePath; 
								
								
								$("#related_material").append('<div class="related_item" ><a href="/'+r_id+'/'+r_period+'/'+r_year+'"><img src="'+cms_root+r_thumb+'" /></a> <p><a href="/'+r_id+'/'+r_period+'/'+r_year+'">'+r_title+'</a></p></div>');
							  
							} 
						})
						
					}     
				});  
				
				
				
				setMeta(title, description);
			   	  
								
				$(document).attr('title', title+' CIRCA '+year+' '+period+' | Timeline | Homeland Afghanistan');
				$(document).attr('description', description);
			
		  	 }
		     
		
		})   //end ajax
	}    
               

        
   


       

  
   


