// JavaScript Document
function isEmail(strEmail){
	var patrn = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	return patrn.test(strEmail);
}

$(document).ready(function(){
	// main menus - dropdowns
	// =================================================
	$(".sf-menu .li_1:last").css("background-image","none");
	//$(".sf-menu .li_1 ul:last").addClass("lastfix");
	
	$(".sf-menu")
	.superfish({
		animation : { opacity:"show", height:"show" }
	})
	.find(">li:has(ul)")
		.mouseover(function(){
			$("ul", this).bgIframe({opacity:false, src:'#'});
		})
		.find("a")
			.focus(function(){
				$("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
			});

	
	//Support Groups Left Menu
	$('#sg ul').hide();
	$("#sg h3").toggle(
		function(){
			$(this).attr("class","prev");
			$("#sg h3").not($(this)).removeAttr("class");
			
			$("#sg ul").not($(this)).slideUp("normal");
			$(this).parent().children("ul").slideDown("normal");
		},
		function(){
			if($(this).hasClass("prev"))
			{
				$(this).parent().children("ul").slideUp("normal");
				$(this).removeClass("prev");
			}
			else
			{
				$("#sg ul").not($(this)).slideUp("normal");
				$(this).parent().children('ul').slideDown('normal');
				$(this).removeClass("prev");
			}
		}
	);
	
	$('#adslides').cycle();
	
	
	$("#archives h4").toggle(
		function(){$("#archives h5[id^='"+$(this).attr("id")+"']").show();$("#archives div[class^='"+$(this).attr("id")+"']").hide();},
		function(){$("#archives h5[id^='"+$(this).attr("id")+"']").hide();$("#archives div[class^='"+$(this).attr("id")+"']").hide();}
	);
	$("#archives h5").toggle(
		function(){
			$(this).next("div").show();
			if ($(this).next("div").text().length<20)
			{
				$(this).next("div").text("Loading...");
				var str=$.trim($(this).attr("id"));
				var y=str.substring(1,5).toString();
				var m=str.substring(7).toString();
				$(this).next("div").load("/load-news.asp", {Y:y,M:m});
			}
		},
		function(){$(this).next("div").hide();}
	);

	
	//build an anchor list in the left column
	if($(".secondleft").text().replace(/\s/g,'').length<20)
	{
		var strHtml='';
		$(".secondright a[name]").each(function(){
			strHtml=strHtml+'<li><a href="#'+$(this).attr("name")+'">'+$(this).text()+'</a></li>';
		});
		
		if (strHtml!='')
		{
			strHtml='<ul>'+strHtml+'</ul>';
			$(".secondleft h2").after(strHtml);
		}
	}

	$("#login input:first").focus();
	
	// Tips & Tricks left column
	if (document.location.href.indexOf('/coping/tips/') > 0) {
		// Load the Tips & Tricks sidebar from this url:
		var url = '/coping/tips/index.html';
		$(".secondleft ul").html('<li>Loading...</li>')
		    .load(url+' .secondleft ul');
	}



	// Add Pictures Page
	var randomPicnumber=Math.floor(Math.random()*111111)
	var picType = $.query.get('Type');
	if (picType == 'photoalbum') {
	}else{
		$("#uploadify").uploadify({
			'uploader'       : '/inc/uploadify/uploadify.swf',
			'script'         : '/inc/uploadify/uploadify.php',
			'cancelImg'      : '/inc/uploadify/cancel.png',
			'folder'         : '/temp/'+randomPicnumber,
			'queueID'        : 'fileQueue',
			'fileDesc'	 : '*.jpg',
			'fileExt'	 : '*.jpg',
			'sizeLimit'	 : '2000000',
			'auto'           : true,
			'multi'          : true,
			'onComplete'	 : function(event, queueID, fileObj, response, data) {
					     $('#filesUploaded').append(fileObj.name+'<br>');
					     $('#randomPicnumber').val(randomPicnumber);
					     alert($('#randomPicnumber').val());
						}
		});
	}
	
	
	





});
