if ($.browser.msie) {
	//window.onerror = function() { return true; }
}



   $(document).ready(function() {

    	function megaHoverOver(){

    		$(this).find(".menu_div").removeClass("menu_div").addClass("menu_div_hover");

    		$(this).find(".sub-left").stop().fadeTo('fast', 1).show();
    		$(this).find(".sub-right").stop().fadeTo('fast', 1).show();

    		//Calculate width of all ul's
    		(function($) {
    			jQuery.fn.calcSubWidth = function() {
    				rowWidth = 0;
    				//Calculate row
    				$(this).find("ul").each(function() {
    					rowWidth += $(this).width();
    				});
    			};
    		})(jQuery);

    		if ( $(this).find(".row").length > 0 ) { //If row exists...
    			var biggestRow = 0;
    			//Calculate each row
    			$(this).find(".row").each(function() {
    				$(this).calcSubWidth();
    				//Find biggest row
    				if(rowWidth > biggestRow) {
    					biggestRow = rowWidth;
    				}
    			});
    			//Set width
    			$(this).find(".sub-left");
    			$(this).find(".sub-right");
    			$(this).find(".row:last").css({'margin':'0'});

    		} else { //If row does not exist...

    			$(this).calcSubWidth();
    			//Set Width
    			$(this).find(".sub-left");
    			$(this).find(".sub-right");
    		}
    	}

    	function megaHoverOut(){

    	  $(this).find(".sub-left").stop().fadeTo('fast', 0, function() {
    		  $(this).hide();
     	  });
    	  $(this).find(".sub-right").stop().fadeTo('fast', 0, function() {
    		  $(this).hide();
    	  });

  		   $(this).find(".menu_div_hover").removeClass("menu_div_hover").addClass("menu_div");


    	}

    	var config = {
    		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
    		 interval: 10, // number = milliseconds for onMouseOver polling interval
    		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
    		 timeout: 10, // number = milliseconds delay before onMouseOut
    		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    	};

    	$("ul#topnav li .sub-left").css({'opacity':'0'});
    	$("ul#topnav li .sub-right").css({'opacity':'0'});
    	$("ul#topnav li").hoverIntent(config);

    });


	$(function() {
	    $('#slideshow').cycle({
	        fx:     'fade',
	        speed:  'slow',
	        timeout: 9000,
	        pager:  '#slideshownav',
        next:   '#slideshownext',
        prev:   '#slideshowprev',
	        pagerAnchorBuilder: function(idx, slide) {
	            // return sel string for existing anchor
	            return '#slideshownav li:eq(' + (idx) + ') a';
	        }
	    });
	    $('li a').click(function() {
	        $('#slideshow').cycle('pause');
	    });
		$('#pauseButton').click(function() {
		    $('#slideshow').cycle('pause');
		});
		$('#resumeButton').click(function() {
		    $('#slideshow').cycle('resume');
		});
	});

var clickT = "";
function studentLoginPopUp(){
	$("#xaw_dialog").css("display","none");
	$("#xdialog").css("display","block");
	$("#xdialog").dialog({position: "center",zIndex:50,width:350});

	$("#xdialog input").focus(function(){
		var obj = this;
		$(document).keypress(function(e,o){
			if(e.keyCode == 13){
				var form  = $(obj).parent().parent();
				var form_id = $(form).attr("id");
				clearTimeout(clickT);
				clickT = setTimeout(function(){form.find("input.button1").trigger('click')},300);
			}
		});
	});
}

function awardsLoginPopUp(){
	$("#xdialog").css("display","none");
	$("#xaw_dialog").css("display","block")
	$("#xaw_dialog").dialog({position: "center",zIndex:50});

	$("#xaw_dialog input").focus(function(){
		var obj = this;
		$(document).keypress(function(e,o){
			if(e.keyCode == 13){
				var form  = $(obj).parent().parent();
				var form_id = $(form).attr("id");
				clearTimeout(clickT);
				clickT = setTimeout(function(){form.find("input.button1").trigger('click')},300);
			//	form.find("input.button1").trigger('click');
			}
		});
	});




}
function admLoginPopUp(){
	$("#xdialog").css("display","none");
	$("#xadm_dialog").css("display","block")
	$("#xadm_dialog").dialog({position: "center",zIndex:50});

	$("#xadm_dialog input").focus(function(){
		var obj = this;
		$(document).keypress(function(e,o){
			if(e.keyCode == 13){
				var form  = $(obj).parent().parent();
				var form_id = $(form).attr("id");
				clearTimeout(clickT);
				clickT = setTimeout(function(){form.find("input.button1").trigger('click')},300);
			//	form.find("input.button1").trigger('click');
			}
		});
	});




}
function checkPass(selector,user,locate,box, redirect_url){
		var params=$(selector).serialize();
		params=params;
              
//		if(user=="student"){
//			$.post("/login.php?user=student", params,function(data){
//				relocate(data,locate,box,redirect_url);
//			});
//		}elseif {
//			$.post("/login.php?user=award", params,function(data){
//				relocate(data,locate,box, redirect_url);
//			});
//		}

                switch (user) {
                    case "student": 
                        $.post("/login.php?user=student", params,function(data){
				relocate(data,locate,box,redirect_url);
			});
                      break;
                    case "award": 
                        $.post("/login.php?user=award", params,function(data){
				relocate(data,locate,box, redirect_url);
			});
                      break; 
                    case "adm": 
                         $.post("/login.php?user=adm", params,function(data){			
                                relocate(data,locate,box, redirect_url);
			});
                     break;
                }

}
function relocate(data,loc,box, redirect_url){
     
	if(data == "Error"){
		//alert("Incorrect login");
		$(box).dialog("option", "title", '<strong style="color:#fff772;">Incorrect login</strong>');
	}else{
		$(box).dialog("option", "title", "Logging in...");
		if(typeof(redirect_url) != 'undefined' && redirect_url!='') {
			window.location.href=redirect_url;
		}
		else {
			window.location.href="https://"+location.host+loc;
		}
	}
}


////////////////////////////////////////////////////////////////////////////////
// info
function seeInfo(id,donorName){
	window.location.href="/donor/"+donorName+"/"+id;
}

function toUrl(string){
	var string=string.replace(/[^A-z0-9]/i,"-");
	return string.replace(/[\t]/i,"-");
}
function savenow(selector){
	$(selector).css("display","inline");
	$(selector).text(" changes saved");

	function fade() {
	   $(selector).fadeOut(1000);
	}
	setTimeout(fade,1000);
}

function checkAgreement(box){
	if (document.getElementById("agreebox").checked) {
		document.forms['st_reg'].submit();
	}else{
		$(box).dialog("option", "title", "<strong style='color:#fff772;'>You must agree to Terms and Conditions.</strong>");
	}
}
function checkxAgreement(box){
	if (document.getElementById("xagreebox").checked) {
		document.forms['st_reg'].submit();
	}else{
		$(box).dialog("option", "title", "<strong style='color:#fff772;'>You must agree to Terms and Conditions.</strong>");
	}
}

function pngF(){
	$(document).pngFix();
}

function addEventHandler(obj,name,func){
    if (obj.attachEvent) {
		obj.attachEvent("on" + name, func);
	}
	else
		if (obj.addEventListener)
			obj.addEventListener(name, func, false);
   }

addEventHandler(window,"load",pngF);



