var urljs="http://"+window.location.host+"/";
var url="http://"+window.location.host+"/";

$(document).ready(function(){

 $('.infiniteCarousel').infiniteCarousel();
	//evnt calender
	if($('#clcalrowph').length>0)
	{
		getact();
		
		$(".clcalnext").click(function(){
			//alert($("#clcalmon").html());
			var mon=$(".clcalmonth").html();
			getcalendar(mon,1);
		});
		
		function getcalendar(mon,num){
			var mon=$(".clcalmonth").html();
			$.post(url+"eventscal/getmonthcal1",{'mon':mon,'num':num},function(data){
				//alert(data.month);
				//$("#cleventsrowph
				$('#clcalrowph').html(data.result);
				$(".clcalmonth").html(data.month);
				getact();
			},"json");
		}
		$(".clcalprev").click(function(){
			//alert($("#clcalmon").html());
			var mon=$(".clcalmonth").html();
			getcalendar(mon,-1);
		});	
		getcalendar("",0);
	
}
	function getact(){
		//alert($(this).find('.cldts').attr("data-dt"));
		$(".clcalevts").click(function(){
//			if($(this).find('.cldts').length>0){
//				//alert($(this).find('.cldts').html());
//				alert($(this).find('.cldts').attr("data-dt"));
//			}else{
//				//alert($(this).parent().find('.cldts').html());
//				alert($(this).parent().find('.cldts').attr("data-dt"));
//			}
			//
			var eventdate	=	$(this).attr("data-dt");
			
			$.post(url+"eventscal/displayEvents",{'eventdate':eventdate},function(data){
				  $("#batchStartDetails").html(data.result);
			 },"json");
			
			$(".clcalscrollmain").show();
			$(".clcalscrollmain").animate({width:  '360%',left:'-723px'}, 1000,function(){
				$(".clcalscrollmain").click(function(){
					$(this).hide();
					$(".clcalscrollmain").css({width:  '0%',left:'0'});
				});
//				$('html, body').click(function(){
//					$(".clcalscrollmain").hide();
//					$(".clcalscrollmain").css({width:  '0%',left:'0'});
//					$('html, body').unbind("click");
//				});
				
			});
			
		});
//		$('html, body').click(function(){
//			//$(".clcalscrollmain").hide();
//		});
	}

	registration();
	function registration()
	 {
			$("#registrationSubmit").live('click',function(){
				if ($('#termsandCondition').is(':checked'))
				{
					var js=$("#registrationfrm").serializeArray();	
					
					 $("#registrationfrm").clvalidate({
							onComplete:function(b){
								if(b){
									$.post(url+"user/registration/saveProfile",js,function(data){
										//alert(data.result);
										 $("#registerSuccessMsg").html(data.result);
										 $("#registrationfrm").html('');
									},"json");
								}else{
									$('html, body').animate({scrollTop: '150px'}, 800);	
								}
					 }});
				}
				else
					{
						alert("Please accept Terms and Conditions.");
					}
				
				
				
			 });//registration
	 }
	
	$("[name=dob]").datepicker({
        showOn: "button",
        buttonImage: "../../images/calendar.gif",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: '1900:2020',
        dateFormat: 'M-dd-yy'
        
    });

	 //home schedule batches
	 
	/* hmeScheduleBatches();
	 function hmeScheduleBatches()
	 {
		 $("[name=hmeScheduleBatches]").live('click',function(){
			 alert("enter");
			 $.post(url+"home/hmeScheduleBatches",function(data){
				  $(".aboutusScheduleBatches").html(data.result);
			 },"json");
		});
	 }*/
	
	 
	 
	 popularClasses();
	 
	 function popularClasses()
	 {
		 $("#popularClasses").click(function(){
			alert("enter");
			 $.post(url+"home/popularClasses",function(data){
				  $(".aboutusPopularClasses").html(data.result);
			 },"json");
		});
	 }
	 
	 
		 $("[name=hmeeventstype]").click(function(){
			 var eventTypeId=$(this).attr('id');
			 $.post(url+"home/getEventFestival",{'eventTypeId':eventTypeId},function(data){
				 $("#aboutusEventFestival").html(data.result);
			 },"json");
		});
		 
		 
	
	 
	 
	 
	 //classes
	 classes();
	 function classes()
	 {
		 $("[name=danceTypes]").live('click',function() {
			 //alert("ff");
			 var danceTypeId=$(this).attr('id');			 
			$("input[type=hidden][name=seldanceType]").val(danceTypeId);
			
			$.post(url+"classes/displayClasses",{'danceTypeId':danceTypeId,'levelId':''},function(data){
				  $("#displayClasses").html(data.result);
			 },"json");
		 });
		 
		 var danceTypeId=1;	
		 $("[name=danceTypes]:first").trigger('click');
	 }
	 
	 
	 selectlevel();
	 function selectlevel()
	 {
		 $("[name=level]").live('click',function() {
			var danceTypeId	=	 $("input[type=hidden][name=seldanceType]").val();
			var levelId		=	$(this).attr('id');
			
			$.post(url+"classes/displayClasses",{'danceTypeId':danceTypeId,'levelId':levelId},function(data){
				  $("#displayClasses").html(data.result);
			 },"json");
		 });
	 }
	 
	 $(".show_btn").live('click',function() {
		 var danceStyleId	=	$(this).attr("alt");
		 $("[name="+danceStyleId+"]").slideToggle("slow");
		 var showmoreimg='<img src="'+urljs+'images/yellowDw_arrow.png" border="0" />';
		 var hideimg='<img src="'+urljs+'images/yellowleft_arrow.png" border="0" />';
		 if ($(this).attr("title") == "Show more")
		 {
			 $(this).html("Hide"+hideimg);
			 $(this).attr("title","Hide");
		 }
		 else
	     {
			 $(this).html("Show more"+showmoreimg);
			 $(this).attr("title","Show more"); 
	     }
	});
	 
	//events
	 
	 displayevents();
	 function displayevents()
	 {
		 $("[name=locations]").live('click',function() {
			 $("#showDisplaydiv").html('');
			 var locationId=$(this).attr('id');
							
			$("input[type=hidden][name=selfeatured]").val(locationId);
			
			$.post(url+"events/displayEvents",{'locationId':locationId,'isFeatured':''},function(data){
				  $("#displayEvents").html(data.result);
			 },"json");
		 });
		 
	 }
	 
	 displayFeaturedEvents();
	 function displayFeaturedEvents()
	 {	
		 $("[name=featured]").live('click',function() {
			$("#showDisplaydiv").html('');
	
			 var locationId	=	 $("input[type=hidden][name=selfeatured]").val();
				var isFeatured		=	$(this).attr('id');
				
				$.post(url+"events/displayEvents",{'locationId':locationId,'isFeatured':isFeatured},function(data){
					  $("#displayEvents").html(data.result);
				 },"json");
			 });
		var isFeatured='Y';	
		 $("[name=featured]:first").trigger('click');
	 }
	 
	
	 //media
	  showFeatured();
	 function showFeatured()
	 {
			$('#mediamnu').live('click',function() {
				 $.post(url+"media/featuredvideo",function(data){
				  $("#featuredvideo").html(data.result);
				//  $(".video").html('<iframe id="src" width="360" height="209" src="'+data.src+'" frameborder="0" allowfullscreen></iframe>');
			 },"json");
			});
		 $('#mediamnu').trigger('click');
	 }
	 
	 showLatestMedia();
	 function showLatestMedia()
	 {
		 $("[name=latest]").bind('click',function() {
			 $("#displayPhotos").html('');
			 $("#displayVideos").html('');
			 $("#displayHotStuff").html('');
			 $.post(url+"media/latestMedia",function(data){
				  $("#latestDisplay").html(data.result);
        		  $('.infiniteCarousel').infiniteCarousel();
			 },"json");
		 });
	 }
	 
	 showPhotos();
	 function showPhotos()
	 {
		 $("[name=photos]").live('click',function() {
			 $("#latestDisplay").html('');
			 $("#displayVideos").html('');
			 $("#displayHotStuff").html('');
			 $.post(url+"media/displayPhotos",function(data){
				  $("#displayPhotos").html(data.result);
        		  $('.infiniteCarousel').infiniteCarousel();
			 },"json");
		 });
	 }
	 
	 showVideos();
	 function showVideos()
	 {
		 $("[name=video]").live('click',function() {
			 $("#latestDisplay").html('');
			 $("#displayPhotos").html('');
			 $("#displayHotStuff").html('');
			 $.post(url+"media/displayVideos",function(data){
				  $("#displayVideos").html(data.result);
        		  $('.infiniteCarousel').infiniteCarousel();
			 },"json");
		 });
	 }
	 
	 showHotStuff();
	 function showHotStuff()
	 {
		 $("[name=hotstuff]").live('click',function() {
			 $("#latestDisplay").html('');
			 $("#displayPhotos").html('');
			 $("#displayVideos").html('');
			 $.post(url+"media/displayHotStuff",function(data){
				  $("#displayHotStuff").html(data.result);
        		  $('.infiniteCarousel').infiniteCarousel();
			 },"json");
		 }); 
	 }
	 
	 //display schedule class/batch based on locations
	 displaybatch();
	 function displaybatch()
	 {
		 $("[name=schLocation]").live('click',function() {
			
			 var locationId=$(this).attr('id');
							
			//$("input[type=hidden][name=selfeatured]").val(locationId);
			
			$.post(url+"batchschedule/displayBatch",{'locationId':locationId},function(data){
				  $("#displayBatchDetails").html(data.result);
			 },"json");
			
			$.post(url+"batchschedule/displayInstructors",{'locationId':locationId},function(data){
				  $("#meetInstructor").html(data.result);
			 },"json");
			
		 });
		 
		 var sectionId=1;	
		 $("[name=schLocation]:first").trigger('click');
	 }
	 
	 //contact us
	 mailtoadmin();
	 function mailtoadmin()
	 {
		 $("#contactUsSubmit").live('click',function(){
			 $("#contactusfrm").clvalidate({
			 onComplete:function(b){
			 if(b){
				 var name	=	 $("[name=name]").val();
				 var email	=	 $("[name=email]").val();
				 var message=	 $("[name=message]").val();
				 var phone	=	 $("[name=phone]").val();
				  var city	=	 $("[name=city]").val();
				 $.post(url+"contactus/sendMail",{'name':name,'email':email,'phone':phone,'city':city,'message':message},function(data){
					 alert(data.result); 
					 $("#contactConfirmMsg").html(data.result);
				 },"json");
			 }else{
					$('html, body').animate({scrollTop: '150px'}, 800);	
				}
			 }});
			 
		 });
	 }
	 
	 displayStudioDetails();
	 function displayStudioDetails()
	 {
		 $("[name=sectionType]").live('click',function() {
			 $("#showmoreStudioDetails").html('');
			 var sectionId=$(this).attr('id');	
			// alert(sectionId);
			//s$("input[type=hidden][name=cmsname]").val(sectionId);
			
			$.post(url+"aboutus/displayStudioDetails",{'sectionId':sectionId},function(data){
				  $("#displayStudioDetails").html(data.result); 
					 $("[name=addressLocation]:first").trigger('click');	 
			 },"json");
		 });
		 
		 var sectionId=1;	
		 $("[name=sectionType]:first").trigger('click');

		 
		
	 }
	 
	 displayAddress();
	 function displayAddress()
	 {
		 $("[name=addressLocation]").live('click',function() {
				
			 var locationId	=	$(this).attr('id');
			 var sectionId	=	$("[name=sectionId]").val();
			 $.post(url+"aboutus/displayAddress",{'sectionId':sectionId,'locationId':locationId},function(data){
				  $("#displayStudiolocation").html(data.result);
			 },"json");
			
		 });
		
	 }
	 
	
});

