
// define some vars

// var clurl = ""; // data from the class detail info popup that we need for adding classes, gets passed in name attr
// var cart=new Array(); // array for holding the shopping cart data even though it's primarily php driven vv
// cart[0]=new Array(4); // ^^ 2d array consisting of 0 = classid, 1 = classname, 2 = class date, 3 = class start time
// var cinc = 0; // items in cart, js cart stuff not really used atm but if cart ends up being js...
// var valid = 0; // user is logged in or not
// var good = 0; // used for some form stuff
// var name = "foo"; // city name, etc.
// var dd = 1;
// var urly = "no.php";
// var urly2 = "no.php";

// needed for drop down menus on older msie browsers

if ($.browser.msie && (parseInt(jQuery.browser.version) < 7)) {
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
}
// 
// // set select values for forms, kind of crap
// 
// function Select_Value_Set(SelectName, Value) {
//   eval('SelectObject = document.' + SelectName + ';');
//   for(var index = 0; 
//     index < SelectObject.length; 
//     index++) {
//    if(SelectObject[index].value == Value)
//      SelectObject.selectedIndex = index;
//    }
// }

// hash = site page to load usually, dd = number of days to show if the page shown is a list of classes
// some pages (e.g. #login) have the site reload in secure (https) mode
// onload handler hash values in url, makes pages bookmarkable.

// chkhash = function(hash, dd) {	
// 	if (!hash) {
// 		var hash = window.location.hash;
// 	}
// 	if (hash == "#edit") { hash="#home"; } // don't want to allow #edit in this context
// 	var match = 0;
// 	var test = false;
// 	var href = $('#nav li a').each(function() {
// 	href = $(this).attr('href');
// 	    if (hash == href) {
// 			if (hash=="#join") {
// 				match = 1;
// 				var test = dosecure(hash);				
// 				if (test) {
// 					jointheclass();
// 				}
// 			}
// 			else if ((match == 0) && (hash !="#login")){
// 					match = 1;
// 					if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7)  {
// 						if (!dd) { $("#left_stuff").hide(); } }
// 					var file = $(this).attr("name")+" #left_stuff";
// 					var name = hash.substr(1);
// 					if (!dd) { dd = 1; }
// 					if ($(this).attr("name") == "classlist.php") { // need to pass name variable for db name, jquery bugginess or smth
// 						$('#left_stuff').load(file, {name:name, class_range:dd}, function() {
// 						     $('.nyroModal', this).nyroModal(),
// 							 $("#left_stuff").fadeIn(150);
// 							$("#class_range").change(onSelectChange);
// 							var ddt = "2 weeks";
// 							switch (dd) {
// 								case "2": ddt="3 weeks"; break;
// 								case "3": ddt="4 weeks"; break;
// 							}
// 							$('#class_range').val(ddt);
// 						  });
// 					}
// 					else {
// 						match = 1;
// 						$('#left_stuff').load(file, null, function() {
// 						     $('.nyroModal', this).nyroModal(),
// 							 $("#left_stuff").fadeIn(150),
// 							 contactform();
// 						  });
// 					}
// 			}
// 	    }
// 	});
// 	if ((match == 0)) { // no matches so just load home page content + can't edit on a page load
// 		$('#left_stuff').load('home.html div#left_stuff', null, function() {
// 			$('.nyroModal', this).nyroModal(),
// 			 $("#left_stuff").fadeIn(150);
// 		});
// 	}
// 	if (hash=="#login") { // we want home content to load first since login is just a dialog...
// 		var test = dosecure(hash);
// 		if (test) { login(); }
// 	}
// }

