$(document).ready(function(){
	
	var pathname = window.location.pathname;
	//alert(pathname);
	if(pathname == '/educomp/user')
	    $('.tabs.primary li:first').hide();
	//	alert
	
	//alert(base_path);
	//@Sandip remove the parent menu item links except about us.
	  $("li.menuparent > a").removeAttr("href");
	// $("li.menuparent > a").eq(0).attr("href", "about-us");
	  $('#location-city').change(function() {
  		setTimeout("$('.search-tab1').width($('#location').width())",500);
	});
	 
	 setTimeout("$('.anim-banner').fadeOut('slow')",3800);
	// alert(Drupal.settings.basePath);
 	$('.homebanner-menu a:first').addClass("menuselect");
	var clickr=$('.homebanner-menu a');
	var getBlocks= $('.homebanner-img');    
	$(getBlocks[0]).show();    
	$('.homebanner-menu a').click(function(){		
		var getIndex = $(clickr).index(this);
		$('.anim-banner:eq('+getIndex+")").show();
		$('.homebanner-menu a').removeClass('menuselect');
		$(this).addClass('menuselect');
		$(getBlocks).hide();
		$(getBlocks[getIndex]).fadeIn();
		setTimeout("$('.anim-banner').fadeOut('slow')",3800);
	});
	
	
	$('.slide-details:first').clone().appendTo('#slides');
	$(".myController").jFlow({
		slides: "#slides",
		controller: ".jFlowControl", // must be class, use . sign
		slideWrapper : "#jFlowSlide", // must be id, use # sign
		selectedWrapper: "jFlowSelected",  // just pure text, no sign
		auto: true,		//auto change slide, default true
		width: "210px",
		height: "175px",
		duration: 1000,
		prev: ".jFlowPrev", // must be class, use . sign
		next: ".jFlowNext", // must be class, use . sign
		loop:true
	});
	
//	$('.slide-details:first').clone().appendTo('#slides-locate');
//	$(".myController-locate").jFlow({
//		slides: "#slides-locate",
//		controller: ".jFlowControl-locate", // must be class, use . sign
//		slideWrapper : "#jFlowSlide-locate", // must be id, use # sign
//		selectedWrapper: "jFlowSelected-locate",  // just pure text, no sign
//		auto: false,		//auto change slide, default true
//		width: "210px",
//		height: "105px",
//		duration: 1000,
//		prev: ".jFlowPrev", // must be class, use . sign
//		next: ".jFlowNext", // must be class, use . sign
//		loop:false
//	});
	
	$('.slide-details:first').clone().appendTo('#slides-right');
	$(".myController-right").jFlow({
		slides: "#slides-right",
		controller: ".jFlowControl-right", // must be class, use . sign
		slideWrapper : "#jFlowSlide-right", // must be id, use # sign
		selectedWrapper: "jFlowSelected-right",  // just pure text, no sign
		auto: true,		//auto change slide, default true
		width: "210px",
		height: "175px",
		duration: 1000,
		prev: ".jFlowPrev", // must be class, use . sign
		next: ".jFlowNext", // must be class, use . sign
		loop:true
		
	});
			
		
	//tabs kids
	$(".kids-action").hide(); //Hide all content
	$("ul.tab li a:first").addClass("active-tab").show(); //Activate first tab
	$(".kids-action:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tab li a").click(function() {
		$("ul.tab li a").removeClass("active-tab"); //Remove any "active" class
		$(this).addClass("active-tab"); //Add "active" class to selected tab
		$(".kids-action").hide(); //Hide all tab content
		var activeTab = $(this).attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	function setBlock(selector, wrapper, numBlocks){
				var num=$(selector), wrapx=[];
				for (m=0; m<num.length; m+=numBlocks)
				{
				for(var i=0, n=m; i<numBlocks; i++, n++)
				{
				wrapx[i]=num[n];
				}
				$(wrapx).wrapAll(wrapper);
				}
			}
		setBlock('.ad-thumb li','<ul />', 5);
		setBlock('.petal-content li','<ul />', 1);
		setBlock('.incontent li','<ul />', 1);
		$(".gallery,.petal-box-gallery,.content-tips").scrollable({size: 1, speed:1000, clickable:false, next:'.next-ad', prev:'.prev-ad'});
		
		
		
  /* ROOUNDIES EXAMPLE */
  /* varying radii, "all" browsers */
  DD_roundies.addRule('ul.tab li a', '10px 10px 0px 0px', true);
  
		$("#accordion").accordion({
			collapsible: true
		});
		
		$("#slider").easySlider({
				auto: true,
				continuous: true 
			});
		$("#slider1").easySlider({
				auto: true,
				continuous: true 
			});
		
	  	var $tabs = $('#tabs').tabs();

		$(".ui-tabs-panel").each(function(i){

		  var totalSize = $(".ui-tabs-panel").size() - 1;

		  if (i != totalSize) {
		      next = i + 2;
	   		  $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
		  }
  
		  if (i != 0) {
		      prev = i;
	   		  $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
		  }
	
		});

		$('.next-tab, .prev-tab').click(function() { 
	           $tabs.tabs('select', $(this).attr("rel"));
	           return false;
	       });

	
	//Event page State city
	$("#edit-field-event-state-value").change(function (){
		var st_val = $("#edit-field-event-state-value").val();
		if(st_val == '')
			$("#edit-field-event-city-value-wrapper").hide();
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="-1">Select City</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.tid + '">' + row.name + '</option>';
				});
				$("#edit-field-event-city-value").html(optionsValues);
			}); 
	});
	//center page State city
	$("#edit-field-center-state-value").change(function(){
		// alert("Event Fired..");
		var st_val = $("#edit-field-center-state-value").val();
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select City</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.tid + '">' + row.name + '</option>';
				});
				$("#edit-field-center-city-value").html(optionsValues);
	 	}); 
	});
	
	//Admission Form Select City
	/*var getID=document.location.href.split('/');
	getID=getID[getID.length-1];
	alert(getID);
	if(getID == "221")
	{ 
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			//state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select City</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
				});
				$("#sl_city").html(optionsValues);
	 	}); 
		
		//State For Admission Form
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			onlyState:1
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select State</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.tid + '">' + row.name + '</option>';
				});
				$("#sl_state").html(optionsValues);
	 	}); 
		
	}*/
	
	//Event Search Page Select City
	/*if(getID == "219")
	{ 
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			//state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select City</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
				});
				$("#SelCity").html(optionsValues);
	 	}); 
		$.getJSON(Drupal.settings.basePath+"get_centers.ajax",{
			//city:ct_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select Location</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.title + '">' + row.title + '</option>';
				});
				$("#SelLocation").html(optionsValues);
	 	}); 
	}*/
	//Admission Form
	var city,locatestate,locatestate1,country;
	
	country=$('#edit-submitted-country').val();
	city=$('#edit-submitted-select-city-select').val();
	
	//admission country
	if(country == "")
	{
		$('#edit-submitted-select-city-select').html('<option>Select City</option>');
		$('#edit-submitted-select-center').html('<option>Select</option>');
	}
		
	//admission city
	if(city == "")
	    $('#edit-submitted-select-center').html('<option>Select</option>');
	//$("#dob").datepicker();
	//------------------------------------------------------------
	
	//Franchisee Enquiry Form
	country=$('#edit-submitted-franchisee-country').val();
	if(country == "")
	{
		$('#edit-submitted-state-select').html('<option>Select State</option>');
		$('#edit-submitted-city-select').html('<option>Select City</option>');
	}	
	city=$('#edit-submitted-locate-state').val();
	if(city == "")
	    $('#edit-submitted-locate-city-select').html('<option>Select</option>');
	
	locatestate=$('#edit-submitted-contactdetails-locate-state').val();
	if(locatestate == "")
	   $('#edit-submitted-contactdetails-locate-city-select').html('<option>Select</option>');
	
	locatestate1=$('#edit-submitted-state').val();
	if(locatestate1 == "")
	   $('#edit-submitted-city').html('<option>Select</option>');
	
	
	//City For Admission Form
	$("#edit-submitted-locate-state").change(function(){
		var st_val=$("#edit-submitted-locate-state").val();
		//alert(st_val);
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select City</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
				});
				$("#edit-submitted-locate-city-select").html(optionsValues);
	 	}); 
	});
	
	$("#edit-submitted-state").change(function(){
		var st_val=$("#edit-submitted-state").val();
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				var zone_email="";
				optionsValues += '<option value="">Select City</option>';
				
				$(data).each(function(i,row){
					if(i<data.length-1)
					{
						optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
					}
				});
				optionsValues += '<option value="select_or_other">Other...</option>';
				zone_email=data[data.length-1];
				$('#edit-submitted-email-to').val(zone_email);
				$("#edit-submitted-city").html(optionsValues);
				
	 	}); 
	});
	$("#edit-submitted-state-select").change(function(){
		var st_val=$("#edit-submitted-state-select").val();
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				var zone_email="";
				optionsValues += '<option value="">Select City</option>';
				
				$(data).each(function(i,row){
					if(i<data.length-1)
					{
						optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
					}
				});
				optionsValues += '<option value="select_or_other">Other...</option>';
				zone_email=data[data.length-1];
				//alert(zone_email);
				$('#edit-submitted-email-to').val(zone_email);
				$("#edit-submitted-city-select").html(optionsValues);
				
	 	}); 
	});
	
	
	
	//Admission Form Select Center List
	$("#edit-submitted-contactdetails-locate-state").change(function(){
		var st_val=$("#edit-submitted-contactdetails-locate-state").val();
		$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
			state:st_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select City</option>';
				$(data).each(function(i,row){
					if(i<data.length-1)
					{
						optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
					}
				});
				optionsValues += '<option value="select_or_other">Other...</option>';
				$("#edit-submitted-contactdetails-locate-city-select").html(optionsValues);
	 	}); 
	});
	
	$("#edit-submitted-select-city").change(function(){
		// alert("Event Fired..");
		var ct_val = $("#edit-submitted-select-city").val();
		//alert(ct_val);
		$.getJSON(Drupal.settings.basePath+"get_centers.ajax",{
			city:ct_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select Center</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.nid + '">' + row.title + '</option>';
				});
				$("#edit-submitted-select-center").html(optionsValues);
	 	}); 
	});
	
	//******************************START*******Admission page**************************/
	$("#edit-submitted-country").change(function(){
		var country_val = $("#edit-submitted-country").val();
		if(country_val == "India "){
			$('#webform-component-select_city').css("display","block");
			$('#webform-component-select_center').css("display","block");
			$.getJSON(base_path+"get_city.ajax",{
				//country:country_val
				},function(data){
					var optionsValues = "";
					optionsValues += '<option value="">Select City</option>';
					$(data).each(function(i,row){
						if(i<data.length-1)
						{
							optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
						}
				//	optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
					});
					optionsValues += '<option value="select_or_other">Other...</option>';
					$("#edit-submitted-select-city-select").html(optionsValues);
					//$('#edit-submitted-zone-email').val("emailid");
		 	});
		}
		else
		{
			$('#edit-submitted-select-city-select').html('<option>Select City</option>');
			$('#edit-submitted-select-center').html('<option>Select</option>');
			$('#edit-submitted-select-city-select').val("");
			$('#edit-submitted-select-center').val("");
			$('#webform-component-select_city').css("display","none");
			$('#webform-component-select_center').css("display","none");
		}
	});
	//***************************END***********************************/
	
	//******************************START*******Franchisee page**************************/

	$("#edit-submitted-franchisee-country").change(function(){
		var country_val = $("#edit-submitted-franchisee-country").val();
		var onlyState;
		if(country_val == "India "){
			$('#webform-component-state').css("display","block");
			$('#webform-component-city').css("display","block");
			$.getJSON(Drupal.settings.basePath+"get_city.ajax",{
				onlyState:1
				},function(data){
					var optionsValues = "";
					optionsValues += '<option value="">Select State</option>';
					$(data).each(function(i,row){
					optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
					});
					$("#edit-submitted-state-select").html(optionsValues);
		 	}); 
		}
		else
		{
			$('#edit-submitted-select-city-select').html('<option>Select State</option>');
			$('#edit-submitted-city-select').html('<option>Select City</option>');
			$('#edit-submitted-select-city-select').val("");
			$('#edit-submitted-city-select').val("");
			$('#webform-component-state').css("display","none");
			$('#webform-component-city').css("display","none");
		}
	});
	//State For Admission Form
	
	//******************************END*******************************/
	
	//Our Location Page	
	$("#edit-submitted-select-city-select").change(function(){
		// alert("Event Fired..");
		var ct_val = $("#edit-submitted-select-city-select").val();
		//alert(ct_val);
		$.getJSON(Drupal.settings.basePath+"get_centers.ajax",{
			city:ct_val
			},function(data){
				var optionsValues = "";
				var zoneemail = "";
				optionsValues += '<option value="">Select Center</option>';
				$(data).each(function(i,row){
					optionsValues += '<option value="' + row.nid + '">' + row.title + '</option>';
					zoneemail=row.email;
				});
			//	alert(zoneemail);
				$("#edit-submitted-zone-email").val(zoneemail);
				$("#edit-submitted-select-center").html(optionsValues);
	 	}); 
	});
	
	
	//Our Location Page
	$.getJSON(base_path+"get_city.ajax",{
		//state:st_val
		},function(data){
			var optionsValues = "";
			optionsValues += '<option value="">Select City</option>';
			$(data).each(function(i,row){
				if(i<data.length-1)
				{
					optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
				}
		//	optionsValues += '<option value="' + row.name + '">' + row.name + '</option>';
			});
			optionsValues += '<option value="select_or_other">Other...</option>';
			$("#location-city").html(optionsValues);
 	});
	
	//Location According to City Selection 
	$("#location-city").change(function(){
		// alert("Event Fired..");
		var ct_val = $("#location-city").val();
		//alert(ct_val);
		$.getJSON(base_path+"get_centers.ajax",{
			city:ct_val
			},function(data){
				var optionsValues = "";
				optionsValues += '<option value="">Select Center</option>';
				$(data).each(function(i,row){
				optionsValues += '<option value="' + row.title + '">' + row.title + '</option>';
				});
				$("#location").html(optionsValues);
	 	}); 
	});
	 
	
	//Locate Center //Select center // Google Map 
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
	
	$('#location').change(function(){
		var location_val = $("#location").val();
		$('.location-search-result').css('display','block');
		$.getJSON(Drupal.settings.basePath+"get_latlong.ajax",{
			location:location_val
			},function(data){
				//alert(data);
				var address = "";
				var addressshow = "";
				var testimonials = "";
				var testipagination = "";
				var testi = Array();
				var b = data.address;
				var temp = new Array();
				temp = b.split(',');
				
				for (var i=0; i < temp.length; i++)
					addressshow +='<span>'+ltrim(temp[i])+'</span>,<br/>';
				
				addressshow=addressshow.substring(0, addressshow.length-6);
				
				//alert(addressshow);
				var uid = data.uid;
					address += data.location + "," + data.city + "," + data.state;
					//Center Address
					$('#center-tabs li:eq(0)').html(
						'<h4>Centre <span>address</span></h4>'+addressshow+',<br/>'+ data.city +","+data.state+"-"+data.pincode 
					);
					//center Timings
					$('#center-tabs li:eq(1)').html(
						'<h4>Centre <span>timings</span></h4><span>Session I</span><br />'+data.weekdays.substring(0,34)+'<br /><span>Session II</span><br />'+data.weekend
					);
					//Contact 
					$('#center-tabs li:eq(2)').html(
							'<h4>Centre <span>contact</span></h4><span>LANDLINE</span><br />'+data.landline+'<br /><span>MOBILE</span><br />'+data.mobile
					);
					//Status Message for center
					//alert(data.news.length);
					if(data.news.length > 0)
					{
						$(".testimonial-locate-news").css('display','block');
						$('#locate-news').html(
							'<h4>latest centre news</h4>'+'<p class="loctxt">'+data.news+'<p class="loctxt">Contact center for more info.</p>'
				        );
					}
					else
					{
						$(".testimonial-locate-news").css('display','none');
					}
					//Get All testimonials
					//$("#jflow-content-slider").text('');
					$("#slides-locate").text('');
					$("#testi-pegination").text('');
					//alert(data.testimonials.length);
					if(data.testimonials.length > 0)
					{
						//$(".testimonialbox-main").css('display','block');
						//testimonials += '<div id="slides-locate">';
						$(data.testimonials).each(function(i,row){
							//alert(row.testi);
							//row.title   <li class="jFlowControl-locate">1</li>
							testimonials += '<div class="slide-details">'+
				                  '<h2>'+row.title+'</h2>'+
				                    '<div class="description">'+row.testi+'</div>'+
				                  '</div>';
						});
						//testimonials += '</div>';
							$(data.testimonials).each(function(i,row){
								//alert(row.testi);
								//row.title
								j = i+1;
								testipagination += ' <li class="jFlowControl-locate">'+j+'</li>';
							
							});
							
						//Replace Testimonials
						//$("#jflow-content-slider").html(testimonials);
						//	alert(testimonials);

						$(".testimonial-floater").html(testimonials);
						$("#testi-pegination").html(testipagination);
					}else
					{
						
						$('.scrollable-thing').css('display','none');
						//$('.testimonialbox-main').css('display','none');
					}
					
					if(data.news.length <= 0 && data.testimonials.length <= 0)
					{
						$('.testimonialbox-main').css('display','none');
					}
					
					//Locating marker on google map
					codeAddress(address);
					//configure the url for event search
					$("a.Myevents").attr("href", Drupal.settings.basePath+"event-search?uid="+uid);
					$("a.Mygallery").attr("href", Drupal.settings.basePath+"center-gallery?uid="+uid);
					
					$('#user-id').val(uid);
	 	}); 
		
	});
	 
	//Google map according to address
	  function codeAddress(address) {
		 //  alert(address);
		    geocoder.geocode( { 'address': address}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		        map.setCenter(results[0].geometry.location);
		        var marker = new google.maps.Marker({
		            map: map, 
		            position: results[0].geometry.location
		        });
		      } else {
		        alert("Geocode was not successful for the following reason: " + status);
		      }
		    });
		  }
	  
	  $('#webform-client-form-222.webform-client-form').wrap(function(){return '<div id="franchisee-form"></div>'});
	  $('#franchisee-form').prepend('<p> Franchisee Enquiry Form </p>');
	  
	  //Event Search For center
	  
	  $('#center-event-search').change(function(){
		  var event_val = $("#center-event-search").val();
		  window.location.replace(event_val);
	  });
	  
	  //Center Gallery
	  
	  $("ul.tabs li:last, .adv-gallery li:last").addClass("last");
	  
	  if ( $.browser.msie )
	  {
		if ( $.browser.version == 6 )    
	  {
		DD_belatedPNG.fix('ul.nav, img,.content-wrapper, table.vacancies td, ul.adv-gallery a');
		}
	  }
	  
	//$('#edit-submitted-job-id').val("Sandip");$designation
		$("#event-reminder").validate({
			rules: {
				mobile:{required: true,
				digits: true,
				minlength:10,
				maxlength:14
				},
				email:{
						required: true,
						email: true
					}
			},
			messages: {
				email: {required:"email id.",digits:"Please enter a valid email id"},
				mobile: {required:"require mobile.",digits:"Please enter a valid number"}
				},
			submitHandler: function(form) {
					  $.post(Drupal.settings.basePath+"event-set-reminder", $("#event-reminder").serialize(),
						  function(data){
						  //$('#result').hide("fast"
						  $('#result').css('display','block');
						  $('#adf').hide();
				  		}
					  ); 
	         }
		});
		  
	  $('#event-remind').click(function(){
		  //alert('fired');
		  $("#event-reminder").submit();
			//event.preventDefault();
	  });
	  
	///Validation 
	  $('#webform_client_form_2').validate({
			rules:{
			'edit-submitted-mobile':{required:true,maxlength:'10',digit:true}
			},
			messages:{
			'edit-submitted-mobile':{required:'Please enter your mobile number.',maxlength:'Name should not be more than 10',digit:'number only'}
			},
			errorLabelContainer: $("#error_box"),
			wrapper: "li",
			submitHandler: function(form) {
			form.submit();
			}
	});
	  
});

