// JavaScript Document

$(document).ready(function(){


//Find out how many  pages there are
if ($('body').attr('id') == 'aboutBAP_photoGallery') {
	
	$("a.group").fancybox();
	
	
	
	var current = $('#pictures ul');
	$('#next').attr('href', '#'+current[1].id);
	$('#previous').attr('href', '#'+current[current.length - 1].id);
	for (i=0; i<current.length; i++){
		//build the top selector
		var page = i + 1;
		var activeNewSelector= '<div class=\"select\"><a class=\"active\" href=\"#' + current[i].id + '\" id=\"'+ page + '\">Page ' + page + '</a></div>';
		var newSelector = '<div class=\"select\"><a href=\"#' + current[i].id + '\" id=\"'+ page + '\">Page ' + page + '</a></div>';
		//show the first page, hide the rest
		if (i==0) {
		//set the indicator to class active
			$('#selectors').append(activeNewSelector);
			$(this).addClass('active');
		} else {
		//$(current[i]).css('display', 'hidden');
		$('#selectors').append(newSelector);
		};
	};
	$('#selectors div.select a, #next, #previous').click( function(e) {
		e.preventDefault();
		//$('#selectors div.select a').removeClass('active');
		//$(this).addClass('active');
		var myHref = $(this).attr('href');
		
		jumpHref(myHref);
 	});

$('#upload_photos').validate({
					rules :{
								 name : 'required',
								 email : {
									required : true,
									 email : true
								 }, description : 'required',
								 file_name : 'required'
								
									 
							 },
					messages : {
								name : 'Your name is required',
								 email : {
									 required: "Email address is required",
       								email: "Your email address must be in the format of name@domain.com"
								 },
								 description : 'A description is required',
								 file_name : 'The file is required'
					},
							 errorClass : "invalid",
							 
							 highlight: function(element, errorClass) {
     							$(element).addClass(errorClass);
     							$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
  							},
  							unhighlight: function(element, errorClass) {
     							$(element).removeClass(errorClass);
     							$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
  							},
							submitHandler: function(form) {
       			   				form.submit();
							},
							onfocusout : true
					 });

	
	};

function jumpHref(myHref) {
	myHref= myHref.split('#');
	myHref = '#'+myHref[1];
	
	var current = $('#pictures ul'); //get all uls in an array
	$('#pictures ul').fadeOut('slow').removeClass('active'); //fadeout the ul with class active, remove class
	$('#selectors div.select a').removeClass('active');//remove class active from all top selector dots
	//var selectors = $('#selectors div.select a');
	$('#selectors div.select a').each(function(){ //build array and search through selectors 
			//if(navigator.appName == "Microsoft Internet Explorer") { 
			var myHash = $(this).attr('href');
			myHash = myHash.split('#');
			var newHash = '#'+ myHash[1];
			if (newHash == myHref) {$(this).addClass('active');};
			//} else {
	//if ($(this).attr('href') == myHref) {$(this).addClass('active');};
	//	};//if the href matches the passed var add class active, else test alert
											   });
	$(myHref).fadeIn('slow').addClass('active'); //fade in the passed ID and set class to active
	
	for (i=0; i<current.length; i++){ //for loop to change the  next/previous buttons
					if (myHref == "#"+current[i].id) {
						var x = i-1;
						var y = i+1;
						
						if (x < 0) { x = current.length - 1};
						if (y >= current.length) { y = 0;};
						
						var nextHref = '#'+current[y].id;
						var prevHref = '#'+current[x].id;
						
						$('#next').attr('href', nextHref);
						$('#previous').attr('href', prevHref);
						};
				};
};

						   //Drop down navigation for keyboard
						   $('li.level-1 a:not("ul.level-2 li a")').focus(function() {
							  //alert('I have focus');
							  $('li.level-1').removeClass('active').children('ul.level-2').slideUp('fast');
								$(this).parents('li').addClass('active').children('ul.level-2').slideDown('slow');
								$('*:not("ul.level-2 li a, ul.level-3 li a,li.level-1 a")').focus(function(){$('li.level-1').removeClass('active').children('ul.level-2').slideUp('fast');});
							});
						   //Drop down navigation for mousing
						    $('li.level-1 a').mouseenter(function(){
							$(this).parents('li').addClass('active').children('ul.level-2').slideDown('fast')
														  });
						 $('li.level-1').mouseleave(function(){
							$(this).removeClass('active').children('ul.level-2').slideUp('fast')
														  });
						   

						   $('#loginLink').click(function(e) {
							e.preventDefault();
							$('#loginForm').fadeIn().hover(function(){}, function(){setTimeout(function(){$('#loginForm').fadeOut('slow')}, 1500);});					
							$('body:not("#loginForm")').hover(function() {setTimeout(function(){$('#loginForm').slideUp()}, 1500)}, function(){});
							//$('body:not("#loginForm")').focus(function() {setTimeout($('#loginForm').slideUp(), 1000)});
							});
						   
						      //Moving through the registration form
						   $('a.next-section').click(function(e) {
								 e.preventDefault();
								var openMe = $(this).attr('href');
								//alert (openMe);
								//openMe = '#' + openMe;
								//$(this).parent('fieldset').slideUp();
								$(openMe).slideDown('slow');
								
							});
						   
						   $('a.back-section').click(function(e) {
								 e.preventDefault();
								var openMe = $(this).attr('href');
								//$('fieldset').slideUp();
								$(openMe).slideDown('slow')
								
							});
						   
						   //drop down for business type
$('select#ba_bus_type').val('');
$('select#ba_bus_type').change(function(){
												   //get value
												   var myVal = $(this).val();
												   
												   var showID = '';
												   //case statement 
												   switch(myVal) {
													 case 'Service Establishments': 
													 showID = '#service';
													 break;
													 case 'Professional Offices':
													 showID = '#professional-offices';
													 break;
													 case 'Automotive Repair and Maintenance':
													 showID = '#auto';
													 break;
													 case 'Building and Dwelling Services':
													 showID = '#building';
													 break;
													 case 'Real Estate':
													 showID = '#real-estate';
													 break;
													 case 'Proffessional Services':
													 showID = '#proffessional-services';
													 break;
													 case 'Specialty Services':
													 showID = '#specialty';
													 break;
													 case 'Retail':
													 showID = '#retail';
													 break;
													 case 'Transportation':
													 showID = '#transportation';
													 break;
													 case 'Other':
													 showID = '#other';
													 break;
													 case 'Construction-Special Trade Contractors':
													 showID = '';
													 break;
													 case 'Eating and Drinking Establishments':
													 showID = '';
													 break;
													 default:
													 showID = '';
												   };
												   if (showID == '') { $('div.row.second').slideUp('fast');
												   } else {
													   
												   $('div.row.second:not("'+showID +'")').slideUp('fast');
												   $(showID).slideDown('slow');
												   //alert($(showID + ' select').val());
												   if ($(showID + ' select').val() == 'Other'){
													$('#other').slideDown();
													};
												   $(showID + ' select').change(function() {
														var newVal = $(this).val();
														//alert(newVal);
															if (newVal =='Other') {
																$('#other').slideDown();
															} else {
																$('#other').slideUp();
															};
																							  
																							  });
												   };
												   });
				
$('#ba_hear_about').change(function() {
		var myValue = $(this).val();
		var myOption = "";
		switch(myValue) {
			case "chamber-org":
			myOption = "#orgName";
			break;
			case "print ad":
			myOption = "#magName";
			break;
			case "print article":
			myOption = "#magName";
			break;
			case "radio":
			myOption = "";
			break;
			case "TV":
			myOption = "";
			break;
			case "mailer":
			myOption = "";
			break;
			case "friend":
			myOption = "#referName";
			break;
			case "past participant":
			myOption = "#referName";
			break;
			case "agent":
			myOption = "#referName";
			break;
			case "social media":
			myOption = "";
			break;
			case "other":
			myOption = "#referOther";
			break;
		};
		 if (myOption == '') { $('div.row.second').slideUp('fast');
												   } else {
			$('div.row.second:not("'+myOption+'")').slideUp('fast');
			$(myOption).slideDown();
												   };
									});
				$('#file_name').change(function(e){
												$in = $(this);
												//var  myFile = $(this).attr('value');
												$('#inputbox').val($in.val());
												
												//alert($in.val() + ' ' +$('#inputbox').val());
												});
						   
						   
						   
						   	//ACCORDION BUTTON ACTION
							$('.accordionButton').click(function() {
						 
								if($(this).next().is(':visible')) {
									$('.accordionContent').slideUp('normal');
									$(this).css({background:'url(../images/icon_plus.gif) 0 8px no-repeat'});
								} else {
									$('.accordionContent').slideUp('normal');	
									$('.accordionButton').css({background:'url(../images/icon_plus.gif) 0 8px no-repeat'});
									$(this).next().slideDown('normal');
									$(this).css({background:'url(../images/icon_minus.gif) 0 8px no-repeat'});
								}
							});
							
							$('.accordionButton').hover(
							function(){
								 $(this).css({color:'#666'}); //mouseover
							},
							function(){
								 $(this).css({color:'#7dae28'}); // mouseout
							});
						 
								//HIDE THE DIVS ON PAGE LOAD	
							$(".accordionContent").hide();
							
							//ACCORDION BUTTON ACTION
							$('.accordionBtn').click(function() {
						 
								if($(this).next().is(':visible')) {
									$('.accordionCont').slideUp('normal');
									$(this).css({background:'url(../../images/icon_plus.gif) 15px 8px no-repeat'});
								} else {
									$('.accordionCont').slideUp('normal');	
									$('.accordionBtn').css({background:'url(../../images/icon_plus.gif) 15px 8px no-repeat'});
									$(this).next().slideDown('normal');
									$(this).css({background:'url(../../images/icon_minus.gif) 15px 8px no-repeat'});
								}
							});
							
							$('.accordionBtn').hover(
							function(){
								 $(this).css({color:'#66605b'}); //mouseover
							},
							function(){
								 $(this).css({color:'#7dae28'}); // mouseout
							});
						 
								//HIDE THE DIVS ON PAGE LOAD	
							$(".accordionCont").hide();

						
							//ACCORDION BUTTON ACTION
							$('.accordionB').click(function() {						 
								if($(this).next().is(':visible')) {
									$(this).next().slideUp('slow');
									$(this).css({background:'url(../../images/icon_plus_large.png) 6px 22px no-repeat'});
								} else {
									$(this).next().slideDown('slow');
									$(this).css({background:'url(../../images/icon_minus_large.png) 6px 22px no-repeat'});
								}
							});
							
							
							//ACCORDION BUTTON ACTION
							$('.accordionFAQ').click(function() {						 
								if($(this).next().is(':visible')) {
									$(this).next().slideUp('slow');
								} else {
									$(this).next().slideDown('slow');
								}
							});
							
							
							//ACCORDION BUTTON ACTION
							$('.accordion_button').click(function() {
						 
								if($(this).next().is(':visible')) {
									$(this).next().slideUp('normal');
									$(this).css({background:'url(../../images/icon_plus.gif) 0px 5px no-repeat'});
								} else {
									$(this).next().slideDown('normal');
									$(this).css({background:'url(../../images/icon_minus.gif) 0px 5px no-repeat'});
								}
							});
							
							$('.accordion_button').hover(
							function(){
								 $(this).css({color:'#7dae28'}); //mouseover 
							},
							function(){
								 $(this).css({color:'#66605b'}); // mouseout
							});
							
							
						
							//ACCORDION BUTTON ACTION
							$('.accordionClick').click(function() {
						 
								if($(this).next().is(':visible')) {
									$(this).next().slideUp('normal');
									$(this).css({background:'url(../../images/icon_plus.gif) 0px 7px no-repeat'});
								} else {
									$(this).next().slideDown('normal');
									$(this).css({background:'url(../../images/icon_minus.gif) 0px 7px no-repeat'});
								}
							});
							
							$('.accordionClick').hover(
							function(){
								 $(this).css({color:'#666'}); //mouseover
							},
							function(){
								 $(this).css({color:'#7dae28'}); // mouseout
							});
							
							
							
							
						 
								//HIDE THE DIVS ON PAGE LOAD	
							$(".accordionCont").hide();
							$(".accordion").hide();
						 
								//HIDE THE DIVS ON PAGE LOAD	
							$(".accordionC, .accordion_content").hide();
							
								$('.show').slideDown(
								function(){
									$(this).next().slideDown('slow');
									$(this).css({background:'url(../../images/icon_minus_large.png) 6px 22px no-repeat'});
							});

$('a.iframe').fancybox({
'frameWidth' : 975,
'frameHeight' : 500
 });
});


function setSocialLinks(){
	
	var url=location.href;
	var title=document.title;
		
$('#toolbar a').attr('target','_blank');
	$('#toolbar a.facebook').attr('href','http://www.facebook.com/share.php?u='+url+'&title='+title);
	$('#toolbar a.linkedIn').attr('href','http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=&source=The Business Accelerator Program');
	$('#toolbar a').click(function(e){toggleShare(0);});
}