// ajax & form validation, etc. for the sign up form
// 
// joinform = function() {
// 	var v = jQuery("#joinform").validate({
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#result",
// 				success: function()
// 					{
// 						if (valid==1)
// 							{
// 							if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7) {
// 							  $("#left_stuff").hide();}
// 							$('div#myclasses').load('myclasses.php div#myclasses', null,function() { $('.nyroModal', 'div#myclasses').nyroModal(), $('div#myclasses').fadeIn(600)}),
// 							$('li.panel_button').toggle(),
// 							$('li.acct_button').toggle(),
// 							$('#left_stuff').load('home.html div#left_stuff', null, function() {
// 									$('.nyroModal', this).nyroModal(),
// 									$("#left_stuff").fadeIn(150);
// 								});
// 							}
// 					}
// 			});
// 		}
// 	});
// }
// 
// // ajax & form validation for the edit account form
// acctform = function() {
// 	var v = jQuery("#accountform").validate({
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#result",
// 				success: function()
// 					{
// 						if (good==1)
// 							{
// 							amodal("Account changes saved.");
// 							if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7) {
// 							  $("#left_stuff").hide();}
// 							$('div#myclasses').load('myclasses.php div#myclasses', null,function() { $('.nyroModal', 'div#myclasses').nyroModal(), $('div#myclasses').fadeIn(600)}),
// 							//$('li.panel_button').toggle(),
// 							//$('li.acct_button').toggle(),
// 							$('#left_stuff').load('home.html div#left_stuff', null, function() {
// 									$('.nyroModal', this).nyroModal(),
// 									$("#left_stuff").fadeIn(150);
// 								});
// 							}
// 					}
// 			});
// 		}
// 	});
// }
// 
// 
// // ajax & form validation for the contact form
// 
// contactform = function() {
// 	var v = jQuery("#contactform").validate({
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#result",
// 				success: function()
// 					{
// 						if (good==1) {
// 							amodal("Thank you for your email.");
// 							if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7) {
// 								$("#left_stuff").hide();}
// 							$('#left_stuff').load('home.html div#left_stuff', null, function() { // reload home page content whend done
// 								$('.nyroModal', this).nyroModal(),
// 								$("#left_stuff").fadeIn(150);
// 							});
// 						}
// 					}
// 			});
// 		}
// 	});
// }

// function to set select values in forms
// 
// function onSelectChange(){  
//     var selected = $("#class_range option:selected");
// 	dd = selected.val();
// 	name = $("#classlist_db").attr("value");
// 	hash = "#"+name;
// 	chkhash(hash, dd);
// }  
// 
// // ajax form handler for class list date range dropdown
// 
// listform = function() {
// 	var v = jQuery("#listform").validate({
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#logresult3",
// 				success: function() {
// 						$('#left_stuff').load('classlist.php div#left_stuff', {name:name, class_range:dd},function() {
// 							$('.nyroModal', 'div#left_stuff').nyroModal(),
// 							$('div#left_stuff').fadeIn(150),
// 							listform()});
// 							$('#listform #class_range').hide();
// 				} 
// 			});
// 		}
// 	});	
// }

// form stuff for shopping cart - not needed if rolling in separate cart module

// cartform = function() {
// 	var v = jQuery("#mycartform").validate({
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#cartresults",
// 				success: function() {
// 					if (good == 1) { // classes registered, update myclasses, remove cart
// 						$('#mycart').hide();
// 						setTimeout("$.nyroModalRemove();",800);
// 					
// 						$('div#myclasses').load('addclass.php div#myclasses', null,function() {
// 							$('.nyroModal', 'div#myclasses').nyroModal(),
// 							$('div#myclasses').hide(),
// 							$('div#myclasses').fadeIn(600)
// 							});
// 					}
// 					if (good == 2) { // classes all cleared, remove cart
// 						$('#mycart').fadeOut(600);
// 					}
// 					if (good == 3) { // some classes removed, update cart
// 						cart2();
// 					}
// 
// 				} 
// 			});
// 		}
// 	});	
// }

// more cart stuff

// cart2 = function() {
// 	$('#mycart').load('mycart.php', null,function() {
// 		$('.nyroModal','div#mycart').nyroModal(),
// 		$('div#mycart').fadeIn(600),
// 		cartform();
// 		});
// }

// A simple dialog for alerting the user to things, auto closes in 5 seconds

// amodal = function(msg) {
// 	setTimeout("$.nyroModalRemove();",5000);
// $.nyroModalManual({
// 	content: "<p class='boxTextw' style='text-align:center;margin-top:25px;'>"+msg+"</p>",
//     width: 300,
//     height: 130,
// 	wrap: {manual: "<div class='wrapper' style='background: url(images/alertbkgd.png);'></div>"},
// 	closeButton: "<a href='#' class='nyroModalClose' id='closeBut' title='close'>Close</a>",
// 	resizeable: true
//     });
// 
// }

// menu fx

$(function() {
			$('#nav li a').hover(function() {
			  $(this).animate({ color: '#ffffff' }, 350);
			}, function() {
			  $(this).animate({ color: '#ce812d' }, 350);          
			});
});


// don't want close button on modal (want to place it depending on use) but do want click outside to close so can't do modal: true

// $(function() {
// 	$.nyroModalSettings({
// 		closeButton: "<a href='#' class='nyroModalClose' id='closeBut' title='close' style='display:none'>Close</a>"
// 	});
// });

// separate function for jtc menu item, needed to jump to secure mode, probably could be rolled back in
// 
// $(function() {
//         $('#jointheclass').click(function(e) {
//         e.preventDefault();
// 		var test = dosecure("#join");
// 		if (test) {
// 		  jointheclass();
// 	  	}
//         return false;
//         });
//       });
// 
// // need to do the http -> https shuffle for joining too
// 
// jointheclass = function() {
// 	if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7) {
// 		$("#left_stuff").hide();
// 	}
// 	$('#left_stuff').load('join.php div#left_stuff', null, function() {
// 		$('.nyroModal', 'div#left_stuff').nyroModal(),
// 	    $('#left_stuff').fadeIn(150),
// 		joinform();
// 		});
// }
// 
// // separate function for edit account item, class rubbish, meh
// 
// $(function() {
//         $('#editaccount').click(function(e) {
//           e.preventDefault();
// 		  if (!$.browser.msie || $.browser.msie && parseInt(jQuery.browser.version) > 7) {
// 		  $('#left_stuff').hide();}
// 		  $('#left_stuff').load('editacct.php div#left_stuff', null, function() {
// 		     $('.nyroModal', this).nyroModal(),
// 			 //Select_Value_Set("accountform.add_state", add_state),
// 			 //Select_Value_Set("accountform.city_name", city_name),
// 		     $("#left_stuff").fadeIn(200),
// 			 acctform();
// 		  });
//           return false;
//         });
//       });

// validation for login dialog

// $(function() {
// 	var v = jQuery("#login").validate({
// 		messages: { 
// 		            username: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", 
// 		            password: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
// 		           },
// 		submitHandler: function(form) {
// 			jQuery(form).ajaxSubmit({
// 				target: "#logresult",
// 				success: function() {
// 				if (valid==1)
// 					{
// 						$('div#myclasses').load('myclasses.php div#myclasses', null,function() {
// 							$('.nyroModal', 'div#myclasses').nyroModal(),
// 							$('div#myclasses').hide(),
// 							$('div#myclasses').fadeIn(600)
// 							});
// 						$('li.panel_button').toggle(),
// 						$('li.acct_button').toggle();
// 						$.nyroModalRemove();
// 					}
// 				} 
// 			});
// 		}
// 	});
// 	
// });
// 
// // manual call for login button, needed to style modal
// 
// $(function() {
//         $('#loginmenu').click(function(e) {
// 	        e.preventDefault();
// 			var test = dosecure('#login');
// 			if (test) {
// 				login();
// 			}
// 	        return false;
// 	        });
//       });
// 
// 
// 
// // manual call for logout, styled modal + php
// 
// $(function() {
//         $('#logoutmenu').click(function(e) {
// 	        e.preventDefault();
// 			logout();
// 	        return false;
// 	        });
//       });
// 
// // break out this section because we use it when doing the login http -> https shuffle
// 
// login = function() {
// 	  $.nyroModalManual({
// 		debug: false,
// 		modal: false,
// 		resizeable: true,
// 		type: 'div',
// 		url: '#logind',
//       width: 300,
//       height: 210,
// 		wrap: {div: "<div class='wrapper' style='background: url(images/loginback.jpg)'></div>"},
// 		closeButton: "<a href='#' class='nyroModalClose' id='closeBut' title='close' style='top: 141px;right: 170px'>Close</a>"
//       });
// }
// 
// logout = function() {
// 	  $.nyroModalManual({
// 		debug: false,
// 		modal: false,
// 		type: 'ajax',
// 		url: 'logout.php',
//     width: 300,
//     height: 130,
// 	wrap: {ajax: "<div class='wrapper' style='background: url(images/alertbkgd.png);'></div>"},
// 	closeButton: "<a href='#' class='nyroModalClose' id='closeBut' title='close'>Close</a>",
// 	resizeable: true
// });
// setTimeout("$.nyroModalRemove();",5000);
// }
// 
// // check to see if the page url is secure, if not load it secure. the correct address to use
// // should be "https://www.thebetterclass.com/home.php"+hash but since they don't have a server yet...
// 
// deetspop = function(urly) {
// 	  var pos=urly.indexOf("&spl");
// 	  var len=urly.length;
// 	  var url=urly.substr(0,pos);
// 	  clurl=urly.substr(pos+4,len);
// 	  $.nyroModalManual({
// 		debug: false,
// 		modal: false,
// 		resizeable: true,
// 		type: 'ajax',
// 		url: url,
// 		resizeable: true
//       });
// }

dosecure = function(hash) {
	//var prefix = parent.location.protocol + '//'
    //if (prefix != 'https://') {
	//	window.location.href="https://www.thebetterclass.com/home.php"+hash; // 71.92.100.29 192.168.1.101
//		return false;
//		setTimeout(5000); // spin some clock so it doesn't return before browser has a chance to start loading secure version
  //  }
	//else {
		return true;
	//}
}

// manual call for logout, styled modal + php

// $(function() {
//        $('#passreset').click(function(e) {
//         e.preventDefault();
// 		$.nyroModalManual({
// 			debug: false,
// 			modal: false,
// 			type: 'ajax',
// 			url: 'forgotpw.php',
// 	    	width: 400,
// 	    	height: 350,
// 			resizeable: true
// 		});
//         return false;
//         });
//      });
// 
// 
// 	 $(function() {
//        $('#submitcart').click(function(e) {
//         e.preventDefault();
// 		$.nyroModalManual({
// 			debug: false,
// 			modal: false,
// 			type: 'ajax',
// 			url: 'submitcart.php',
// 	    	width: 400,
// 	    	height: 350,
// 			resizeable: true
// 		});
//         return false;
//         });
//      });
// 

// add to class function - javascript "cart" functions aren't really used but this is left in just in case...

// addtocart = function(clurl) {
// 	var msplit=clurl.split(',');
// 	cart[cinc][0]=msplit[0];
// 	cart[cinc][1]=msplit[1];
// 	cart[cinc][2]=msplit[2];
// 	cart[cinc][3]=msplit[3];
// //	alert (cart[cinc][0]+"\n"+cart[cinc][1]+"\n"+cart[cinc][2]+"\n"+cart[cinc][3]);
// }
// 
// 
// // simple preload function for images
// 
// jQuery.preloadImages = function()
// {
// 	for(var i = 0; i<arguments.length; i++)
// 	{
// 		jQuery("<img>").attr("src", "images/"+arguments[i]);
// 	}
// }

// Get cookie routine by Shelley Powers - site cookies aren't used due to ambiguous security needs, but might be convenient

// function get_cookie(Name) {
//   var search = Name + "="
//   var returnvalue = "";
//   if (document.cookie.length > 0) {
//     offset = document.cookie.indexOf(search)
//     // if cookie exists
//     if (offset != -1) { 
//       offset += search.length
//       // set index of beginning of value
//       end = document.cookie.indexOf(";", offset);
//       // set index of end of cookie value
//       if (end == -1) end = document.cookie.length;
//       returnvalue=unescape(document.cookie.substring(offset, end))
//       }
//    }
//   return returnvalue;
// }
// 
// // the following are needed for the jquery.history plugin
// 
// function pageload(hash, dd) {
// 	// hash doesn't contain the first # character.
// 	if(hash) {
// 		hash="#"+hash;
// 	}
// 	else {
// 	  var hash = "#home";
// 	}
// 	chkhash(hash, dd);
// }

$(document).ready(function(){
	$("#nav > li").mouseover( function() {
		$(this).addClass("hovering");
	}).mouseout( function() {
		$(this).removeClass("hovering");
	});
});


